server.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Run the example
Save the code above as
server.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
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/90_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")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U fastmcp
Run the example
server.py, then run:python server.py
Was this page helpful?