Python Weather MCP Server
Enables AI agents to fetch real-time weather data for any location using the OpenWeatherMap API. Demonstrates how to build a simple MCP server that exposes weather information as a tool for LLMs.
README
Python Simple MCP Tutorial
This project demonstrates a simple weather server using the mcp library. It exposes a tool that returns real weather data for a given location using the OpenWeatherMap API.
MCP (Model Context Protocol) is a universal standard that enables AI agents (LLMs) to access data, tools and services. In this case, we will build a "server" that fetches real weather data for an LLM to interact with.
Setting Up
This project uses uv for package management. Go here for instructions on how to install uv.
uv venv
Activate the virtual environment:
source .venv/bin/activate
Install dependencies.
uv sync
API Key Setup
This project uses the OpenWeatherMap API to fetch real weather data. You'll need to:
- Sign up for a free account at OpenWeatherMap
- Get your API key from the dashboard
- Set the environment variable:
export OPENWEATHER_API_KEY=your_api_key_here
How To Run
To test the weather MCP server, execute the following command:
mcp dev src/mcp_weather.py
Then wait a while for to load, and click the link to "open inspector with token pre-filled". This will give you a UI you can use to test the MCP server right in your browser.
Deep Dive
How does our AI agent know how to use this MCP tool? Well, in short, it gets serialized into a JSON schema.
FastMCP automatically registers the get_weather function as a tool, extracting the schema from the function signature and docstring.
{
"name": "get_weather",
"description": "Get current weather for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": { "type": "string" }
},
"required": ["location"]
}
}
Then, the AI agent that we use (e.g. Claude Desktop, Cursor, or our own implementation) will know about these tools and know how to invoke them via prompt engineering. It will be turned into a prompt similar to this:
You have access to these tools:
- get_weather: Get current weather for a location
To use: <tool_call>{"name": "get_weather", "parameters": {"location": "Tokyo"}}</tool_call>
MCP Clients: Interacting with MCP Servers
If you want your AI agent to interact with MCP servers, you need an MCP client. Some UI tools (Claude Desktop and Cursor) have this built-in for you already. But you can do this programmatically via code as well.
What it usually boils down to is declaring your MCP server in a config file with instructions on how to access it. In the case of Claude Desktop, it looks something like this:
{
"mcpServers": {
"weather": {
"command": "uv",
"args": ["run", "[...]", "/[PATH_TO_PROJECT]/src/mcp_weather.py"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
}
}
}
(This example is simplified — refer to https://modelcontextprotocol.io/quickstart/user for more details)
And this will live inside the claude_desktop_config.json file which you can access via the Developer settings. But you can also take a shortcut and install it right away by running this command (which will just create the entry in the config file for you):
mcp install server.py
You will need to restart Claude desktop to see the tool in your "search and tools" section.
For options on implementing MCP clients in code:
- https://modelcontextprotocol.io/quickstart/client
- https://github.com/mcp-use/mcp-use
Using Third-Party MCP Servers (Google Sheets Example)
If your goal is to build powerful and useful AI agents, then you're probably more interested in using existing MCP servers rather than creating your own. There's a huge list of available servers here from both first-party and third-party developers: https://github.com/modelcontextprotocol/servers
It's also really easy to use in Claude Desktop. For this example, let's try integrating Google Sheets access (not just to read, but to create and modify).
- Follow the instructions on https://github.com/xing5/mcp-google-sheets.
- Set up Google access:
- Create a Google Cloud account and project.
- Create a service role and save the JSON to disk somewhere.
- Create a folder in Google drive, and share its permission to the service account email.
- Enable Drive and Sheets API in the GCP project.
Then set up the MCP server in Claude desktop (replace the environment variables):
{
"google-sheets": {
"command": "uvx",
"args": ["mcp-google-sheets@latest"],
"env": {
"SERVICE_ACCOUNT_PATH": "[...]/keys/service-account-xxx.json",
"DRIVE_FOLDER_ID": "XXX"
}
}
}
This will now make Google Sheets available as a tool. The uvx command also lets you run it without having to clone the Github project or install any dependencies/environments.
Setting Up uv and uvx commands
On MacOS/Linux, Claude desktop might complain that it can't find uv or uvx when you try to start the server. You might just have to create a symlink to the binary.
sudo ln -s ~/.local/bin/uv /usr/local/bin/uv
sudo ln -s ~/.local/bin/uvx /usr/local/bin/uvx
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。