天气MCP服务器

天气MCP服务器

一个使用Model Context Protocol (MCP) 提供天气数据的服务器,基于TypeScript和Node.js构建。

快速入门指南

功能特点

  • 获取并处理天气数据
  • 使用MCP SDK协议
  • 基于TypeScript开发,确保类型安全
  • 支持通过环境变量配置

安装与运行

  1. 克隆仓库: git clone https://github.com/your-username/weather-mcp-server.git cd weather-mcp-server

  2. 安装依赖: npm install

  3. 编译项目: npm run build

  4. 启动服务器: npm start

或者直接运行编译后的文件: node build/index.js

配置

在根目录创建 .env 文件,并添加以下内容:

API_KEY=your_weather_api_key
PORT=3000

脚本命令

命令描述
npm run build编译TypeScript代码
npm start启动服务器
npm run lint检查代码格式

项目结构

weather-mcp-server/
├── src/         # 源码目录
├── build/       # 编译输出目录
├── package.json # 项目依赖和脚本配置
├── tsconfig.json # TypeScript配置
└── .eslintrc.js # ESLint配置

常见问题

  • 如果编译失败,检查TypeScript日志:npx tsc --diagnostics
  • 如果Node.js找不到文件,请确认 build/ 目录中包含编译后的文件:ls build/
  • 在Windows上运行时,移除 chmod 755 build/index.js