Every tool in this course so far has been a Python function you wrote and described by hand. MCP flips that: tools live on a separate server — possibly written by someone else, in any language, running as its own process — and your agent discovers what’s available at runtime instead of hardcoding a TOOLS list.
server.py exposes tools; your agent is an MCP client that connects to itsession.list_tools(), instead of writing a schema by hand — MCP tools already carry a JSON Schema in inputSchematool_use request to session.call_tool(name, input) over the MCP connection, instead of calling a local function directlyasync with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools_response = await session.list_tools()
claude_tools = [mcp_tool_to_claude_schema(t) for t in tools_response.tools]
# ...same agent loop as Module 2, except:
result = await session.call_tool(block.name, block.input)
The agent loop itself — send messages, check stop_reason, handle tool_use, append tool_result — is identical to Module 2. The only thing that changes is where a tool call actually executes: instead of a Python function in this file, it’s a request sent to server.py over stdio, which could just as easily be a remote server over HTTP. This is the point of MCP: it standardizes the wire format for tools so an agent can plug into tool servers it’s never seen before, without you writing a bespoke integration for each one.
server.py (provided) exposes the same calculate and get_weather tools from Module 2, just declared with the mcp SDK’s @mcp.tool() decorator instead of a hand-written schema — proof that this is the same tool-use concept, wearing a standardized protocol.
server.py — a minimal MCP server (provided, not part of the exercise).exercise.py — fill in mcp_tool_to_claude_schema, tool discovery, and the MCP dispatch call.solution.py — the completed reference implementation.pip install -r requirements.txt
export ANTHROPIC_API_KEY=your_key_here
python exercise.py # after filling in the TODOs — this launches server.py itself, no separate step needed
python solution.py # to compare against a working version
Module 12 — Context Management for Long-Running Agents — what to do when a conversation outgrows the context window.