The MCP Python SDK is the official Python implementation of the Model Context Protocol, a standard for exposing data and functionality to LLM applications. It's for Python developers who want to build servers that LLM hosts (like Claude Desktop or other MCP-aware apps) can call into, or clients that talk to any MCP server. Think of MCP as a web API convention purpose-built for LLM tool use.
The SDK turns typed Python functions into a full MCP server: a function's type hints become the JSON Schema, and its docstring becomes the description the LLM sees. There's no manual request parsing or protocol handling to write. The same package also implements the client side, so you can connect to any MCP server over stdio, HTTP, or SSE, or even talk to a server object directly in-process for testing.
@mcp.tool(); type hints generate the schema automatically@mcp.resource("scheme://{param}") patterns that map to function argumentsClient connects to a remote URL, a stdio subprocess, a custom transport, or an in-memory server object for testsmcp command (via the cli extra) provides mcp dev, mcp run, and mcp install for local development and inspectionmcp dev server.py opens your server in the Inspector UI to call tools interactivelyThis SDK fits when you're building a backend that an LLM application needs to call, such as exposing internal APIs, databases, or file systems as tools an AI assistant can use. It also fits when you're building an MCP-compatible client or host application that needs to connect to third-party MCP servers written in Python or any other language.
It's a good fit for quick prototyping too: a working tool server is a dozen lines of code, testable in-process without spinning up a transport. It's less useful if you're not working with LLM tool-calling at all, or if your stack has no Python component and another language's MCP SDK is a more natural fit for your team. If you're still on MCP Python SDK v1.x and not planning to migrate, note that plain pip install mcp now installs v2, so pin mcp>=1.28,<2 until you're ready to move.
Requires Python 3.10 or later. Install with uv or pip:
uv add "mcp[cli]" # or: pip install "mcp[cli]"
The cli extra adds the mcp command-line tool on top of the base SDK. Skip it if you only need the library. For a one-off run without a project:
uv run --with "mcp[cli]" mcp ...
A minimal server looks like this:
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 through the Inspector to try it out:
uv run mcp dev server.py
A client is just as short and can connect to the same server directly or over HTTP:
import asyncio
from mcp import Client
from server import mcp
async def main() -> None:
async with Client(mcp) as client:
result = await client.call_tool("add", {"a": 1, "b": 2})
print(result.structured_content)
asyncio.run(main())
Swapping mcp for a URL like "http://localhost:8000/mcp" connects the same client code to a remote server instead.