Skip to main content
Glama

MCP 服务器

一个带有天气和时间工具的可扩展 Model Context Protocol (MCP) 服务器。专为学习而构建——将其连接到 Claude Desktop 并开始对话吧。

入门指南

1. 克隆并安装

git clone <repo-url> && cd mcp-server
python3 -m venv .venv
source .venv/bin/activate   # macOS / Linux / WSL
pip install -e .

或者使用 uv:

git clone <repo-url> && cd mcp-server
uv venv
source .venv/bin/activate
uv pip install -e .

2. 连接到 Claude Desktop

运行安装脚本以自动写入 Claude Desktop 配置文件:

macOS:

python setup_claude_agent.py

这会将 ~/Library/Application Support/Claude/claude_desktop_config.json 指向你项目的 .venv/bin/python。

如果你的项目位于非标准位置,请显式传递路径:

python setup_claude_agent.py --project-path /path/to/mcp-server

Windows (通过 WSL):

python3 setup_claude_agent.py --windows --win-user <YourWindowsUser> --wsl-user <YourWSLUser>

例如:

python3 setup_claude_agent.py --windows --win-user Cam --wsl-user cam

这会写入 %APPDATA%\Claude\claude_desktop_config.json 并配置 Claude Desktop 通过 WSL 启动服务器。

3. 重启 Claude Desktop

关闭并重新打开 Claude Desktop。要验证服务器是否已连接,请前往 设置 (Settings) → 开发者 (Developer) — 你应该能看到带有绿色 运行中 (running) 标志的 mcp-server。

4. 试用

向 Claude 询问以下任何问题:

  • “现在几点了?” — 使用 get_current_time 工具

  • “获取加利福尼亚州的天气警报” — 使用 weather://alerts/CA 资源

  • “纬度 40.7128,经度 -74.0060 的天气预报是什么?” — 使用预报资源

你无需手动启动服务器 — Claude Desktop 会自动启动它。


Related MCP server: mcp-weather

可用工具与资源

类型

名称

功能

工具

get_current_time

返回带有自动时区检测功能的当前时间

资源

weather://alerts/{state}

美国各州的天气警报(例如 CA, NY)

资源

weather://forecast/{lat}/{lon}

坐标的 5 时段预报

提示词

analyze_weather_prompt

指导 Claude 进行全面的天气分析

提示词

timezone_helper_prompt

协助进行时区检查、转换和比较

添加你自己的工具

打开 src/mcp_server/server.py 并添加一个带有 @mcp.tool() 装饰器的函数:

@mcp.tool()
async def my_tool(param: str) -> str:
    """Description of what this tool does."""
    return f"Result for {param}"

重启 Claude Desktop 以应用更改。

有关资源和提示词的信息,请参阅 CONTRIBUTING.md。

运行测试

pip install -e ".[dev]"   # or: uv pip install -e ".[dev]"
pytest

项目结构

src/mcp_server/
├── server.py              # MCP server entry point — register tools here
└── tools/
    ├── weather/           # Weather alerts & forecasts (NWS API)
    ├── time/              # IP-based timezone & current time
    └── conversation/      # Conversation tools

许可证

MIT

资源

Available Tools

4 tools
clear_old_cacheA

Clear expired weather cache entries.

Args: max_age_minutes: Maximum age in minutes before considering expired

Returns: Status message with number of entries removed

Inputs: max_age_minutes. Returns: result

get_alertsA

Get active weather alerts for a US state.

Provides current weather alerts and warnings for the specified state. Checks cache first (30 min expiry), fetches fresh if needed.

Args: state: Two-letter US state code (e.g. CA, NY)

Inputs: state (required). Returns: result

get_current_timeA

Get the current time based on the user's IP address.

This tool determines the user's timezone from their IP address using geolocation and returns the current local time in that timezone.

Args: ip_address: Optional IP address to determine timezone. If not provided or empty string, attempts to detect automatically or defaults to UTC.

Returns: Formatted string with current time, timezone, day, and ISO timestamp

Inputs: ip_address. Returns: result

get_forecastA

Get weather forecast for geographic coordinates.

Provides a 5-day forecast for the specified location. Checks cache first (60 min expiry), fetches fresh if needed.

Args: latitude: Latitude of the location (-90 to 90) longitude: Longitude of the location (-180 to 180)

Inputs: latitude (required), longitude (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool targets a distinct function: cache management, alerts, current time, and forecast. No overlap or ambiguity.

    Naming Consistency5/5

    All names follow a consistent verb_noun snake_case pattern (clear_old_cache, get_alerts, get_current_time, get_forecast).

    Tool Count4/5

    With 4 tools, the set is slightly sparse but well-scoped for a combined weather/time server. Each tool serves a clear purpose.

    Completeness3/5

    Missing current weather conditions and location-based time input; only alerts and forecast for weather, time only via IP. Notable gaps exist.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol (MCP) server built with the mcp-framework to provide weather-related tools and data to AI clients. It enables integration of weather capabilities and custom tools into the MCP ecosystem for use with platforms like Claude Desktop.
      -
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that provides weather and time tools, enabling users to get current time, weather alerts, and forecasts through natural language with Claude Desktop.
      4
      MIT