MCP / Python

MCP server in Python.

Python is the second-most-common MCP server language after TypeScript. The official SDK is Pydantic-aware, async-friendly, and works equally well on `pip install` or `uvx` distribution. Here is the practical guide.

Completely free for 30 days. No credit card required.

01Details

Two paths: SDK direct vs FastMCP wrapper

01

mcp package on PyPI — the official Anthropic SDK. Lower-level, more boilerplate, full control.

02

fastmcp — community Pydantic-flavoured wrapper that feels like FastAPI for MCP. Decorator-based tool registration. Quicker for small servers.

03

Most production servers in the wild use the official SDK. Most prototypes use FastMCP. Either ships to PyPI cleanly.

02Details

Minimum viable (official SDK)

01

pip install "mcp[cli]" (or uv add "mcp[cli]") — the [cli] extra brings the mcp dev / mcp install commands you'll want. Async-only — import asyncio at the entry point.

02

Create a Server(name, version). Register tools with @server.call_tool() decorators returning typed responses.

03

Wire stdio_server() as the transport. The whole skeleton is ~25 lines.

04

Run with python -m your_module or expose via [project.scripts] in pyproject.toml for uvx your-mcp distribution.

03Details

pyproject.toml for PyPI publish

01

Use Hatch, Poetry, or PDM — all build PEP 517 wheels that PyPI accepts.

02

Declare [project.scripts] your-mcp = "your_module:main" so uvx your-mcp works directly from the source.

03

Include py.typed in the package so mypy/pyright see your types — Python MCP clients increasingly type-check tool schemas.

04

Pin mcp >= <last-known-good-version> — early-version SDK ships breaking minors occasionally.

04Details

Production patterns

01

Pydantic v2 BaseModel for every tool's input schema. The SDK reads them as JSON Schema for the agent.

02

Wrap downstream HTTP calls in httpx.AsyncClient (async) or httpx.Client (sync) — both are first-class.

03

Error handling: raise McpError with a clear code + message. Agents read the code; humans read the message.

04

Auth: read API key from env at startup; never accept it as a tool input (agents will leak it into chat history).

05Details

Distribution

01

Publish to PyPI: python -m buildtwine upload dist/*.

02

Tag your release in git (v0.1.0). Add an mcpName field to pyproject.toml metadata if listing on the official MCP registry.

03

MCP clients install via { "command": "uvx", "args": ["your-mcp"], "env": { "YOUR_API_KEY": "..." } }.

04

For users on pip instead of uv: pipx install your-mcp then point the command at the installed binary.

06Details

Auto-generation from OpenAPI (preview)

01

Python SDK ships today. Python MCP-server emission is in preview alongside the same pipeline.

02

Preview output: one tool per operation with Pydantic v2 schemas derived from your components/schemas.

03

Will ship to PyPI under your scope so uvx your-co-mcp (or pipx install your-co-mcp) works directly. Reach out if MCP generation is a launch requirement.

04

Compatibility report runs on every spec change for SDKs today; MCP-tool drift will join the same report once GA.