Product Catalog MCP Server
README.md
# Product Catalog MCP Server
A production-oriented [Model Context Protocol](https://modelcontextprotocol.io) server in Python. It exposes read-only product catalog tools over stateless Streamable HTTP.
**Version:** 0.6.0 · **MCP spec:** 2026-07-28 (also serves 2025-x clients) · **License:** [Apache 2.0](LICENSE) · [Changelog](CHANGELOG.md) · [Roadmap](docs/mcp-server-roadmap.md)
## Quick start
```bash
python3 -m venv .venv
.venv/bin/pip install --require-hashes -r requirements-dev.lock.txt # pinned, hashed (threat T10)
.venv/bin/pip install --no-deps -e .
cp .env.example .env # adjust settings if needed
.venv/bin/mcp-server # serves http://127.0.0.1:8000/mcp
.venv/bin/pytest # run the tests
.venv/bin/python evals/run_evals.py --dry-run # validate the model eval set (free)
```
In VS Code, use the **Run and Debug** panel: "MCP server (local)", "Tests (all)" and others are defined in `.vscode/launch.json`.
**Production-shaped stack** (2 instances, Redis, nginx on port 8080):
```bash
docker compose -f deploy/docker-compose.yml up --build
```
Add `--profile observability` for Prometheus (http://localhost:9090) and the Grafana traffic dashboard (http://localhost:3000).
## Setup checklist
What to configure, in order. Settings are environment variables (see [Configuration](#configuration)).
| # | Where | Step | How | Required? |
|---|---|---|---|---|
| 1 | Local | Install from the hashed lock files | `pip install --require-hashes -r requirements-dev.lock.txt` then `pip install --no-deps -e .` | Yes |
| 2 | Local | Create `.env` | `cp .env.example .env`; defaults work on `localhost` | Yes |
| 3 | Local | Check it runs | `.venv/bin/pytest -q`, then `.venv/bin/mcp-server` and `curl localhost:8000/healthz` | Yes |
| 4 | Local | Connect a client | Postman or another MCP client at `http://localhost:8000/mcp` ([Testing with Postman](#testing-with-postman)) | Optional |
| 5 | Redis tools | Turn on and point at a Redis | `MCP_REDIS_TOOLS_ENABLED=true`, `MCP_REDIS_TOOLS_URL`, ideally `MCP_REDIS_TOOLS_KEY_PREFIX` | Optional; read [threat T13](docs/threat-model.md) first |
| 6 | Voice tool | Keep or turn off `find_products` | `MCP_VOICE_TOOLS_ENABLED` (default `true`) | Optional |
| 7 | GitHub | Create the repo and push | `git remote add origin <url>` then `git push -u origin main` | Yes |
| 8 | GitHub | Protect `main` | **Settings → Branches**: require pull requests and the `CI / test` and `CI / image` checks | Yes |
| 9 | GitHub | Turn on security features | **Settings → Code security**: Dependabot alerts and security updates, private vulnerability reporting (used by [SECURITY.md](SECURITY.md)), secret scanning | Yes |
| 10 | GitHub | Add a code owner | Create `.github/CODEOWNERS` (e.g. `* @your-team`) | Yes for production (roadmap: named owner) |
| 11 | GitHub | Paid eval secret | **Settings → Secrets → Actions**: `ANTHROPIC_API_KEY`, only if evals run in CI | Optional |
| 12 | Production | Network and hosts | `MCP_HOST=0.0.0.0`, `MCP_ALLOWED_HOSTS`, `MCP_ALLOWED_ORIGINS` for the clients that connect | Yes |
| 13 | Production | Behind a load balancer | `MCP_TRUSTED_PROXIES` | Yes, if behind one |
| 14 | Production | 2+ instances | `MCP_REDIS_URL` for shared rate limits | Yes, if more than one instance |
| 15 | Production | Build identity | `docker build --build-arg MCP_BUILD_ID=$(git rev-parse --short HEAD) .` | Recommended |
| 16 | Production | Observability | `OTEL_EXPORTER_OTLP_ENDPOINT`; scrape `/metrics`; load [prometheus-alerts.yml](deploy/prometheus-alerts.yml) and the [Grafana dashboard](deploy/grafana/dashboards/mcp-traffic.json) | Recommended |
| 17 | Production | Cost cap | `MCP_DOWNSTREAM_DAILY_QUOTA` before connecting a paid API | Yes, if a paid API is used |
## Testing with Postman
Start the server (`.venv/bin/mcp-server`), then use either option.
**Option A: MCP request (easiest).** **New → MCP**, transport **HTTP**, URL `http://localhost:8000/mcp`, then **Connect**. Postman runs the handshake and lists the tools; fill in the arguments and run them.
**Option B: plain HTTP.** `POST http://localhost:8000/mcp` with these headers:
```
Content-Type: application/json
Accept: application/json, text/event-stream
```
1. Send `initialize`:
```json
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"postman","version":"1"}}}
```
2. Add the header `MCP-Protocol-Version: 2025-06-18`, then list or call tools:
```json
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
```
```json
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_product","arguments":{"sku":"SKU-1001"}}}
```
**Common errors**
| Response | Cause | Fix |
|---|---|---|
| `403 Forbidden` | Postman in the browser (go.postman.co) or the Postman Agent sends an `Origin` header the server doesn't allow | Use the desktop app, or for local testing only add `https://go.postman.co` to `MCP_ALLOWED_ORIGINS` in `.env`. Never in production. |
| `421 Misdirected Request` | The URL uses a hostname other than `localhost` or `127.0.0.1` | Use `localhost`, or add the host to `MCP_ALLOWED_HOSTS` |
| `400`, code `-32020` | `MCP-Protocol-Version` header doesn't match the version in the request | Make the header and the body's version the same |
| `405 Method Not Allowed` | A `GET` request to `/mcp` | Use `POST` |
| `isError: true`, "Invalid arguments…" | An argument is missing, misspelled or invalid | The message names the field and the allowed arguments |
| `429 Too Many Requests` | Rate limit (100/min per client) or the same call repeated more than 10 times a minute | Wait for `Retry-After`, or change the arguments |
## Tools
| Tool | Purpose |
|---|---|
| `search_products` | Find products by name, with category and stock filters and pagination |
| `get_product` | Full details for one SKU |
Details: [docs/tool-catalog.md](docs/tool-catalog.md)
## Project layout
```
src/mcp_server/
domain/ entities, errors, ports (no framework code)
application/ use cases
infrastructure/ repositories, Redis rate limiter, resilience, metrics, logging
interface/ MCP tools, HTTP middleware, health and metrics routes
bootstrap.py wires everything; entry point
tests/ unit, interface, infrastructure and architecture tests
deploy/ docker-compose, nginx, Prometheus alerts
loadtest/ Locust load test
evals/ model eval set: does Claude pick the right tool?
docs/ requirements, roadmap, architecture, decisions, runbook
```
## Documentation
Also: [CONTRIBUTING.md](CONTRIBUTING.md) (setup, PR rules) · [SECURITY.md](SECURITY.md) (reporting, known limits)
| Doc | What it covers |
|---|---|
| [Production requirements](docs/mcp-server-production-requirements.md) | The full checklist |
| [Roadmap](docs/mcp-server-roadmap.md) | Phases and progress |
| [Architecture](docs/architecture.md) | Layers, request flow, how to extend |
| [Decisions](docs/decisions/) | Why things are the way they are |
| [Tool catalog](docs/tool-catalog.md) | Tool contracts and rules |
| [Threat model](docs/threat-model.md) | Risks and controls |
| [Data handling](docs/data-handling.md) | Logging, redaction, retention |
| [Runbook](docs/runbook.md) | Alerts, procedures, load test results |
| [Versioning](docs/versioning.md) | Breaking-change rules, release checklist |
| [Decision 0005](docs/decisions/0005-mcp-2026-07-28.md) | How each MCP 2026-07-28 rule is met |
| [Decision 0006](docs/decisions/0006-phase3-scope.md) | Phase 3: what was built and what was deferred |
## Configuration
All settings come from environment variables, read in [config.py](src/mcp_server/config.py). Copy [.env.example](.env.example) to `.env` to start.
**Nothing is required to run locally.** Every setting has a safe default. The server checks settings at startup and refuses to start with a message saying what to fix.
### Required for production
| Situation | Set | Why |
|---|---|---|
| Running in a container or behind a load balancer | `MCP_HOST=0.0.0.0`, `MCP_ALLOWED_HOSTS`, `MCP_ALLOWED_ORIGINS` | The defaults only accept `localhost`; other Host and Origin headers are rejected (DNS rebinding protection) |
| Behind a load balancer | `MCP_TRUSTED_PROXIES` | Without it, `X-Forwarded-For` is ignored and every client looks like the proxy, sharing one rate limit |
| 2 or more instances | `MCP_REDIS_URL` | Rate limits are per instance without it |
| Using the Redis tools | `MCP_REDIS_TOOLS_ENABLED=true`, `MCP_REDIS_TOOLS_URL`, ideally `MCP_REDIS_TOOLS_KEY_PREFIX` | Off by default: anyone who can reach the server can read that Redis. The URL must differ from `MCP_REDIS_URL`. |
| Calling a paid downstream API | `MCP_DOWNSTREAM_DAILY_QUOTA` | The cost cap is off (`0`) by default |
| Tracing | `OTEL_EXPORTER_OTLP_ENDPOINT` | Tracing is off without it |
### All settings
| Variable | Default | What it does |
|---|---|---|
| **Version** | | |
| `MCP_SERVICE_VERSION` | `version` in `pyproject.toml` | Version reported in MCP `serverInfo`, `/healthz` and traces. Must be semver. |
| `MCP_BUILD_ID` | empty | Git SHA or image digest, shown on `/healthz`. Docker: `--build-arg MCP_BUILD_ID=...` |
| **Network** | | |
| `MCP_HOST` | `127.0.0.1` | Bind address. Use `0.0.0.0` only inside a private network or container. |
| `MCP_PORT` | `8000` | Port |
| `MCP_ALLOWED_HOSTS` | `localhost:*,127.0.0.1:*` | Allowed `Host` headers, comma-separated |
| `MCP_ALLOWED_ORIGINS` | `http://localhost,http://127.0.0.1` | Allowed `Origin` headers. Requests without an Origin (non-browser clients) are allowed. |
| `MCP_TRUSTED_PROXIES` | empty | Proxy IPs whose `X-Forwarded-For` is trusted |
| **Limits** | | |
| `MCP_MAX_BODY_BYTES` | `1048576` | Request body cap (1 MB) |
| `MCP_GLOBAL_RATE_PER_MIN` | `1500` | Requests per minute, all clients together |
| `MCP_CLIENT_RATE_PER_MIN` | `100` | Requests per minute per client |
| `MCP_TOOL_RATE_LIMITS` | `search_products=60,get_product=120,find_products=60` | Per-tool limit per client per minute |
| `MCP_LOOP_MAX_REPEATS_PER_MIN` | `10` | Identical calls per minute before a call is treated as a runaway loop (`0` disables) |
| `MCP_MAX_CONCURRENCY` | `64` | In-flight requests per instance before returning `503` |
| `MCP_MAX_OUTPUT_CHARS` | `20000` | Tool output cap; longer results are truncated and marked |
| `MCP_DOWNSTREAM_TIMEOUT_S` | `10` | Timeout for each downstream call |
| `MCP_DOWNSTREAM_DAILY_QUOTA` | `0` | Downstream calls per UTC day (`0` = no cap) |
| **Cache** | | |
| `MCP_CACHE_TTL_S` | `30` | Read-only response cache lifetime (`0` disables) |
| `MCP_CACHE_MAX_ENTRIES` | `1000` | Cache size |
| **Shared state** | | |
| `MCP_REDIS_URL` | empty | Redis for shared rate limits. Empty = in-process limits. |
| **Redis tools** ([decision 0007](docs/decisions/0007-redis-tools.md)) | | |
| `MCP_VOICE_TOOLS_ENABLED` | `true` | Register `find_products`, the voice-first tool: takes the user's words as spoken, returns a `speak` sentence and at most 3 items |
| `MCP_REDIS_TOOLS_ENABLED` | `false` | Register the Redis tools, the `redis://keys/{key}` resource and the `debug_redis_key` prompt |
| `MCP_REDIS_TOOLS_URL` | `redis://localhost:6379/0` | The Redis the model can inspect (`redis://` or `rediss://`) |
| `MCP_REDIS_TOOLS_MODE` | `readonly` | `readonly`. `readwrite` is rejected until authentication ships (Phase 4). |
| `MCP_REDIS_TOOLS_KEY_PREFIX` | empty | Confine every key and scan to this prefix (no glob characters) |
| `MCP_REDIS_TOOLS_MAX_RESULTS` | `100` | Max items per call |
| **Observability** | | |
| `MCP_LOG_LEVEL` | `INFO` | Log level |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | empty | OTLP/HTTP endpoint, e.g. `http://otel-collector:4318`. Turns on tracing. |
| `OTEL_SERVICE_NAME` | `mcp-server` | Service name in traces |
| **Evals only** (`evals/run_evals.py`; not used by the server) | | |
| `ANTHROPIC_API_KEY` | empty | Or use an `ant auth login` profile |