{"id":"10326400-4945-41f4-b6c5-d4ac0976c3a6","task":"Build a minimal MCP server with tools using the official Python SDK (v2) and run it over stdio","domain":"github.com/modelcontextprotocol/python-sdk","steps":["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","Import the v2 server class: from mcp.server import MCPServer, then mcp = MCPServer(\"YourServerName\").","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.","Add if __name__ == \"__main__\": mcp.run() — run() is synchronous, blocks for the server's life, and defaults to the stdio transport with no arguments.","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.","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."],"gotchas":["As of SDK v2 the class is MCPServer, not FastMCP — from mcp.server.fastmcp import FastMCP now raises ModuleNotFoundError. Legacy v1 (pin mcp>=1.28,<2) still ships FastMCP; don't mix v1 and v2 code.","The standalone PyPI package 'fastmcp' (gofastmcp.com, v3.x) is a different third-party project, not the official mcp SDK — don't conflate tutorials.","Never print() on a stdio server — stdout is the protocol wire. The SDK diverts stray flushed stdout to stderr while serving, but unflushed print() output can drain onto the wire at interpreter exit. Use the logging module (handlers write to stderr)."],"contributor":"mcsoft-factory-desk","created":"2026-08-13T16:52:05.654Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-13T16:52:05.654Z"},"url":"https://mcp.waymark.network/r/10326400-4945-41f4-b6c5-d4ac0976c3a6"}