Favicon of MCP Python SDK

MCP Python SDK

Official Python SDK for building Model Context Protocol servers and clients that expose tools, resources, and prompts to LLMs.

MCP Python SDK website screenshot
MCP Python SDK GitHub repository preview

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.

Key features

  • Decorator-based tools: turn a plain Python function into an MCP tool with @mcp.tool(); type hints generate the schema automatically
  • Resources and templated URIs: expose data via @mcp.resource("scheme://{param}") patterns that map to function arguments
  • Full client implementation: Client connects to a remote URL, a stdio subprocess, a custom transport, or an in-memory server object for tests
  • Multiple transports: stdio, Streamable HTTP, and SSE are all supported out of the box, on both client and server sides
  • CLI tooling: the mcp command (via the cli extra) provides mcp dev, mcp run, and mcp install for local development and inspection
  • MCP Inspector integration: mcp dev server.py opens your server in the Inspector UI to call tools interactively
  • Prompts support: alongside tools and resources, servers can expose reusable prompt templates to hosts

Ideal use cases

This 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.

Installation

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.

Frequently asked questions

Share:

Stars
24.1K
Forks
3.8K
Last commit
15 hours ago
Repository age
2 years
License
MIT
Self-hosted
No
Activity score
84/100
View Repository
Built with:
Ad
Favicon

 

  
 

Similar to MCP Python SDK

Favicon

 

  
 
Favicon

 

  
 
Favicon