Custom MCP math & database tool server, following the lecture samples
(Sample 3 MCP / Sample 4 MCP Architecture).
The MCP server exposes three tools. A LiteLLM ReAct client discovers those tools at runtime and calls them over Streamable HTTP.
| Tool | Purpose |
|---|---|
lookup_inventory |
SQLite lookup against inventory.db (products) |
compute_tiered_discount |
Tiered discount formula based on order volume |
append_audit_event |
Append a timestamped event to logs/audit.log |
The audit file is also published as the MCP resource file://audit/events.
Discount brackets:
- 1–9 units → 0%
- 10–49 units → 5%
- 50–99 units → 12%
- 100–249 units → 18%
- 250+ units → 25%
- Python 3.11+
- uv
- LiteLLM proxy running locally
- SQLite (
sqlite3is in the Python standard library)
python -m pip install uv
python -m uv sync
copy .env.example .envEdit .env:
LITELLM_API_BASE=http://localhost:4000
LITELLM_KEY=sk-your-litellm-key
LITELLM_DEFAULT_MODEL=gpt-4o-mini
MCP_SERVER_URL=http://localhost:8000/mcp
The first server start creates inventory.db if it is missing and seeds:
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
quantity INTEGER NOT NULL
);You can also point the project at an existing inventory.db by placing the file
in this directory.
Terminal 1 – MCP server:
python -m uv run python server.pyTerminal 2 – ReAct client (LiteLLM):
python -m uv run python client.pyThe client prompt looks up Hydraulic Pump, computes an 80-unit discount at $120, and writes an audit event.
See logs/execution.log for a captured client run that
exercises all three tools.