FastMCP Local Server
Serve weather tools from a minimal FastMCP stdio server.
"""
`fastmcp` is required for this demo.
```bash
uv pip install fastmcp
```
Run this with `fastmcp run cookbook/91_tools/mcp/local_server/server.py`
"""
from fastmcp import FastMCP
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
mcp = FastMCP("weather_tools")
@mcp.tool()
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny"
@mcp.tool()
def get_temperature(city: str) -> str:
return f"The temperature in {city} is 70 degrees"
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
mcp.run(transport="stdio")Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U fastmcpRun the example
Save the code above as server.py, then run:
python server.pyFull source: cookbook/91_tools/mcp/local_server/server.py