城市州解析服务

一个基于MCP协议的服务,提供印度城市与州之间的映射关系,支持HTTP传输和自动化测试。

  • by geekconvert
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 geekconvert/my-mcp-server

使用说明

MCP城市状态解析服务器

一种模型上下文协议(MCP)服务器,使用StreamableHTTP传输为印度城市提供状态信息。

特性

  • 🌍 城市到州地图:获取印度城市的州名
  • 🚀 HTTP传输:使用StreamableHTTP进行通信
  • 🧪 综合测试:包括自动化测试套件
  • 📋 管理脚本:易于服务器管理

支持城市

服务器目前支持以下城市:

  • 坎普尔 → 北方邦
  • 德里 → Delhi
  • 孟买 → 马哈拉施特拉
  • 班加罗尔 → 卡纳塔克邦
  • 金奈 → 泰米尔纳德邦
  • 加尔各答 → 西孟加拉邦
  • 海得拉巴 → 特伦甘纳
  • 浦那 → 马哈拉施特拉
  • 斋浦尔 → 拉贾斯坦
  • 勒克瑙 → 北方邦

文件结构

├── simple-mcp-server.mjs    # Main MCP server implementation
├── server.mjs               # Alternative StreamableHTTP implementation
├── test-mcp.mjs            # Test suite for the MCP server
├── manage-server.sh        # Server management script
├── package.json            # Node.js dependencies
└── .vscode/mcp.json       # VS Code MCP configuration

安装

  1. 安装依赖项:
npm install
  1. 启动服务器:
./manage-server.sh start

用法

使用管理脚本

# Start the server
./manage-server.sh start

# Check server status
./manage-server.sh status

# Test the server
./manage-server.sh test

# View logs
./manage-server.sh logs

# Stop the server
./manage-server.sh stop

# Restart the server
./manage-server.sh restart

手动测试

服务器运行在 http://localhost:3001/mcp 并遵循MCP协议。

工具详细信息

getStateByCityName

描述:获取印度某个城市的州名

参数:

  • city (string,必填):城市名称

回应:

{
  "city": "Kanpur",
  "state": "Uttar Pradesh",
  "found": true
}

VS代码集成

服务器已配置为在中集成VS Code MCP .vscode/mcp.json:

{
  "servers": {
    "statename": {
      "type": "http",
      "url": "http://localhost:3001/mcp"
    }
  }
}

测试结果

✅ 服务器初始化:已成功使用MCP协议进行初始化
✅ 工具发现:正确列出可用工具
✅ 城市查询:返回已知城市的正确状态
✅ 未知城市:优雅地处理未知城市
✅ 错误处理:对无效请求的正确错误响应

上面是使用stdin/stdout将此mcp服务器与vscode连接的json。