API集成工具

一个基于配置文件的灵活REST API集成工具,支持动态加载端点和验证请求字段,无需修改代码即可连接不同API。

  • by Daemonlite
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 daemonlite/mcp-api-tester

使用说明

🛠️ MCP API集成工具

这个项目是 模型上下文协议(MCP)服务器 使您能够与任何REST API集成。 它不使用硬编码端点和请求有效载荷,而是使用 config.json 您可以在其中定义的文件:

  • 这 API基本URL
  • 列表 端点 他们的道路和田野
  • 引导请求的有效载荷示例

这使得它可以灵活地连接到不同的API,而无需修改代码。


📂 项目结构

py-mcp/
│── main.py         # MCP server implementation
│── config.json     # Stores base URL, endpoints, and payload field definitions
│── README.md       # Project documentation

⚙️ 配置(config.json)

这 config.json 文件控制MCP服务器如何连接到您的API。

例子:

{
  "api_base_url": "http://localhost:8000/api",
  "endpoints": {
    "products": {
      "path": "/products",
      "method": "POST",
      "fields": {
        "name": "string",
        "price": "float",
        "stockQuantity": "integer"
      }
    },
    "customers": {
      "path": "/customers",
      "method": "POST",
      "fields": {
        "firstName": "string",
        "lastName": "string",
        "email": "string"
      }
    }
  }
}
  • api_base_url → API的根URL

  • endpoints → 可用端点字典

    • 每个端点都有:

      • path:URL路径(例如。, /products)
      • method:HTTP方法(POST, GET, PUT, DELETE)
      • fields:预期的请求正文字段

🚀 运行MCP服务器

  1. 安装依赖项:
pip install mcp httpx anyio
  1. 确保您的 config.json 设置正确。

  2. 运行MCP服务器:

py main.py

🧩 示例用法

  • 随着 config.json 在上面,您可以拨打:
{
  "endpoint": "products",
  "payload": {
    "name": "Laptop",
    "price": 1200,
    "stockQuantity": 50
  }
}

服务器将此请求发送到:

POST http://localhost:8000/api/products

并返回API的响应。


🌟 特性

  • ✅ MCP兼容服务器
  • ✅ 从以下位置动态加载端点 config.json
  • ✅ 支持多个API,无需更改代码
  • ✅ 验证所需的有效载荷字段
  • ✅ 灵活适用于REST API集成