Model Context Protocol (MCP) 1 · Python server
Create a Python server with a tool
Define a function the model can call. The docstring and type hints become the tool's description and schema.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
if __name__ == "__main__":
mcp.run()
Official Model Context Protocol (MCP) 1 documentation
More python server commands
- Install the Python SDK
- Expose a resource
- Expose a prompt template
- Serve over HTTP
- Log without breaking stdio
- Test with the dev server
All python server commands · Model Context Protocol (MCP) 1 cheatsheet