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

All python server commands · Model Context Protocol (MCP) 1 cheatsheet

Was this page helpful?