MCP Servers 项目

by MCP-Mirror

155 downloads
Not rated
GitHub

About

MCP Servers 项目 is a collection of services built on the Model Context Protocol (MCP) to enhance Cursor IDE with intelligent features. Currently it includes a demo service for learning and a weather service for live weather data. It is aimed at developers using Cursor IDE who…

Details

Author
MCP-Mirror
Downloads
155
Categories
Other

- Three-layer architecture: config, controllers, service
- Demo service for learning MCP patterns
- Weather service with real-time and 5‑day forecasts
- Supports multiple city queries
- TypeScript with typed constants and interfaces
- Environment‑based API key management

Clone the repository, install dependencies with npm install, build all services with npm run build or individual services using npm run build:weather. Configure MCP in ~/.cursor/mcp.json with the appropriate command and environment variables (e.g., OPENWEATHER_API_KEY). Start a service with npm run start:weather or npm run start:demo. The server is invoked via Cursor IDE using the configured MCP tool definitions.

MCP Servers 项目

基于 Model Context Protocol (MCP) 开发的服务集合,用于支持 Cursor IDE 的智能功能。目前包含示例服务和天气服务。

开发环境要求

- Node.js >= 16.0.0
- npm >= 8.0.0
- TypeScript >= 4.5.0
- Cursor IDE(最新版本)

项目结构

mcp-servers/
├── src/                    # 源代码目录
│   ├── demo/              # 示例服务
│   │   ├── config/       # 配置层:常量、类型定义
│   │   │   ├── constants.ts    # 常量定义
│   │   │   └── types.ts        # 类型定义
│   │   ├── controllers/  # 控制器层:请求处理
│   │   │   └── GreetingController.ts  # 问候控制器
│   │   ├── service/      # 服务层:业务逻辑
│   │   │   └── GreetingService.ts     # 问候服务
│   │   ├── package.json  # 服务配置文件
│   │   ├── tsconfig.json # TypeScript 配置
│   │   └── index.ts      # 服务入口文件
│   │
│   └── weather/          # 天气服务
│       ├── config/       # 配置层:常量、类型定义
│       │   ├── constants.ts    # 常量定义
│       │   └── types.ts        # 类型定义
│       ├── controllers/  # 控制器层:请求处理
│       │   └── WeatherController.ts  # 天气控制器
│       ├── service/      # 服务层:业务逻辑
│       │   └── WeatherService.ts     # 天气服务
│       ├── package.json  # 服务配置文件
│       ├── tsconfig.json # TypeScript 配置
│       └── index.ts      # 服务入口文件
│
├── build/                  # 编译输出目录
├── node_modules/          # 依赖包
├── package.json           # 项目配置
├── tsconfig.json          # TypeScript 配置
└── README.md             # 项目文档

代码分层架构

项目采用三层架构设计,每个服务都遵循相同的结构模式:

1. 配置层(Config)

位置:服务目录/config/ - 职责: - 定义常量和配置项 - 声明类型和接口 - 管理环境变量 - 主要文件: - constants.ts: 常量定义 - types.ts: 类型定义 - 特点: - 集中管理配置 - 类型安全 - 易于维护和修改

2. 控制器层(Controllers)

位置:服务目录/controllers/ - 职责: - 处理 MCP 请求和响应 - 参数验证和错误处理 - 调用服务层方法 - 主要文件: - XXXController.ts: 具体业务控制器 - 特点: - 请求参数验证 - 错误处理和日志 - 响应格式化

3. 服务层(Service)

位置:服务目录/service/ - 职责: - 实现核心业务逻辑 - 处理数据转换 - 调用外部 API - 主要文件: - XXXService.ts: 具体业务服务 - 特点: - 业务逻辑封装 - 数据处理和转换 - 外部服务集成

服务入口(index.ts)

位置:服务目录/index.ts - 职责: - 初始化服务实例 - 注册 MCP 工具 - 处理标准输入输出 - 特点: - 统一的入口点 - MCP 工具注册 - 错误处理

开发流程

1. 新建服务

   mkdir -p src/new-service/{config,controllers,service}

2. 实现各层功能
- 配置层:定义常量和类型
- 控制器层:处理请求和响应
- 服务层:实现业务逻辑

3. 创建配置文件
- package.json: 服务依赖和脚本
- tsconfig.json: TypeScript 配置

4. 编写入口文件
- 创建 index.ts
- 注册 MCP 工具
- 实现请求处理

快速开始

1. 克隆项目

git clone <repository-url>
cd mcp-servers

2. 安装依赖

npm install

3. 构建项目

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.