MCP (Model Context Protocol)¶
Intermediate → Advanced · 7 topics
The AI Agents series showed MCP in one section. This series goes all the way: the protocol itself, building and testing servers, connecting them to real hosts and frameworks, running them remotely with proper auth, and the security problems that come with letting other people's tools into your model's context. MCP shows up in more and more GenAI job descriptions, and "have you built an MCP server?" is now a common interview question.
# Pages 1, 2 and 7 run offline with the Python standard library.
# Pages 3-6 need packages and are marked "no-run"; their outputs are from real runs:
pip install "mcp>=2" # the official Python SDK (servers and clients)
pip install langchain-mcp-adapters openai-agents # page 6, in a separate environment (they still use mcp 1.x)
| # | Topic | Sub-topics |
|---|---|---|
| 1 | What MCP is | The N×M problem · host, client, server · tools, resources, prompts · JSON-RPC · handshake era vs the stateless 2026-07-28 spec · MCP vs function calling |
| 2 | The protocol from scratch | A stdlib server and client · server/discover · tools and resources · protocol errors vs isError · multi round-trip elicitation · the stdio transport |
| 3 | Building servers with the Python SDK | MCPServer · structured output · ToolError · resources and templates · prompts · progress · Resolve and Elicit · lifespan · MCP Inspector |
| 4 | Clients and hosts | Claude Code, Claude Desktop, Cursor, VS Code configs · the Python Client · MCP tools as LLM tools · an agent loop over MCP · several servers · caching |
| 5 | Remote servers and auth | Streamable HTTP on the wire · Mcp-Method / Mcp-Name headers · stateless scaling · mounting in FastAPI · OAuth 2.1 · no token passthrough |
| 6 | MCP in agent frameworks | langchain-mcp-adapters · LangGraph · OpenAI Agents SDK · the Claude API MCP connector · Claude Code · choosing an approach |
| 7 | Security and production | Tool poisoning · rug pulls and pinning · injection through results · the lethal trifecta · approvals · audit logs · testing · checklist |
flowchart LR
U[User] --> H[Host<br/>Claude, IDE, your agent]
H --> L[LLM]
H --> C1[MCP client] <-->|stdio| S1[Local server<br/>files, git, CLI]
H --> C2[MCP client] <-->|Streamable HTTP + OAuth| S2[Remote server<br/>company API]
S1 --> T1[tools · resources · prompts]
S2 --> T2[tools · resources · prompts]
A fast-moving standard
These pages follow the 2026-07-28 MCP spec and the Python SDK mcp 2.x (where FastMCP became
MCPServer). Older tutorials use the initialize handshake and FastMCP; page 1 explains both, and the SDKs
still talk to older servers and clients.
Before you start
These pages assume structured output & tool calling, ReAct from scratch and Tools and MCP. Some async Python helps for pages 3-6: see async programming.
Back to: Notes overview