Skip to main content
Glama
MCP Weather Service

MCP Weather Service

by terisuke

MCP 气象服务

该存储库是一个简单的服务,使用模型上下文协议 (MCP) 提供天气信息。您可以获取多个城市(福冈、东京、大阪、莫斯科、纽约等)的天气信息。

目录

  1. 先决条件

  2. 项目设置

  3. 如何使用

  4. 开发指南

  5. 上传到 GitHub

  6. 故障排除

Related MCP server: Weather MCP

先决条件

要完成此项目,您需要以下软件:

  • Node.js(版本 18 及以上)

  • npm(通常与 Node.js 一起安装)

  • Git

如何安装

安装 Node.js 和 npm

  1. 从Node.js 官方网站下载安装程序并安装。

  2. 安装完成后,通过在终端中运行以下命令来验证:

node -v
npm -v

安装 Git

  1. 从Git官方网站下载安装程序并安装。

  2. 安装完成后,通过在终端中运行以下命令来验证:

git --version

项目设置

创建新项目

  1. 创建一个新目录并导航到该目录:

mkdir my-weather-mcp
cd my-weather-mcp
  1. 初始化你的 npm 项目:

npm init -y
  1. 安装所需的软件包:

npm install @modelcontextprotocol/sdk axios zod typescript @types/node https-proxy-agent
npm install --save-dev ts-node
  1. 创建 TypeScript 配置文件:

npx tsc --init
  1. 按如下方式编辑tsconfig.json文件:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "outDir": "./build",
    "strict": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
  1. 编辑package.json文件的脚本部分,如下所示:

"scripts": {
  "build": "tsc && node -e \"import('fs').then(fs => fs.default.chmodSync('build/index.js', '755'))\"",
  "start": "node build/index.js",
  "inspect": "npx @modelcontextprotocol/inspector build/index.js",
  "dev": "ts-node src/index.ts"
}
  1. 创建项目目录结构:

mkdir -p src test

克隆现有项目

如果您想使用现有项目,请克隆它:

git clone https://github.com/terisuke/my-weather-mcp.git
cd my-weather-mcp
npm install

如何使用

构建并运行

要构建并运行项目,请使用以下命令:

npm run build && npm run start

使用检查器

要使用 MCP Inspector 测试天气服务,请运行以下命令:

npm run build && npm run inspect

一旦 Inspector 运行,您就可以通过在浏览器中访问http://127.0.0.1:6274与天气服务进行交互。

获取天气信息

使用检查器,您可以获取以下城市的天气信息:

  • 福冈

  • 东京

  • 大阪

  • 莫斯科

  • 纽约

可以指定其他城市,但必须被 Open-Meteo API 识别。

开发指南

文件结构

my-weather-mcp/
├── build/              # コンパイルされたJavaScriptファイル
├── src/                # TypeScriptソースコード
│   └── index.ts        # メインのアプリケーションコード
├── test/               # テストファイル
├── package.json        # プロジェクト設定
├── tsconfig.json       # TypeScript設定
└── README.md           # このファイル

修复代码

  1. 编辑src/index.ts文件以添加或修改功能。

  2. 要测试您的更改,请运行以下命令:

npm run build && npm run inspect
  1. 一旦您对更改的效果感到满意,请提交更改。

上传到 GitHub

创建您的第一个 GitHub 存储库

  1. 前往GitHub并创建帐户或登录。

  2. 点击右上角的“+”按钮,选择“新建存储库”。

  3. 输入存储库名称(例如, my-weather-mcp )并添加可选描述。

  4. 将您的存储库设置为公共或私有,然后单击“创建存储库”。

初始化并推送本地仓库

  1. 在本地项目目录中,初始化 Git 存储库:

git init
  1. 将您的更改添加到暂存区:

git add .
  1. 提交更改:

git commit -m "初回コミット:MCP天気サービスの実装"
  1. 添加远程存储库(使用来自 GitHub 的存储库 URL):

git remote add origin https://github.com/ユーザー名/my-weather-mcp.git
  1. 将更改推送到远程存储库:

git push -u origin main

将更改推送到现有存储库

  1. 将您的更改添加到暂存区:

git add .
  1. 提交更改:

git commit -m "変更内容の説明"
  1. 将更改推送到远程存储库:

git push

创建拉取请求

  1. 转到 GitHub 上的存储库页面。

  2. 单击“拉取请求”选项卡,然后单击“新拉取请求”按钮。

  3. 选择基础分支和比较分支。

  4. 单击“创建拉取请求”按钮。

  5. 输入拉取请求的标题和描述,然后单击“创建拉取请求”按钮。

故障排除

常见问题及解决方案

ERR_PACKAGE_PATH_NOT_EXPORTED错误

当@modelcontextprotocol/sdk包的导入路径不正确时会出现此错误。请按如下方式修复:

// 誤ったインポート
import { McpServer } from "@modelcontextprotocol/sdk";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/transports";

// 正しいインポート
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

网络连接错误

如果在进行 API 调用时遇到网络错误,请检查您的代理设置。您可以通过设置环境变量HTTP_PROXY或HTTPS_PROXY来使用代理:

export HTTP_PROXY=http://プロキシサーバー:ポート
export HTTPS_PROXY=https://プロキシサーバー:ポート

其他问题

如果问题仍然存在,请使用以下信息创建问题:

  • 发生的错误信息

  • 您正在使用的 Node.js 和 npm 版本

  • 命令执行

  • 预期行为与实际行为

Available Tools

1 tool
get-weatherC

Get weather information for a city

Inputs: city (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 1 tool

    Disambiguation5/5

    With only one tool, there is no possibility of ambiguity or overlap between tools. The tool 'get-weather' has a clear, singular purpose that cannot be confused with any other tool in the set.

    Naming Consistency5/5

    The single tool name 'get-weather' follows a consistent verb_noun pattern, and with only one tool, there is no inconsistency or deviation to evaluate. The naming is straightforward and predictable.

    Tool Count2/5

    A single tool for a weather service is too few for the apparent scope, as it lacks basic operations like forecasts, historical data, or multi-location queries. This minimal set feels thin and incomplete for a typical weather domain.

    Completeness1/5

    The tool surface is severely incomplete for a weather service. It only provides current weather for a city, missing essential operations such as forecasts, alerts, historical data, or support for multiple locations, which are core to weather-related workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      A Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.
      8
      2,313 PyPI
      61
      Apache 2.0
    • F
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that provides current weather information and 3-day forecasts for specified cities using the Open-Meteo API.
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that provides weather information using the Open-Meteo API, allowing users to get current weather for specific cities and retrieve weather data for date ranges.
      Apache 2.0

    Appeared in Searches