Module 08E: Projects
Starter projects are guided step by step and suit freshers. Stretch projects are open-ended, add production concerns, and suit experienced readers.
One project, a starter: a custom MCP server (08E.P1). It builds on lesson 08E.1 and nothing else in this module. Everything runs keylessly. The MCP server and its in-memory client are pure Python over in-memory fake data, so you can finish the "Done when" checklist without a single API key. Real MCP hosts (a desktop app or an IDE) and provider-native MCP support are the stretch goal once you have keys; the lesson shows exactly where they plug in.
What the fakes can and cannot tell you. The in-memory client proves the protocol plumbing: that your tools, resource and prompt are listed, that calls return the right shapes, and that errors come back as errors. It cannot tell you how a real model will use your tools: which one it picks, whether it invents an argument, how it reads your descriptions. Any "expected output" below is labelled illustrative. That gap is what the tool-use evals of lesson 08A.6 are for.
First time? Do the shared setup once: uv init tools-agents --bare --python 3.13 && cd tools-agents, then uv add "mcp[cli]" pytest anyio (the lesson picked its own folder name; any works). Run scripts with uv run python file.py and tests with uv run pytest -q. No .env file is needed for anything below.
You will reuse lesson files rather than reinvent them. The names below are the real ones from the lesson. Copy each file into your project folder exactly as printed there:
- From 08E.1:
ops_server.py,test_ops_server.py,s2_mini_mcp.py
If you also work through the projects of Module 08A, keep this project in its own folder so file names do not collide.
Starter: Custom MCP server#
Goal: Expose your own data as an MCP server — a tool, a resource and a prompt — built with the official mcp SDK exactly as lesson 08E.1 teaches, tested in memory with the SDK's Client, served over stdio and Streamable HTTP, and connected from a small client that lists and calls it. Optionally map the server's tools into the provider-neutral shape so your agent loop could call them.
What you'll practise:
- The three MCP primitives — tools, resources (and templates), prompts — and the
2026-07-28protocol revision the SDK serves (lesson 08E.1, 2.3, 1.4) MCPServerdecorators, typed schemas from signatures,ToolAnnotations, structured results andToolErrorfor model-actionable failures (lesson 08E.1, 3.1–3.2)- In-memory testing with
Client(mcp, raise_exceptions=True)(lesson 08E.1, 3.4) - Running and packaging: stdio default,
mcp dev/mcp run, Streamable HTTP transport (lesson 08E.1, 3.5) - Mapping MCP tools onto provider formats as pure Python (lesson 08E.1, 4.2)
- The security checklist you apply before trusting any server — yours included (lesson 08E.1, Part 5)
Setup: the shared project plus uv add "mcp[cli]" pytest anyio. The samples were checked against mcp 2.3.0 as of November 2026, and a plain install gives you the newest release; its high-level class is MCPServer (v1's FastMCP name does not import on v2 — 08E.1, 3.1).
Steps:
- Copy the pattern, change the data. Read 08E.1's
ops_server.pyand its test first. Then writegarden_server.py: anMCPServer("garden-helper")for a fictional houseplant shop, over an in-memoryPLANTSdict (provide your own five entries — e.g.monstera,snake_plant,pothos,fiddle_leaf_fig,succulent— each withlight,water_every_days,toxic_to_pets,notes). - Add the primitives. Three things, mirroring the lesson:
@mcp.tool(annotations=ToolAnnotations(read_only_hint=True))plant_lookup(plant_id: str) -> PlantResult— a dataclass result (structured output) orToolErrorfor unknown IDs ("no plant 'x'; known ids: ...").@mcp.tool()log_watering(plant_id: str, notes: str = "") -> str— appends to aWATERING_LOGlist, returns a confirmation; not read-only, so hosts prompt before running it.@mcp.resource("care://{plant_id}")care_guide(plant_id: str) -> str— a templated resource returning the care text.@mcp.prompt()plant_triage(problem: str) -> str— a prompt template that inlines the relevant care guide, like the lesson'srefund_triage.
- Test in memory. Write
test_garden_server.pyon the lesson's fixture pattern:Client(mcp, raise_exceptions=True); assertlist_tools()contains both tools,call_tool("plant_lookup", ...)returnsstructured_content, a bad ID returnsis_errorwith your message,read_resourceon the care URI works, andget_prompt("plant_triage", ...)inlines the guide. Runuv run pytest -q— all green before you go further. - Serve it. Keep
mcp.run()(stdio) as the default inif __name__ == "__main__". For HTTP, add a commented variantmcp.run(transport="streamable-http", port=3001)and run it in a second terminal; confirmhttp://127.0.0.1:3001/mcpanswers. Tryuv run mcp dev garden_server.pyto watch the inspector. - Write the client.
mcp_client.py: an asyncmain()that connects withClient("http://127.0.0.1:3001/mcp")(orClient(mcp)in-process for the keyless path), callslist_tools(),call_tool("plant_lookup", {"plant_id": "monstera"}),read_resource("care://monstera")andget_prompt(...), and prints a readable summary. Then paginate correctly: follownext_cursoronlist_toolsif the SDK returns one (08E.1, 4.1). - Map to provider format. Write
map_tools.py: a pure functionto_openai_tools(listing) -> list[dict]andto_anthropic_tools(listing) -> list[dict]convertingclient.list_tools()output into the Chat Completions / Messages tool shapes from 03.5 — this is the lesson's exercise 3, and the bridge between "MCP server" and "your agent loop". Unit-test it with a canned listing; no network. - Security pass. Walk 08E.1's Part 5 checklist against your own server: are annotations honest (
log_wateringis not read-only)? Do error messages leak internals? Would you add an auth layer before exposing port 3001 beyond localhost? Write three sentences in your notes.
Verify it, and what you should see:
uv run pytest -q test_garden_server.py # all tests pass
uv run python mcp_client.py # prints the tool list + one call resulttools: plant_lookup(read_only), log_watering
plant_lookup(monstera): light=bright_indirect water_every_days=7 toxic_to_pets=true
resource care://monstera: "Monstera deliciosa — water when the top 5cm..."
prompt plant_triage: "A customer reports brown leaf tips..."Done when:
test_garden_server.pypasses entirely in memory — no port, no transport, no keys.- The server exposes at least one tool, one resource (templated or static) and one prompt, with honest
ToolAnnotations. mcp_client.pylists, calls, reads and prompts against your running server over Streamable HTTP (or in memory).map_tools.pyconverts a reallist_tools()listing into both provider shapes and its unit test passes.- Your security notes answer: what would you never expose from this server, and what would you add before a real host connects?
Stretch ideas:
- Add
ctx: Contextandawait ctx.report_progress(...)to a slow tool, plus lifespan state (AppContext) holding the watering log, per 08E.1, 3.3. - Add an approval-gated escalation with
Resolve/Elicit— theescalate_ticketpattern from 08E.1, 3.6 — and drive it in a test withelicitation_callback. - Package it:
uv build, then document theuvx/mcp installcommand a host would run (08E.1, 3.5). - Hosted, needs keys: point a provider's native MCP support at your server (08E.1, 4.3) or register it with Claude Desktop/Cursor config, and compare the tool schemas the host actually sends.
Common problems:
ImportError: cannot import name 'FastMCP': you're on SDK v2 — usefrom mcp.server import MCPServer(08E.1, 3.1).- Tests see "Internal server error": you forgot
raise_exceptions=Trueon the testClient— real tracebacks are sanitised for remote callers by design. - Tool returns a dict the client can't read: return a dataclass or
strfor structured output; raiseToolError(not a bareException) for failures the model should read (08E.1, 3.2 notes). - Resource template 404s: URI must match the template exactly —
care://monsteramatchescare://{plant_id};care://plants/monsteradoes not. - HTTP transport won't start: check the port isn't taken and that you used
transport="streamable-http", not the deprecated SSE transport (08E.1, 2.6).