MCP Python SDK
ActiveDescription
MCP Python SDK is the official Python implementation for building MCP servers and agent-side integrations with a standardized tool protocol.
Key Features
- FastMCP high-level interface — quickly define MCP Server tools, resources and prompts with decorators
- Multi-transport support — supports stdio, SSE and Streamable HTTP standard transport methods
- Structured output — tool return values automatically serialized into structured JSON responses
- Resource and prompt system — expose data via Resources, define interaction templates via Prompts
- OAuth authentication support — built-in OAuth authentication flow in client
- ASGI mounting — mountable into existing FastAPI/Starlette apps as sub-applications
Use Cases
💡 Quickly build MCP Servers exposing database query capabilities for LLM applications
💡 Wrap existing Python APIs into MCP-compatible tool services for agent invocation
💡 Build local MCP Servers connected to Claude Desktop for tool extensions
💡 Mount MCP Servers in FastAPI apps to provide standardized LLM context interfaces
💡 Build MCP clients to connect to and invoke any standard MCP Server
Categories
Quick Start
uv init mcp-server-demo
cd mcp-server-demo
uv add "mcp[cli]"
# server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Demo", 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:
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run(transport="streamable-http")