# MCP Python SDK

> The official Python SDK for building Model Context Protocol (MCP) servers and clients, enabling standardized LLM context integration via tools, resources, and prompts.

The MCP Python SDK is the official Python implementation of the Model Context Protocol, maintained by the `modelcontextprotocol` organization on GitHub. It provides everything needed to build MCP servers that expose data and functionality to LLM applications, as well as MCP clients that connect to those servers. The library is published on PyPI as `mcp` and is licensed under the MIT License.

## What It Is

The Model Context Protocol (MCP) is an open standard that lets applications provide context to LLMs in a structured, transport-agnostic way. The Python SDK implements the full MCP specification, covering server construction, client connectivity, transport layers (stdio, SSE, and Streamable HTTP), and all protocol lifecycle events. It ships two server layers: a high-level `FastMCP` interface for rapid development and a low-level `Server` class for full protocol control.

## Core Primitives and Architecture

The SDK organizes MCP functionality around three protocol primitives:

- **Resources** — read-only data endpoints (analogous to HTTP GET), used to load information into an LLM's context
- **Tools** — executable functions with side effects (analogous to HTTP POST), exposed to the LLM for taking actions
- **Prompts** — reusable interaction templates that define structured conversation patterns

The `FastMCP` class wraps these primitives with Python decorators (`@mcp.tool()`, `@mcp.resource()`, `@mcp.prompt()`), automatic type-based structured output validation via Pydantic, and a `Context` object injected into handlers for logging, progress reporting, resource reading, and LLM sampling.

## Transport and Deployment Model

The SDK supports three transport mechanisms:

- **stdio** — for local process-based integrations (e.g., Claude Desktop)
- **SSE (Server-Sent Events)** — legacy HTTP streaming transport, now superseded
- **Streamable HTTP** — the recommended production transport, supporting stateful and stateless modes, resumability via event stores, and ASGI mounting into existing Starlette or other ASGI applications

Streamable HTTP servers can be mounted at custom paths, support host-based routing, and can run multiple MCP servers within a single ASGI application. CORS configuration is documented for browser-based clients.

## Authentication and Advanced Features

The SDK includes OAuth 2.1 resource server support via `mcp.server.auth`, where MCP servers act as Resource Servers validating tokens from separate Authorization Servers. It implements RFC 9728 (Protected Resource Metadata) for AS discovery. Client-side OAuth is also supported through `OAuthClientProvider`. Additional advanced capabilities include:

- Elicitation (form-mode and URL-mode) for requesting structured user input during tool calls
- LLM sampling via `ctx.session.create_message()`
- Pagination for large dataset list operations
- Structured output with schema validation for tool return types
- Lifespan management for startup/shutdown resource initialization

## Update: v1.27.1

The repository's latest stable release is **v1.27.1**, published on 2026-05-08. The README notes that v1.x is the current stable branch, while v2 is in pre-alpha development on the `main` branch with separate documentation at `README.v2.md`. The project was created in September 2024 and has seen rapid iteration, with the GitHub repository reporting over 23,000 stars and more than 3,400 forks as of the last recorded update.

## Features
- FastMCP high-level server interface with decorator-based API
- Low-level Server class for full protocol control
- Resources, Tools, and Prompts primitives
- Structured output with Pydantic validation
- stdio, SSE, and Streamable HTTP transports
- ASGI mounting for Starlette and other frameworks
- OAuth 2.1 resource server and client support
- Elicitation (form-mode and URL-mode) for user input during tool calls
- LLM sampling via session.create_message()
- Progress reporting and logging via Context object
- Pagination support for large dataset list operations
- Lifespan management for startup/shutdown resource initialization
- MCP Inspector integration for development and debugging
- Claude Desktop integration via mcp install
- CORS configuration for browser-based clients
- Stateful and stateless Streamable HTTP operation modes
- Resumability with event stores
- Host-based routing for multi-server ASGI deployments

## Integrations
Claude Desktop, Claude Code, MCP Inspector, Starlette, FastAPI (ASGI), Pydantic, uv, pip, PyPI, OAuth 2.1 Authorization Servers

## Platforms
WINDOWS, LINUX, API, DEVELOPER_SDK, CLI

## Pricing
Open Source

## Version
v1.27.1

## Links
- Website: https://modelcontextprotocol.github.io/python-sdk/
- Documentation: https://modelcontextprotocol.github.io/python-sdk/
- Repository: https://github.com/modelcontextprotocol/python-sdk
- EveryDev.ai: https://www.everydev.ai/tools/mcp-python-sdk
