Chapter 5 · Part 3
Connect it to Claude
Your server works in the Inspector. Now let a real AI use it. Because it speaks MCP, connecting is a one-liner in each host — you don't touch the server code.
Claude Code
With the server running (python server.py), register it with one command:
claude mcp add --transport http my-server http://localhost:8000/mcpThat's it. In your next Claude Code session, ask something that needs your tools — "search my
notes for anything about the Q3 launch" — and Claude calls search_notes on your server, reads
the result, and answers. The same claude mcp add works for any MCP server, yours or someone
else's.
The Claude API
To use your server from your own code, the Claude API has an MCP connector: point it at the
server's URL and Claude calls the tools server-side. It needs two matching pieces — the server in
mcp_servers, and an mcp_toolset that references it by name:
from anthropic import Anthropic
client = Anthropic()
reply = client.beta.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
betas=["mcp-client-2025-11-20"],
mcp_servers=[
{"type": "url", "url": "http://localhost:8000/mcp", "name": "my-server"}
],
tools=[{"type": "mcp_toolset", "mcp_server_name": "my-server"}],
messages=[{"role": "user", "content": "Search my notes about the Q3 launch."}],
)
print(reply.content[-1].text)Listing a server in mcp_servers without a matching mcp_toolset entry (or vice-versa) is
rejected — the toolset's mcp_server_name must match the server's name. The connector is beta,
so it lives under client.beta.messages and takes the mcp-client-2025-11-20 flag.
A word on transports
How the client and server actually talk is the transport. MCP supports three:
- stdio — the server runs as a local subprocess the host launches. Great for local, personal servers; no ports, no network.
- Streamable HTTP — the server listens on a URL (what we've used). The right choice for a remote or shared server.
- SSE — an older HTTP-based transport you'll still see in the wild.
You pick it in one place — mcp.run(transport=...) — and nothing else in your server changes.
Your server is live in Claude. Last chapter: make it safe to expose, and where to go next.