Overview
The Python MCP SDK is the official library for building MCP servers in Python. It supports tools, resources, prompts, transports, and the stdio and streamable-http transport.
Installation
pip install mcpMinimal Server Example
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("my-server")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
if __name__ == "__main__":
mcp.run(transport="stdio")Adding a Tool
Tools are the primary way MCP servers expose functionality to clients. Each tool has a name, input schema, and handler function.
@mcp.tool()
async def get_weather(city: str) -> dict:
"""Get weather for a city."""
return await fetch_weather(city)Supported Features
tools
resources
prompts
transports
Testing Your Server
- Start the server and verify it prints no startup errors.
- Run
npx @modelcontextprotocol/inspectorand connect over stdio. - Call your tools and verify they return the expected responses.
- Connect from Claude Desktop and confirm tool visibility.