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.py4. 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
- Use clear tool names and descriptions; the model chooses tools by reading them.
- Validate inputs and return short, useful text.
- Do not expose destructive actions without confirmation.
- Add the
mcp-servertopic to your GitHub repository and Socketlist will list it automatically.