Model Context Protocol SDK (Python)
Python SDK for building MCP servers and clients to extend AI agent capabilities.
3. Used by agents' projects
Dependency in 499 public GitHub projects set up for AI coding agents that we scanned (8.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
py.sdk.modelcontextprotocol.io/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Model Context Protocol SDK (Python) does
One official package covers both sides of MCP in Python: you write servers as plain type-hinted functions, and the same install gives you a client. The current v2 line renames and removes enough v1 API that older tutorials no longer run as written.
Model Context Protocol SDK (Python) popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Model Context Protocol SDK (Python) is used
- Model Context Protocol SDK (Python) is a dependency in 499 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (30.7% of the 1,623 Python ones), #2 of 192 in agent, mcp and tool libraries.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,392; those are left out of every share on this page.
- The most used alternative in our scan is Pydantic AI (16 projects).
- Projects that use it most often also use Pydantic (36.5%), python-dotenv (33.7%), Uvicorn (28.7%).
- It is more common in projects set up for Claude Code (8.2%) than for OpenAI Codex (2.8%).
By coding agent
Often used with
Model Context Protocol SDK (Python) in practice
Strengths
The docs' first example is two decorated functions. It needs no hand-written JSON Schema, request parsing or validation code. In the docs' words, <code>a: int, b: int</code> is the schema.
The docs say the MCP Inspector builds a form with required integer fields straight from the function's type hints. They say Claude and other MCP hosts do the same.
The same package that serves tools also has a <code>Client</code>. The README shows it in about 10 lines. Given a URL, <code>Client</code> uses Streamable HTTP. It can also launch a local server as a stdio subprocess or take a custom transport.
You do not need a separate service. The docs have a page on mounting an MCP server inside a FastAPI or Starlette app you already run.
Watch out for
In v2, <code>FastMCP</code> is now <code>MCPServer</code>. Code that imports <code>mcp.server.fastmcp</code> fails on import. The migration guide lists more renames: camelCase fields became snake_case, and <code>McpError</code> became <code>MCPError</code>.
The maintainers advise packages that depend on <code>mcp</code> to keep a <code><2</code> upper bound until they move to v2. v1.x still gets critical bug fixes and security patches.
v2 depends on <code>httpx2</code> instead of <code>httpx</code> and <code>httpx-sse</code>. If your own code imported <code>httpx</code> only because v1 installed it, that import now fails. The traceback never mentions mcp.
A complete MCP server: one tool, one templated resource
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.resource("greeting://{name}")
def greeting(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"More about Model Context Protocol SDK (Python)
Packages around it
- pydantic: Data validation
- python-dotenv: .env config loading
- uvicorn: ASGI server
- fastapi: Web framework
- httpx: Async HTTP client
- requests: Sync HTTP client
More in Agent, MCP and tool libraries
Alternatives
Model Context Protocol SDK (Python) This page
AI agent framework built with Pydantic for structured, typed agent development.
Microsoft SDK for integrating LLMs with traditional code for AI applications.
Compare Model Context Protocol SDK (Python) with another tool
Get started
Install it.
pip install mcpRules for your agent
## MCP Python SDK
- On v2, import `MCPServer` from `mcp.server`. `mcp.server.fastmcp` is the v1 path and fails with `ModuleNotFoundError`.
- Put type hints on every tool parameter and return value, and write a docstring. The SDK builds the tool schema from them.
- Install `mcp[cli]` when you need `mcp dev`, `mcp run` or `mcp install`. `mcp dev` also needs `npx` on PATH for the Inspector.
- Do not pass transport options such as `port` to the `MCPServer` constructor. In v2 that raises `TypeError`.
- Use `streamable_http_client` (the `streamablehttp_client` alias is removed). Pass `httpx2` objects, not `httpx`, to `http_client=` and `auth=`.
- In a sync `def` handler, do not call `asyncio.get_running_loop()`. v2 runs sync handlers on a worker thread, so it raises `RuntimeError`.
- If the project is still on v1, keep `mcp` pinned below 2 until it is migrated.