MCP Python SDK
MCP Python SDK is the official Python implementation of the Model Context Protocol (MCP), enabling developers to build MCP servers and clients that expose data and functionality to LLM applications in a standardized way. It simplifies development by handling protocol details, allowing you to focus on defining tools, resources, and prompts with type hints. This SDK is for Python developers who want to integrate their services with AI assistants or build custom MCP clients.
✨ Key features
- Build MCP servers exposing tools, resources, and prompts.
- Build MCP clients connecting to any MCP server.
- Supports stdio, Streamable HTTP, and SSE transports.
- Type-hinted functions automatically generate JSON Schema.
- Includes CLI tools: mcp dev, run, and install.
- Compliant with MCP specification 2026-07-28 and earlier.
🎯 Use cases
- Create a server that provides a calculator tool to an LLM.
- Expose a templated resource like a greeting endpoint.
- Build a client that calls tools on a remote MCP server.
- Develop a custom MCP server for internal data access.
- Prototype MCP servers using the Inspector via mcp dev.
📦 Installation
🧰 Requirements: Python 3.10+.
uv add "mcp[cli]" # or: pip install "mcp[cli]"
The cli extra adds the mcp command-line tool (mcp dev, mcp run, mcp install) on top of the SDK; install plain mcp if you don't need it. For one-off commands, uv run --with "mcp[cli]" mcp ... works without a project.
🚀 Usage
Create a server.py:
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}!"
Run it with:
uv run mcp dev server.py
Then call the add tool with a=1, b=2 to get 3.
⚠️ Good to know
This is v2 of the SDK; v1.x is available on a separate branch for those not ready to migrate, and the README notes that the project is actively developed with potential rough edges.
❓ FAQ
What Python version is required?
Python 3.10 or higher is required.
How do I install the SDK?
Use uv add "mcp[cli]" or pip install "mcp[cli]" to include the CLI tools, or install plain mcp if you don't need them.
What transports are supported?
The SDK supports stdio, Streamable HTTP, and SSE transports.
Is v1 still available?
Yes, v1.x is maintained on the v1.x branch with critical bug fixes and security patches, and is documented at <https://py.sdk.modelcontextprotocol.io/v1/>.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.