This is a a pratical example of how to setup MCP with UV in Python
- Create dir and cd into it
- uv init hello-world --python 3.12.9
- source ./venv/bin/activate
- uv add "mcp[cli]"
- uv run mcp dev main.py
- Or npx @modelcontextprotocol/inspector uv --directory ./ "run" "main.py"
Sample main.py
from mcp.server.fastmcp import FastMCP
# Create an MCP server
mcp = FastMCP("Weather Service")
@mcp.tool()
def get_weather(location: str) -> str:
"""Get the current weather for a specified location."""
return f"Weather in {location}: Sunny, 72°F"
# Run the server
if __name__ == "__main__":
mcp.run()