返回市场
API到MCP工具

API到MCP工具

作者:JayLi525 星标更新:2025-05-26

项目介绍

@terryliyongjie/api2mcptools

中文文档

smithery badge Model Context Protocol

一个将API转换为MCP(模型上下文协议)工具的Node.js包。

安装

方案 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 [选项]

作为模块

// 示例代码即将推出

开发

# 安装依赖
npm install

# 构建项目
npm run build

# 开发模式运行
npm run dev

# 开发期间的监视模式
npm run watch

# 运行MCP检查器
npm run inspector

许可证

MIT