Skip to main content
Glama
adi0ri

gateway_lab.mcp_server

by adi0ri
README.md
# FDE Assessment

Python implementations of four tasks covering MCP servers, security gateways, streaming guardrails, and model routing.

## Tasks

| Task | Implementation |
|---|---|
| 1. MCP server | [Official SDK stdio server](src/gateway_lab/mcp_server.py) with strict input validation and JSON-RPC errors |
| 2. MCP gateway | [JWT authentication and tool authorization](src/gateway_lab/app.py) for `admin_*` calls |
| 3. Streaming guardrail | [Bounded PII redaction](src/gateway_lab/redaction.py) for emails, SSNs, and card numbers across chunks |
| 4. Model router | [SQLite token limiter](src/gateway_lab/limiter.py) and [fallback routing](src/gateway_lab/provider.py): 50,000 tokens/minute/key, 3-second primary timeout |

## Setup

Requires **Python 3.11+**.

```sh
python -m venv .venv
```

Activate with `source .venv/bin/activate` (macOS/Linux) or `.\.venv\Scripts\Activate.ps1` (Windows PowerShell), then run:

```sh
python -m pip install -r requirements.lock
python -m pip install -e . --no-deps
python -m gateway_lab.demo
```

The gateway runs at `http://127.0.0.1:9000`, with mock upstreams on port `9001`. Demo credentials are printed in the terminal. No paid API keys are needed; refunds are simulated.

From another activated terminal, run `python scripts/exercise_gateway.py` to check authorization, streaming redaction, and fallback. Use `python -m gateway_lab.mcp_server` for the standalone stdio server.

## Tests

```sh
python -m pytest -q
python -m ruff check .
python -m ruff format --check .
python -m pip check
```

65 tests cover protocol handling, authorization, stream boundaries, SQLite concurrency, and fallback. CI runs on Windows and Linux with Python 3.11 and 3.13.

See [design notes](docs/design.md), [verification results](docs/verification.md), and [configuration](.env.example) for details.

TDQS

B3.2/5.0

Scored across 2 tools

Disambiguation5/5

The two tools perform clearly separate operations: retrieving a customer record versus triggering a refund. There is no functional overlap or ambiguity between them.

Naming Consistency5/5

Both tool names follow the same snake_case verb_noun pattern (get_customer_record, trigger_refund). The naming is concise, predictable, and consistent.

Tool Count3/5

Two tools is at the low end of what feels useful; for a mock lab it may be intentional, but the surface is thin. Each tool earns its place, but there is little room for broader workflows.

Completeness2/5

The server covers a single lookup and a single action, with no way to list customers, check refund status, or cancel/reverse a refund. Agents would hit dead ends for any multi-step workflow beyond a simple demo.

Maintenance

ActivityMaintained
ResponsivenessNo issues