Files
Max Isbey d6a15f6d52 [v1.x] Move the v1.x docs to /v1/ and mark v1.x as the maintenance line
With v2 becoming the stable release, v1.x moves from the site root to
/v1/ and stops deploying the site itself: the combined site is built and
deployed from main, which builds this branch's docs into /v1/ via the
new scripts/docs/build.sh. A `docs` CI job runs that same script, so a
change that breaks the v1 docs fails on this branch rather than at
main's next deploy. site_url and the package's Documentation URL move to
/v1/ so canonical links, the sitemap, and llms.txt point at where these
pages are actually served.

The README and landing page now describe v1.x as the maintenance line
and send new users to the v2 docs, and every install line pins `mcp<2`
so a reader following these docs stays on the 1.x line now that an
unpinned install selects 2.x.
2026-07-25 23:49:57 +00:00

2.7 KiB

MCP Python SDK

!!! tip "You are viewing the v1.x maintenance-line documentation" v2 is the current stable release: its documentation is at https://py.sdk.modelcontextprotocol.io/. Staying on v1.x for now? Pin mcp<2 (for example mcp>=1.28,<2) so an unpinned install doesn't move you to 2.x.

The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction.

This Python SDK implements the full MCP specification, making it easy to:

  • Build MCP servers that expose resources, prompts, and tools
  • Create MCP clients that can connect to any MCP server
  • Use standard transports like stdio, SSE, and Streamable HTTP

If you want to read more about the specification, please visit the MCP documentation.

Quick Example

Here's a simple MCP server that exposes a tool, resource, and prompt:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Test Server", json_response=True)


@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b


@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"


@mcp.prompt()
def greet_user(name: str, style: str = "friendly") -> str:
    """Generate a greeting prompt"""
    return f"Write a {style} greeting for someone named {name}."


if __name__ == "__main__":
    mcp.run(transport="streamable-http")

Run the server:

uv run --with "mcp<2" server.py

Then open the MCP Inspector and connect to http://localhost:8000/mcp:

npx -y @modelcontextprotocol/inspector

Getting Started

  1. Install the MCP SDK
  2. Build servers - tools, resources, prompts, transports, ASGI mounting
  3. Write clients - connect to servers, use tools/resources/prompts
  4. Explore authorization - add security to your servers
  5. Use low-level APIs - for advanced customization
  6. Protocol features - MCP primitives, server capabilities

API Reference

Full API documentation is available in the API Reference.

llms.txt

Reading with an LLM? This documentation is also published in the llms.txt format: llms.txt is an index of the pages, and llms-full.txt contains every page in a single file.