# Model Context Protocol SDK (Python) — card for AI agents

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

Category: Agent, MCP and tool libraries · PyPI package `mcp` · latest version 2.3.0 (checked 2026-11-01)
Install: `pip install mcp`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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.

## Docs written for agents
- [llms.txt (index of the docs)](https://py.sdk.modelcontextprotocol.io/llms.txt)

## What it is
- The MCP Python SDK is the official Python implementation of the Model Context Protocol. The README describes the protocol as a way to build servers that expose data and functionality to LLM applications. It puts it as "like a web API, but designed for LLM interactions." The repository was created on 2024-09-24, is MIT licensed, and needs Python 3.10+.
- One package does three jobs. It builds servers that expose tools, resources and prompts. It builds clients that connect to any MCP server. It speaks the stdio, Streamable HTTP and SSE transports. On the server side you decorate ordinary functions with `@mcp.tool()` or `@mcp.resource(...)`. The docs say the type hints and docstring are all the SDK needs: it handles schema, parsing, validation and protocol work.
- The docs site covers v2, "the current stable release line". v1.x has separate docs and a maintenance line. The SDK is for Python developers who want to expose their code to MCP hosts, or who want to call MCP servers from their own application.

## Caveats
- v2 breaks v1 imports, starting with FastMCP: In v2, `FastMCP` is now `MCPServer`. Code that imports `mcp.server.fastmcp` fails on import. The migration guide lists more renames: camelCase fields became snake_case, and `McpError` became `MCPError`.
- Pin below 2 if you have not migrated: The maintainers advise packages that depend on `mcp` to keep a `<2` 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 `httpx2` instead of `httpx` and `httpx-sse`. If your own code imported `httpx` only because v1 installed it, that import now fails. The traceback never mentions mcp.
- New hard dependencies, OpenTelemetry on by default: v2 adds `opentelemetry-api` as a required dependency because trace propagation ships enabled. It also raises the minimum versions of shared packages such as pydantic, anyio and sse-starlette. Those can clash with existing pins.
- Minor releases change wire behaviour: The v2.3.0 notes open with a list of behaviour changes. Among them: the `httpx2` floor is raised, tools with an invalid `x-mcp-header` annotation now fail at registration, and empty `_meta` is no longer sent. The notes ask readers to skim these first.

## Numbers (AgentGid data)
- Gid Score: 82.7 (#59 of all tools, 2 of 192 in its category)
- Used in 499 public projects set up for AI coding agents (8.0%)
- Downloads last week: 81,959,163 (as of 2026-11-24), +21.6% over 4 weeks
- GitHub stars: 24,948 (as of 2026-11-24)
- Last push: 2026-11-17

## Often used with
Pydantic 36.5%, python-dotenv 33.7%, Uvicorn 28.7%, httpx 24.6%, FastAPI 25.1%, Requests 20.4%

## Checked alternatives (same job)
- Pydantic AI: https://agentgid.com/tools/pydantic-ai/agent.md
- Semantic Kernel: https://agentgid.com/tools/semantic-kernel/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/mcp/
- Homepage: https://modelcontextprotocol.io
- Repository: https://github.com/modelcontextprotocol/python-sdk
- Source: https://github.com/modelcontextprotocol/python-sdk#readme
- Source: https://github.com/modelcontextprotocol/python-sdk
- Source: https://github.com/modelcontextprotocol/python-sdk/releases
- Source: https://py.sdk.modelcontextprotocol.io/
- Source: https://py.sdk.modelcontextprotocol.io/migration/index.md

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
