agentic-ai-course

Module 11 — MCP (Model Context Protocol)

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.

What you’ll learn

The core idea

async 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.

Files

Run it

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

Next

Module 12 — Context Management for Long-Running Agents — what to do when a conversation outgrows the context window.