article
README
🚀 @terryliyongjie/api2mcptools
这是一个将 API 转换为 MCP(模型上下文协议)工具的 Node.js 包,助力开发者在相关场景中实现 API 到 MCP 的转换,还能与 MCP 生态系统轻松集成。
- CherryStudio 示例 CherryStudio

🚀 快速开始
本工具提供了便捷的安装与使用方式,你可以根据自身需求选择合适的途径开启使用之旅。
📦 安装指南
选项 1:使用 npx 快速开始(推荐)
set CONFIG_JSON_PATH=example.json
npx @terryliyongjie/api2mcptools
选项 2:传统安装
# 在项目中本地安装
npm install @terryliyongjie/mcp-tools
# 或全局安装以作为 CLI 工具使用
npm install -g @terryliyongjie/mcp-tools
📚 详细文档
配置
环境变量
# 必填:配置 JSON 文件的路径
CONFIG_JSON_PATH=example.json
示例配置文件(example.json):
// 单个工具配置
{
"name": "tool_name",
"description": "工具描述",
"inputSchema": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "参数描述"
}
},
"required": ["param1"]
},
"axiosConfig": {
"url": "https://api.example.com/endpoint",
"method": "get",
"params": {
"key": "your_api_key"
}
}
}
// 或多个工具配置
[
{
"name": "baidu_place_search",
"description": "使用百度地图 API 进行地点检索服务",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "检索关键字"
},
"region": {
"type": "string",
"description": "检索行政区划区域"
}
},
"required": ["query", "region"]
},
"axiosConfig": {
"url": "https://api.map.baidu.com/place/v2/search",
"method": "get",
"params": {
"ak": "your_baidu_map_key"
}
}
},
// 更多工具...
]
功能
- 将 JSON API 转换为 MCP 工具
- 与 MCP 生态系统轻松集成
- 支持多种 API 类型
- 命令行界面(CLI)支持
使用方法
作为 CLI 工具
全局安装后,可以直接在终端中使用命令:
mcp-tools [options]
作为模块
// 示例代码即将发布
开发
# 安装依赖项
npm install
# 构建项目
npm run build
# 在开发模式下运行
npm run dev
# 开发期间监视文件变化
npm run watch
# 运行 MCP 检查器
npm run inspector
📄 许可证
MIT
微信扫一扫