You don’t have to wait for someone else to build an MCP server for your tools. Building one is surprisingly easy. Let’s build a simple server that returns the current weather (mocked) using Python.
Prerequisites
- Python 3.10+
pip install mcp
The Code (server.py)
from typing import Any
import asyncio
from mcp.server.fastmcp import FastMCP
# Initialize the server
mcp = FastMCP("weather-server")
@mcp.tool()
async def get_weather(city: str) -> str:
"""Get the weather for a specific city."""
# In real life, call an API here.
return f"The weather in {city} is Sunny and 25°C."
if __name__ == "__main__":
mcp.run()
How It Works
FastMCP: This is a high-level wrapper provided by the official Python SDK. It handles all the JSON-RPC communication over stdio.@mcp.tool(): This decorator tells Claude “Hey, this function is available for you to use.”- Docstrings: The docstring “Get the weather…” becomes the description the AI sees. This is crucial for the AI to understand when to call the tool.
Hooking it up
Now add it to your claude_desktop_config.json:
"weather-server": {
"command": "python3",
"args": ["/path/to/server.py"]
}
Testing
Restart Claude and ask: “What is the weather in Tokyo?” It will call your Python function and reply: “The weather in Tokyo is Sunny and 25°C.”
Next Steps
This is just a toy example. But you can replace that return statement with:
- A query to your internal SQL database.
- A call to your JIRA API.
- A script that restarts your staging server.
The possibilities are endless once you start building your own tools.