Python Server

Building MCP Servers in Python

MCP also has a Python SDK. If Python is your language of choice, you can build servers with the same capabilities.
python
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("weather-server")

@mcp.tool()
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    # Your weather API logic here
    return f"Weather in {city}: 72°F, Sunny"

@mcp.tool()
def get_forecast(city: str, days: int = 5) -> str:
    """Get weather forecast for a city."""
    return f"{days}-day forecast for {city}: Mostly sunny"

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

Tip:Python's FastMCP makes it incredibly simple to build servers. Just use the @mcp.tool() decorator and you're done!

PreviewTypeScriptRead Only
Copy this code and run it locally with npx tsx server.ts

💬 Got questions? Ask me anything!