C.W.K.
Stream
Lesson 05 of 08 · published

MCP Servers in the Agent SDK

~16 min · mcp, model-context-protocol, servers

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

Why MCP matters here

MCP (Model Context Protocol) is how the Agent SDK extends beyond its built-in tools. You launch an MCP server (your code, or third-party) and the SDK connects, learns the server's tools, and exposes them to the model. Same protocol Claude Code uses; same protocol Cursor and Windsurf use. Build once, use everywhere.

Three transport options

MCP servers run over stdio (subprocess), SSE (HTTP server-sent events), or HTTP (request/response). stdio is the cheapest and most common — your server is a child process the SDK spawns. SSE and HTTP fit when the server runs separately (containers, remote services).

cwkPippa exposes capabilities through MCP

Pippa's vault, weather data, image generation, and other personal-data capabilities run as MCP servers. The Claude brain (Agent SDK) connects to all of them. The same MCP servers can be wired into Claude Code or Cursor for the same Pippa capabilities in any client.

Principle: Build capabilities as MCP servers and your code outlives any single client. The protocol is the durable surface.

Code

Attaching MCP servers via options·python
from claude_agent_sdk import ClaudeAgentOptions

options = ClaudeAgentOptions(
    cwd="/srv/agent",
    mcp_servers={
        "pippa-vault": {
            "type": "stdio",
            "command": "node",
            "args": ["/Users/you_username/Obsidian/pippa/mcp/vault-server.js"],
        },
        "weather": {
            "type": "stdio",
            "command": "python",
            "args": ["-m", "my_weather_mcp"],
            "env": {"WEATHER_API_KEY": os.environ["WEATHER_API_KEY"]},
        },
        "shared-cache": {
            "type": "http",
            "url": "https://internal.example.com/mcp/cache",
            "headers": {"Authorization": f"Bearer {token}"},
        },
    },
)
Discover what tools an MCP server exposes·bash
# Inside the Claude Code CLI (interactive):
#   /mcp list
#
# Or programmatically with the SDK, after connect():
#   await client.list_tools()  # returns the merged tool catalog from all attached MCP servers

External links

Exercise

Identify one capability your agent currently calls inline. Build a small MCP server for it (stdio is fine). Wire it into the Agent SDK options. Verify the model can call it just like a built-in tool.
Hint
If you have an HTTP API you wrote yourself, MCP is a thin wrapper that makes it Claude-callable across clients — usually 50-100 lines of glue code.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.