MCP Weather Service

MIT License
4

Integrations

  • Used to make HTTP requests to the Open-Meteo API for fetching weather information for various cities

  • Provides version control functionality for the weather service project, allowing users to clone, commit, and push changes

  • Enables users to store, share, and collaborate on the weather service project through repositories, pull requests, and issue tracking

MCP 气象服务

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

目录

  1. 先决条件
  2. 项目设置
  3. 如何使用
  4. 开发指南
  5. 上传到 GitHub
  6. 故障排除

先决条件

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

  • 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_PROXYHTTPS_PROXY来使用代理:

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

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

  • 发生的错误信息
  • 您正在使用的 Node.js 和 npm 版本
  • 命令执行
  • 预期行为与实际行为

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

使用模型上下文协议 (MCP) 的简单服务,为福冈、东京、大阪、莫斯科和纽约等多个城市提供天气信息。

  1. 目录
    1. 先决条件
      1. 如何安装
    2. 项目设置
      1. 创建新项目
      2. 克隆现有项目
    3. 如何使用
      1. 构建并运行
      2. 使用检查器
      3. 获取天气信息
    4. 开发指南
      1. 文件结构
      2. 修复代码
    5. 上传到 GitHub
      1. 创建您的第一个 GitHub 存储库
      2. 初始化并推送本地仓库
      3. 将更改推送到现有存储库
      4. 创建拉取请求
    6. 故障排除
      1. 常见问题及解决方案

    Related MCP Servers

    • -
      security
      F
      license
      -
      quality
      This is a Model Context Protocol (MCP) server that provides weather information using the National Weather Service (NWS) API. Features Get weather alerts for a US state Get weather forecast for a specific location (using latitude and longitude)
      Last updated -
      Python
      • Linux
      • Apple
    • -
      security
      A
      license
      -
      quality
      A Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.
      Last updated -
      1
      Python
      Apache 2.0
      • Linux
      • Apple
    • A
      security
      A
      license
      A
      quality
      Model Context Protocol (MCP) server that provides weather forecast, warnings, water level associated with flood, and earthquake reports from Malaysia Government's Open API.
      Last updated -
      4
      Python
      MIT License
    • -
      security
      F
      license
      -
      quality
      An MCP server implementation that allows users to fetch and display weather information for specified cities, including temperature, humidity, wind speed, and weather descriptions.
      Last updated -
      Python
      • Linux
      • Apple

    View all related MCP servers

    ID: c9bqfygh4v