Skip to main content

天气查询MCP服务

Project description

天气查询MCP服务

这是一个基于 MCP (Model Context Protocol) 的天气查询服务,天气查询的结果是基于中国气象局-天气预报网的天气信息,可以查询特定地区的当前的天气信息或者7天以内的天气预报信息。

快速开始 - 使用UVX配置MCP服务(推荐)

  • 用uvx的方式配置MCP服务是推荐的方式。
  • 因为uvx可以在不同的平台上运行,包括Windows、macOS和Linux。
# 给AI模型提供天气查询的MCP服务
{
  "mcpServers": {
    "weather": {
      "command": "uvx",
      "args": [
        "xmcp-server-weather"
      ],
      "env": {}
    }
  }
}

macOS系统的推荐配置

mac系统如果用uvx启动服务会报错,则可以尝试先安装xmcp-server-weather,再用下面的配置使用MCP服务。

# 先安装服务package
pip3 install xmcp-server-weather

# MCP服务的配置
{
  "mcpServers": {
    "weather": {
      "command": "xmcp-server-weather"
    }
  }
}

使用MCP服务

  • 接着,将MCP服务配置给你的AI智能体,让AI可以调用这个MCP来查询天气。 例如,和智能体说:查询北京的天气。然后,该MCP会自动查询并返回对应的天气信息。

本地测试运行MCP服务

  • 本步骤主要是为了 本地测试 天气查询MCP服务。

1、Windows环境的配置:

# 先安装服务
pip install xmcp-server-weather

# 指定日志级别和传输方式(sse方式)
xmcp-server-weather --log-level=INFO --transport=sse --port=8001
  • 然后,就可以配置本地服务来调试MCP
{
  "mcpServers": {
    "weather": {
      "url": "http://localhost:8001/sse"
    }
  }
}

2、macOS系统的配置

# 先安装服务(如果已经安装则忽略)
pip3 install  xmcp-server-weather

# (测试用)指定日志级别和传输方式(sse方式)。
# 下面有显示启动服务说明环境已经安装完毕。
xmcp-server-weather --log-level=INFO --transport=sse --port=8001
  • 然后,就可以配置本地服务来调试MCP
# 默认的stdio模式
{
  "mcpServers": {
    "weather": {
      "command": "xmcp-server-weather"
    }
  }
}

# 或者sse模式(前提是http服务要打开)
{
  "mcpServers": {
    "weather": {
      "url": "http://localhost:8001/sse"
    }
  }
}

命令行参数

日志级别 (--log-level)

设置服务器的日志输出级别,可选值:

  • DEBUG:详细的调试信息,用于开发和问题排查
  • INFO:正常运行的信息,显示关键操作
  • WARNING:警告信息,可能影响功能但不影响运行
  • ERROR:错误信息,功能无法正常执行
  • CRITICAL:严重错误,可能导致程序崩溃

默认值ERROR

示例

xmcp-server-weather --log-level=DEBUG

传输方式 (--transport)

设置服务器与客户端之间的通信协议,可选值:

  • stdio:使用标准输入输出进行通信,适用于进程间通信
  • sse:使用 Server-Sent Events 进行实时通信,适用于网络环境
  • streamable-http:使用可流式的HTTP协议进行通信

默认值stdio

注意

  • stdio 模式下日志不会输出到控制台,避免干扰通信
  • 网络传输模式需要指定端口参数

示例

xmcp-server-weather --transport=sse --port=8001

服务器端口 (--port)

当使用网络传输方式时,指定服务器监听的端口号。

默认值8001

示例

xmcp-server-weather --transport=sse --port=8001

完整示例

启动一个具有详细日志记录的网络服务器:

xmcp-server-weather --log-level=INFO --transport=sse --port=8001

启动一个用于进程间通信的服务器(无日志输出):

xmcp-server-weather --transport=stdio

常见问题解答

1. 为什么 stdio 模式下看不到日志?

stdio 模式使用标准输入输出流进行通信,日志输出会干扰通信协议,因此默认禁用控制台日志。如需查看日志,请使用 sse 模式并设置 --log-level 参数。

2. 如何在后台运行服务器?

Windows

# 使用PowerShell后台作业
Start-Job -ScriptBlock { xmcp-server-weather --transport=sse --port=8001 }

Linux/macOS

# 使用nohup命令
nohup xmcp-server-weather --transport=sse --port=8001 &

3. 端口被占用怎么办?

# 查找占用端口的进程
lsof -i:8001

# 终止进程(替换<PID>为实际进程ID)
kill -9 <PID>

# 或使用其他端口
xmcp-server-weather --transport=sse --port=8081

4. 如果访问天气服务的时候报网络错误怎么办?

  1. 确请检查网络配置,或者如果有打开代理工具,请尝试关闭它再测试。
  2. 检查服务日志中是否有权限错误提示
  3. 暂时关闭安全软件或防火墙
# 以管理员权限运行PowerShell(Windows)
Start-Process powershell -Verb RunAs

# 或调整防火墙规则(Linux)
sudo ufw allow 8001/tcp

5. 如何查看服务状态?

# 查看服务版本
xmcp-server-weather --version

# 查看实时运行状态(sse模式)
curl http://localhost:8001/status

技术支持

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmcp_server_weather-0.1.7.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xmcp_server_weather-0.1.7-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file xmcp_server_weather-0.1.7.tar.gz.

File metadata

  • Download URL: xmcp_server_weather-0.1.7.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for xmcp_server_weather-0.1.7.tar.gz
Algorithm Hash digest
SHA256 002197456de3a8b58c24a279e3dd2ef56ed9e59952b214c89c99dbca6e30a6ce
MD5 a811c4629d3a22fccf486c19fc6b4e6a
BLAKE2b-256 c8ebca17b7c5d9c9a4a9661e813dd79a40efc8b44765cd586e06be2baf7a78a3

See more details on using hashes here.

File details

Details for the file xmcp_server_weather-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for xmcp_server_weather-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7189b7aa775e20b2faac531a8e582bca9bbcefe8eed9b8cb5d76398e0bf596a0
MD5 21aabee1c5885e67c34bb2d4cee83871
BLAKE2b-256 1bd0e1576b76cb12a5174703bb7b3d219913b0a7f8d341b57c66453c7193e5b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page