Building a Python MCP Server
The same calculator, using the Python SDK (FastMCP).
Python is the most popular language for MCP servers. The modern way is FastMCP, a decorator-based wrapper over the official SDK.
Setup
mkdir calc-py && cd calc-py
python3 -m venv .venv && source .venv/bin/activate
pip install mcp
The server
Create server.py:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("calc")
@mcp.tool()
def multiply(a: float, b: float) -> str:
"""Multiply two numbers and return the product."""
return str(a * b)
@mcp.tool()
def add(a: float, b: float) -> str:
"""Add two numbers."""
return str(a + b)
if __name__ == "__main__":
mcp.run() # defaults to stdio transport
Run it: python server.py.
Register it
{
"mcpServers": {
"calc-py": {
"command": "python",
"args": ["/full/path/to/server.py"]
}
}
}
FastMCP niceties
- Docstrings become tool descriptions β the model reads them.
- Type hints become the JSON schema β no manual schema writing.
- You can also expose resources:
@mcp.resource("file://notes")
def notes() -> str:
return "Buy milk. Ship the feature."
Python vs TypeScript
- Python (FastMCP): fastest to write, best for data/ML and quick scripts.
- TypeScript SDK: first-class, great for Node projects and the richest type story.
- Both speak the same protocol β a client can't tell the difference.
The model calls multiply by name, reads your docstring to understand it, and validates arguments against the type hints. Docstrings are not optional decoration β they're the UI.