MCP Weather Service
MCP 气象服务
该存储库是一个简单的服务,使用模型上下文协议 (MCP) 提供天气信息。您可以获取多个城市(福冈、东京、大阪、莫斯科、纽约等)的天气信息。
目录
Related MCP server: Weather MCP
先决条件
要完成此项目,您需要以下软件:
Node.js(版本 18 及以上)
npm(通常与 Node.js 一起安装)
Git
如何安装
安装 Node.js 和 npm
从Node.js 官方网站下载安装程序并安装。
安装完成后,通过在终端中运行以下命令来验证:
node -v
npm -v安装 Git
从Git官方网站下载安装程序并安装。
安装完成后,通过在终端中运行以下命令来验证:
git --version项目设置
创建新项目
创建一个新目录并导航到该目录:
mkdir my-weather-mcp
cd my-weather-mcp初始化你的 npm 项目:
npm init -y安装所需的软件包:
npm install @modelcontextprotocol/sdk axios zod typescript @types/node https-proxy-agent
npm install --save-dev ts-node创建 TypeScript 配置文件:
npx tsc --init按如下方式编辑
tsconfig.json文件:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"outDir": "./build",
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}编辑
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"
}创建项目目录结构:
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 # このファイル修复代码
编辑
src/index.ts文件以添加或修改功能。要测试您的更改,请运行以下命令:
npm run build && npm run inspect一旦您对更改的效果感到满意,请提交更改。
上传到 GitHub
创建您的第一个 GitHub 存储库
前往GitHub并创建帐户或登录。
点击右上角的“+”按钮,选择“新建存储库”。
输入存储库名称(例如,
my-weather-mcp)并添加可选描述。将您的存储库设置为公共或私有,然后单击“创建存储库”。
初始化并推送本地仓库
在本地项目目录中,初始化 Git 存储库:
git init将您的更改添加到暂存区:
git add .提交更改:
git commit -m "初回コミット:MCP天気サービスの実装"添加远程存储库(使用来自 GitHub 的存储库 URL):
git remote add origin https://github.com/ユーザー名/my-weather-mcp.git将更改推送到远程存储库:
git push -u origin main将更改推送到现有存储库
将您的更改添加到暂存区:
git add .提交更改:
git commit -m "変更内容の説明"将更改推送到远程存储库:
git push创建拉取请求
转到 GitHub 上的存储库页面。
单击“拉取请求”选项卡,然后单击“新拉取请求”按钮。
选择基础分支和比较分支。
单击“创建拉取请求”按钮。
输入拉取请求的标题和描述,然后单击“创建拉取请求”按钮。
故障排除
常见问题及解决方案
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 toolget-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
Scored across 1 tool
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.
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.
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.
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
Related MCP Connectors
Hosted MCP server for Xweather weather data: conditions, forecasts, alerts, and more.
An MCP server for weather information by @kulybaba
An MCP server for weather information by @kulybaba
MCP server for weather with reasoning — umbrella advice, outdoor checks, city comparisons.
Related MCP Servers
- AlicenseAqualityCmaintenanceA Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.82,313 PyPI61Apache 2.0
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides current weather information and 3-day forecasts for specified cities using the Open-Meteo API.1-
- AlicenseBqualityDmaintenanceA Model Context Protocol server that provides real-time weather data and forecasts for any city.19 npmISC
- AlicenseNot gradedqualityDmaintenanceA 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