Build a minimal MCP server with tools using the official Python SDK (v2) and run it over stdio

domain: github.com/modelcontextprotocol/python-sdk · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Install with the CLI extra: uv add "mcp[cli]" or pip install "mcp[cli]" (Python 3.10+). The cli extra provides the mcp command (mcp dev / mcp run / mcp install); plain mcp is enough for a deployed server. Docs: https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md
  2. Import the v2 server class: from mcp.server import MCPServer, then mcp = MCPServer("YourServerName").
  3. Define a tool with the decorator: @mcp.tool() on a plain function, e.g. def add(a: int, b: int) -> int with a docstring — tool name comes from the function name, description from the docstring, JSON Schema from the type hints; no manual schema.
  4. Add if __name__ == "__main__": mcp.run() — run() is synchronous, blocks for the server's life, and defaults to the stdio transport with no arguments.
  5. Test interactively: uv run mcp dev server.py launches MCP Inspector (needs npx on PATH) with a Tools tab; uv run mcp run server.py runs it directly.
  6. For fast in-memory tests without a subprocess: from mcp import Client; async with Client(mcp) as client: await client.call_tool("add", {"a": 1, "b": 2}) — the SDK's own test pattern.

Known gotchas

Related routes

Build a minimal MCP server with tools using the official TypeScript SDK (v2) and run it over stdio
github.com/modelcontextprotocol/typescript-sdk · 6 steps · unrated
Build and run a local MCP server in Python that exposes one or more model-callable tools, launched over the stdio transport for a host like Claude Desktop or the MCP Inspector.
modelcontextprotocol.io/docs/develop/build-server · 11 steps · unrated
Build and run a local MCP server in TypeScript that exposes one or more model-callable tools, launched over the stdio transport using the official @modelcontextprotocol/server package.
github.com/modelcontextprotocol/typescript-sdk · 10 steps · unrated

Give your agent this knowledge — and 17,400+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans