AI/TLDR

MCP Python SDK

The official Python SDK for Model Context Protocol servers and clients

Agent Frameworks & BuildersOpen source
Latest
v2.2.0
Updated
7 Sep 2026
Language
Python
License
MIT
Coverage
1 story
$uv add "mcp[cli]" # or: pip install "mcp[cli]"

What's new

v2.2.07 Sep 2026

Streamable HTTP sessions now expire after 30 minutes idle and a server holds at most 10,000 at once, both configurable through new `session_idle_timeout=` and `max_sessions=` settings. HTTP client redirects are constrained to the endpoint's own origin, and OAuth issuer validation was extended to the legacy discovery path. The same changes shipped as 1.30.0 on the maintenance 1.x line.

Latest news

Overview

MCP Python SDK is the official Python library for the Model Context Protocol, the open standard that lets an LLM application discover and call capabilities hosted outside itself. One package covers both sides of the wire: you can write a server that publishes tools, resources and prompts, and you can write a client that connects to any MCP server and calls them.

The server side is decorator-driven. You annotate ordinary type-hinted Python functions with `@mcp.tool()` or `@mcp.resource()`, and the SDK derives the JSON Schema, the wire format and the protocol handshake from the signature and docstring. There is no schema file to maintain by hand and no JSON-RPC plumbing to write, which is what makes a working server fit in about fifteen lines.

Transport is a deployment choice rather than a rewrite. The same server runs over stdio for a local subprocess, or over Streamable HTTP when you want to host it as a network service; SSE is also supported. The SDK ships an OAuth layer for the HTTP transports, with issuer validation and per-server token-resource checks, so an exposed server can require real authorization instead of trusting whoever connects.

What it does

  • Define tools, resources and prompts from type-hinted Python functions using decorators — schemas are derived, not hand-written
  • One package for both servers (`MCPServer`) and clients (`Client`)
  • Transports for stdio, Streamable HTTP and SSE, chosen at run time rather than in code
  • OAuth support for HTTP transports, including authorization-server issuer validation and token-resource restriction
  • Streamable HTTP session controls: configurable idle timeout and a ceiling on concurrent sessions
  • A `mcp` CLI (via the `cli` extra) for developing and running servers locally

Getting started

Install the package with the CLI extra, write a server as decorated Python functions, then run it locally or serve it over Streamable HTTP and connect a client.

Install the SDK

The `cli` extra adds the `mcp` command-line tools; plain `mcp` works without them. Python 3.10 or newer is required.

bashbash
uv add "mcp[cli]"      # or: pip install "mcp[cli]"

Write a minimal server

Save this as server.py. The decorators turn each function into an MCP tool or resource; the type hints and docstring become its schema and description.

pythonpython
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 in the development inspector

This starts the server and opens the MCP development tooling against it, so you can call the tool by hand before wiring up a client.

bashbash
uv run mcp dev server.py

Serve it over HTTP and call it from a client

Start the same server on the Streamable HTTP transport, then connect with the SDK's client. A URL means Streamable HTTP — the transport you deploy.

bashbash
uv run mcp run server.py --transport streamable-http

Connect a client

The client is in the same package. Opening it as an async context manager handles the handshake and tears the session down on exit.

pythonpython
import asyncio
from mcp import Client

async def main() -> None:
    async with Client("http://localhost:8000/mcp") as client:
        result = await client.call_tool("add", {"a": 1, "b": 2})
        print(result.structured_content)  # {'result': 3}

asyncio.run(main())

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Expose an internal API or database as MCP tools that Claude, ChatGPT or a coding agent can call
  • Host an MCP server as a network service over Streamable HTTP with OAuth in front of it
  • Write a Python client that connects to third-party MCP servers and invokes their tools programmatically
  • Ship a local stdio server that an agent launches as a subprocess, with no network exposure

How MCP Python SDK compares

MCP Python SDK alongside other open-source agent frameworks & builders tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
DeepSeek Harness★ 215kDeepSeek AI's open-source agent harness (dsh), built on Cordis, where models, tools, skills, sessions, sandboxes, storage and the UI are all plugins composed through profiles.
AutoGPT★ 187kOne of the earliest autonomous agent projects, now a platform for building and running agents from reusable blocks and workflows.
DeerFlow★ 81.9kByteDance's open-source super agent harness built on LangGraph: skills, sub-agents, sandboxes, a filesystem and long-term memory for long-horizon research, coding and content tasks.
nanobot★ 47.9kLightweight self-hosted personal AI agent framework in Python, with a WebUI, terminal and chat-app channels, tools, long-term memory, MCP and scheduled automations.
Agno★ 42.1kA fast Python framework (formerly Phidata) for building agents with memory, tools, and multimodal inputs, plus a runtime for deploying them in production.
LangGraph★ 41.2kA library from the LangChain team for building stateful, graph-based agent workflows with explicit control over steps, memory, and human-in-the-loop checkpoints.
AgentGPT★ 36.3kAgentGPT lets you name a custom AI, give it a goal, and watch it plan tasks, run them, and learn from the results, all from a web browser.
MCP Python SDKThe official Python SDK for Model Context Protocol servers and clients