Overview
The MCP Python SDK is the official Python implementation of the Model Context Protocol (MCP). It provides primitives and helpers to build MCP servers that expose data (Resources), functionality (Tools), and reusable prompt templates (Prompts) to LLM-based applications, and to create clients that consume those MCP servers. The SDK supports standard transports (stdio, SSE, Streamable HTTP), structured output validation, session and lifespan management, authentication hooks, and developer tooling such as an inspector and examples.
Key features
- Full implementation of the MCP specification for Python (server and client APIs).
- FastMCP: a high-level server class that simplifies declaring tools, resources, prompts and lifecycle hooks.
- Low-level Server API for fine-grained protocol control and custom transports.
- Multiple transports: stdio, SSE and Streamable HTTP (the recommended production transport).
- Structured output support (Pydantic models, TypedDicts, dataclasses) and automatic validation against output schemas.
- Elicitation support (form and URL modes) for interactive user input during tool execution, including a UrlElicitationRequiredError pattern.
- OAuth / TokenVerifier integration to act as a Resource Server validating tokens per MCP auth spec (RFC 9728 support for discovery).
- Progress reporting, logging/notifications, resource/tool/prompt list change notifications, and completions for prompt/resource arguments.
Installation & Quickstart
- Install via pip:
pip install "mcp[cli]"(or use the recommended uv workflow described in docs). - Example quickstart creates a FastMCP server, registers a simple tool (
add), a resource, and a prompt; run it with the streamable-http transport for easy testing and integration.
Developer ergonomics
- Rich examples in the repository (tools, resources, prompts, structured output, low-level server patterns, OAuth examples, mounting into Starlette, pagination, and clients).
- Utilities for building MCP clients and handling CallToolResult parsing, embedded resources, and image content.
- CLI/dev tooling integration via
uvand an MCP Inspector for interactive testing.
Compatibility & Stability
- The repository contains a
mainbranch with v2 of the SDK (in development, pre-alpha). The README notes an anticipated stable v2 release in Q1 2026 and recommends v1.x for production until v2 stabilizes. v1.x branch is maintained for bug and security fixes for a transition period.
Use cases
- Expose application state (databases, files, APIs) to LLMs in a standardized way.
- Implement model-invokable tools that perform actions or side effects with typed, validated outputs.
- Build clients and UIs that integrate with MCP servers using Streamable HTTP for scalable production deployments.
- Prototype LLM-centered integrations with OAuth-protected resources and interactive elicitation flows.
Contributing & License
- The project welcomes contributions; contributing guide is provided in the repository. The SDK is MIT licensed.
Links
- Documentation / API reference: https://modelcontextprotocol.github.io/python-sdk/
- Specification & protocol docs: https://modelcontextprotocol.io
- Repository: https://github.com/modelcontextprotocol/python-sdk
