天气服务工具

通过Open-Meteo提供的免费天气服务工具,包含当前天气、多日预报和指定日期预报功能。

  • by klapom
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 klapom/weather-mcp

使用说明

天气mcp

天气 MCP 通过 开放天气 免费,没有API密钥。三种工具:当前天气,多日预报,特定日期的预报。在Pommer-MCP景观中的Track-A服务。

基于共同模板模式的双表面架构 (~/projects/00-scaffolding/service-template-ts/):

  • REST 上 LISTEN_PORT=32600 关于Hermes + curl
  • MCP Streamable HTTP 的 MCP_PORT=33600/mcp 关於Claude Code / Web
  • MCP 标准dist/index.js关于Claude Desktop

共享所有三个表面 一个 工具定义专业工具(工具即数据,ADR-006)。

堆栈

pnpm·tsup·vitest·biome·zod·pino· @modelcontextprotocol/sdk ≥ 1.12.仅限节点22+ESM。

快速入门

pnpm install
cp .env.example .env       # anpassen, chmod 600
pnpm dev                   # tsx watch, REST + MCP-HTTP lokal
# Smoke:
curl http://localhost:32600/health
curl -X POST http://localhost:32600/tools/get_current_weather -d '{"city":"Hamburg"}'
pnpm mcp:inspect           # MCP-Inspector gegen stdio-Entry

脚本

脚本 目的
pnpm dev tsx手表,HTTP表面
pnpm build tsup-Bundle 的 dist/
pnpm start 双HTTP aus dist/
pnpm start:stdio stdio输入aus dist/
pnpm test / test:coverage vitest(门≥80%)
pnpm lint / lint:fix 生物群落
pnpm typecheck tsc--noEmit
pnpm mcp:inspect MCP Inspector 对 stdio

结构

weather-mcp/
├── src/
│   ├── index.ts                      # stdio entry (Claude Desktop)
│   ├── http_server.ts                # dual REST + MCP-HTTP entry
│   ├── lib/
│   │   ├── dual-server.ts            # createDualServer factory
│   │   ├── http-helpers.ts           # sendJson/readBody/parseJsonBody
│   │   ├── logger.ts                 # pino + PII-Scrubber
│   │   ├── open-meteo-client.ts      # API client (geocode + forecast)
│   │   └── open-meteo-client.test.ts
│   ├── tools/
│   │   ├── index.ts                  # registerTools + buildRestHandlers
│   │   ├── context.ts                # ToolsContext (logger, DEFAULT_CITY/TZ)
│   │   ├── types.ts                  # ToolDef<S>
│   │   ├── get-current-weather.{ts,test.ts}
│   │   ├── get-forecast.{ts,test.ts}
│   │   └── get-weather-for-date.{ts,test.ts}
│   └── test-utils.ts                 # jsonResponse/errorResponse/mockFetchSequence/testContext
├── systemd/weather-mcp.service       # ADR-009-konform
├── .env.example
├── SKILL.md
└── package.json / tsconfig.json / tsup.config.ts / vitest.config.ts / biome.json

部署

pnpm build
cp systemd/weather-mcp.service ~/.config/systemd/user/
# Alte Unit abschalten (Migration 2026-04-21):
systemctl --user disable --now weather-mcp-http.service 2>/dev/null || true
rm -f ~/.config/systemd/user/weather-mcp-http.service
systemctl --user daemon-reload
systemctl --user enable --now weather-mcp.service
systemctl --user status weather-mcp.service

参考资料

  • ~/projects/mcp-platform/docs/adr/ --ADR 005(表面)、006(工具作为数据)、009(系统)、010(配置)
  • ~/projects/mcp-platform/docs/inventory/PORT_REGISTRY.md --港口登记处
  • ~/projects/mcp-platform/docs/runbooks/service-migration-playbook.md --迁移操作手册