🔌 Socketlist

How to build your own MCP server in Python (in 10 minutes)

Build, test and connect a minimal MCP server with the official Python SDK and MCPServer, plus design tips.

Choose an SDK

Official SDKs exist for TypeScript, Python, C#, Java, Kotlin, Go and other languages. This guide uses the official Python SDK 2.x, which needs Python 3.11 or later. Older 1.x releases used FastMCP from mcp.server.fastmcp instead of MCPServer.

1. Set up the project

uv init demo && cd demo
uv add "mcp[cli]"

2. Write the server

A tool is a normal function with type hints and a docstring; the SDK turns them into the tool’s schema and description. mcp.run() starts a stdio server.

# server.py
from mcp.server import MCPServer

mcp = MCPServer("demo")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

if __name__ == "__main__":
    mcp.run()

3. Test it

Open it in the MCP Inspector to call your tools from a web UI:

uv run mcp dev server.py

4. Connect it to a client

Use an absolute path. Claude Desktop and Cursor take this entry; in Claude Code run claude mcp add demo -- uv run --with "mcp[cli]" mcp run /absolute/path/to/server.py.

{
  "mcpServers": {
    "demo": {
      "command": "uv",
      "args": ["run", "--with", "mcp[cli]", "mcp", "run", "/absolute/path/to/server.py"]
    }
  }
}

Design tips

Related guides

Best MCP servers for Claude Desktop (2026) · Best MCP servers for Cursor (2026)

Weekly MCP digest – new and trending MCP servers in your inbox.