HTTP-4-MCP 是一个强大的中间件服务器,能够神奇地转换常规的 HTTP 接口成为 MCP(模型控制协议)接口。通过简单的配置,您的 HTTP API 将瞬间变成 MCP 工具!




# 克隆仓库
git clone https://gitee.com/tght1211/http-for-mcp-server.git
# 或者 git clone https://github.com/tght1211/http-for-mcp-server.git
cd http-for-mcp-server
# 安装依赖(推荐使用 uv 包管理器)
uv venv
uv pip install -r requirements.txt
# 激活虚拟环境
.venv/Scripts/activate # Windows
source .venv/bin/activate # Linux/Mac
# 启动主服务器
uv run run.py
# 启动配置 UI(可选)
uv run run_config_ui.py
http://localhost:8002{
"tools": [
{
"name": "weather_api",
"description": "获取指定城市的实时天气信息,包括温度、湿度、天气状况、风向和风速。\n \n 此工具采用两步查询过程:\n 1. 首先通过城市名称获取精确的位置ID\n 2. 然后使用位置ID查询实时天气数据\n \n 示例用法:\n - 获取“北京”的天气信息\n - 获取“上海”的实时天气状况\n - 查询“广州”的温度和湿度\n \n 返回格式化的天气信息文本,包括城市名称、天气状况、温度、湿度、风向和风速。",
"url": "https://devapi.qweather.com/v7/weather/now",
"method": "GET",
"params": {
"location": {
"type": "string",
"desc": "城市名称或ID",
"required": true,
"default": "101010100"
},
"key": {
"type": "string",
"desc": "API密钥",
"required": true,
"default": "05a3e2c04b65416e912088b76a7a487e"
},
"lang": {
"type": "string",
"desc": "语言",
"required": false,
"default": "zh"
},
"unit": {
"type": "string",
"desc": "单位系统",
"required": false,
"default": "m"
}
},
"headers": {
"User-Agent": "weather-app/1.0"
},
"response": {
"code": {
"path": "code",
"desc": "响应状态码"
},
"updateTime": {
"path": "updateTime",
"desc": "数据更新时间"
},
"fxLink": {
"path": "fxLink",
"desc": "详细天气信息链接"
},
"now": {
"path": "now",
"desc": "实时天气数据对象"
},
"now_obsTime": {
"path": "now.obsTime",
"desc": "实际观测时间"
},
"now_temp": {
"path": "now.temp",
"desc": "当前温度(摄氏度)"
},
"now_feelsLike": {
"path": "now.feelsLike",
"desc": "体感温度(摄氏度)"
},
"now_icon": {
"path": "now.icon",
"desc": "天气图标代码"
},
"now_text": {
"path": "now.text",
"desc": "天气现象文字描述"
},
"now_wind360": {
"path": "now.wind360",
"desc": "风向360度角"
},
"now_windDir": {
"path": "now.windDir",
"desc": "风向描述"
},
"now_windScale": {
"path": "now.windScale",
"desc": "风级"
},
"now_windSpeed": {
"path": "now.windSpeed",
"desc": "风速(公里/小时)"
},
"now_humidity": {
"path": "now.humidity",
"desc": "相对湿度百分比"
},
"now_precip": {
"path": "now.precip",
"desc": "降水量(毫米)"
},
"now_pressure": {
"path": "now.pressure",
"desc": "大气压(百帕)"
},
"now_vis": {
"path": "now.vis",
"desc": "能见度(公里)"
},
"now_cloud": {
"path": "now.cloud",
"desc": "云覆盖率百分比"
},
"now_dew": {
"path": "now.dew",
"desc": "露点温度(摄氏度)"
}
},
"response_mode": "metadata"
}
]
}
# SSE 连接 URL
ws_url = "http://localhost:8000/mcp/sse"
📦 http-for-mcp-server
┣ 📂 config/ # 配置文件
┣ 📂 demo/ # 示例代码
┣ 📂 static/ # 静态资源
┣ 📜 mcp_server.py # 主服务器
┣ 📜 config_ui.py # 配置UI
┣ 📜 run.py # 启动脚本
┗ 📜 requirements.txt # 依赖项
| 配置 | 描述 | 默认值 |
|---|---|---|
| 🌐 host | 服务器地址 | "0.0.0.0" |
| 🔌 port | 服务器端口 | 8000 |
| 🐛 debug | 调试模式 | false |
| 📝 log_level | 日志级别 | "info" |
直接粘贴 cURL 命令,自动生成配置:
curl -X GET 'https://api.example.com/weather?city=beijing'
本项目使用 MIT 许可证 - 详见 LICENSE 文件