my weather mcp
A simple service using Model Context Protocol (MCP) to provide weather information for multiple cities including Fukuoka, Tokyo, Osaka, Moscow, and New York.
A simple service using Model Context Protocol (MCP) to provide weather information for multiple cities including Fukuoka, Tokyo, Osaka, Moscow, and New York.
このリポジトリは、Model Context Protocol (MCP) を使用して天気情報を提供するシンプルなサービスです。複数の都市(福岡、東京、大阪、モスクワ、ニューヨークなど)の天気情報を取得できます。
このプロジェクトは MITライセンス の下で公開されています。
このプロジェクトを実行するには、以下のソフトウェアが必要です:
node -v
npm -v
git --version
mkdir my-weather-mcp
cd my-weather-mcp
npm init -y
npm install @modelcontextprotocol/sdk axios zod typescript @types/node https-proxy-agent
npm install --save-dev ts-node
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 インスペクターを使用して天気サービスをテストするには、以下のコマンドを実行します:
npm run build && npm run inspect
インスペクターが起動すると、ブラウザで 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
my-weather-mcp
)を入力し、必要に応じて説明を追加します。git init
git add .
git commit -m "初回コミット:MCP天気サービスの実装"
git remote add origin https://github.com/ユーザー名/my-weather-mcp.git
git push -u origin main
git add .
git commit -m "変更内容の説明"
git push
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://プロキシサーバー:ポート
問題が解決しない場合は、以下の情報を含むイシューを作成してください:
[
{
"description": "Get weather information for a city",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"city": {
"description": "City name to get weather for",
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
},
"name": "get-weather"
}
]