Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Model Context Protocol SDK (Python)

Python SDK for building MCP servers and clients to extend AI agent capabilities.

Agent, MCP and tool librariesPYPI

GitHubWebsite

1. License

License from PyPI classifier.

github.com/modelcontextprotocol/python-sdk

From 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

83 / 100
Gid Score, #59 overall
82M
downloads a week, pypi
24.9K
GitHub stars
499
agent projects use it
Model Context Protocol SDK (Python): downloads per weekPyPI, mcp 81,015,080
Model Context Protocol SDK (Python): GitHub starsmodelcontextprotocol/python-sdk 24,948

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

269 projects, 8.2%
221 projects, 7.3%
183 projects, 7.5%
17 projects, 5.0%
16 projects, 3.4%
15 projects, 4.5%
13 projects, 2.8%
9 projects, 3.2%

Often used with

In 36.5% of its projects
In 33.7% of its projects
In 28.7% of its projects
In 24.6% of its projects
In 25.1% of its projects
In 20.4% of its projects
In 15.6% of its projects
In 15.0% of its projects

Model Context Protocol SDK (Python) in practice

Strengths

Type hints become the tool schema

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.

Hosts build input forms from your signatures

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.

Server and client in one install

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.

Mounts inside an existing FastAPI or Starlette app

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

v2 breaks v1 imports, starting with FastMCP

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

Pin below 2 if you have not migrated

The maintainers advise packages that depend on <code>mcp</code> to keep a <code>&lt;2</code> upper bound until they move to v2. v1.x still gets critical bug fixes and security patches.

httpx is gone from the dependency tree

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

MITGid 8382M/wk

Pydantic AI

AI agent framework built with Pydantic for structured, typed agent development.

MITGid 641.8M/wk

Semantic Kernel

Microsoft SDK for integrating LLMs with traditional code for AI applications.

MITGid 5585.6K/wk

Compare Model Context Protocol SDK (Python) with another tool

Get started

Install it.

pip install mcp

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## 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.