Exercise ex-mcp-server — a tool server an agent can actually trust

In Java, a method signature is enforced by the compiler before your code ever runs. An agent calling a tool has no compiler — the patterns you just stepped through assumed every tool call just works. MCP (the Model Context Protocol) is the standard shape for the part that actually enforces the contract: a server declares each tool's arguments as a JSON schema, and a well-behaved implementation rejects a bad call with a clear error before the tool body runs at all — not a stack trace, and not a server that falls over on one unlucky request.

~90 minruns locally · uv + pytest 6 checksex-mcp-server

What you're building

The tests are ordinary pytest and ship in the public folder with the starter — read them first; the names below are the check list. Solutions are not published. pyproject.toml pins mcp==1.30.0: the SDK's shape (decorators, exception handling, even which module has Server) has moved fast across versions, and a schema-validation exercise needs one version to be honest against.

Get the repo (once)

Needs git. uv installs the right Python itself, so nothing else is required.

# once, anywhere on your machine
git clone https://github.com/theDocWho/ai-ml-roadmap.git
cd ai-ml-roadmap

No git? Download the ZIP, unzip it, and cd into the unzipped folder instead.

Run it

From the repo root:

# one-time: uv (https://docs.astral.sh/uv/) manages the venv and pins Python ≥ 3.12
cd exercises/ex-mcp-server && uv sync && uv run pytest -q

# the same bar the reference solution clears
uv run ruff check . && uv run mypy src

Done when uv run pytest -q prints 6 passed. Each test spawns your server as a real subprocess and talks to it over stdio with mcp's own ClientSession — exactly how an agent would.

The checks

Files

This is self-attestation — the site cannot see your terminal, so the box and the button are you telling The Path the suite went green on your machine.

If you get stuck