API工具提取服务

从任何文档URL中提取API工具/端点,支持OpenAPI/Swagger规范、MCP端点和HTML文档页面,适用于开发人员快速获取结构化API定义。

  • by KNQuoc
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 KNQuoc/tool-discovery

使用说明

工具发现

从任何文档URL中提取API工具/端点。将其指向API文档页面,并获取带有参数、类型和身份验证信息的结构化工具定义。

支持

  • OpenAPI/Swagger规格 --自动检测,直接解析(无需人工智能)
  • MCP端点 --标准 tools/list 协议
  • HTML文档页面 --AI驱动的提取(需要OpenAI密钥)

安装

npm install
cp .env.example .env
# Add your OPENAI_API_KEY to .env

用法

# OpenAPI spec (auto-detected)
node discover.mjs https://petstore3.swagger.io/api/v3/openapi.json

# HTML docs - single page
node discover.mjs https://resend.com/docs/api-reference/emails/send-email

# HTML docs - crawl entire docs site
node discover.mjs https://resend.com/docs/api-reference/emails/send-email --crawl

# Save output
node discover.mjs <url> --output tools.json

# Control crawl depth
node discover.mjs <url> --crawl --max-pages 30

运作原理

  1. 检测格式 --按照OpenAPI规范尝试URL,探测已知的规范路径,检查HTML中的嵌入式规范,尝试MCP
  2. 如果OpenAPI/Swagger --直接解析规范。获取具有完整参数架构、身份验证信息和响应类型的每个端点
  3. 如果MCP --电话 tools/list 用于结构化工具定义
  4. 如果HTML文档 --智能爬虫:
    • 检测文档框架(Mintlify、ReadMe、GitBook、Docusaurus、Redoc等)
    • 检查sitemap.xml以查找URL
    • 提取带有优先级评分的侧边栏/导航链接
    • 检测SPA shell并使用Jina Reader进行JS渲染
    • 在提取之前为类似API的内容筛选页面
    • AI从页面内容中提取端点定义
    • 消除重复结果

输出格式

{
  "url": "https://api.example.com/openapi.json",
  "sourceType": "openapi",
  "discoveredAt": "2026-02-24T03:15:19.343Z",
  "toolCount": 19,
  "tools": [
    {
      "name": "send_email",
      "method": "POST",
      "path": "/v1/emails",
      "description": "Send an email to a recipient",
      "params": [
        { "name": "to", "type": "string", "required": true, "description": "Recipient email" },
        { "name": "subject", "type": "string", "required": true, "description": "Email subject" },
        { "name": "body", "type": "string", "required": true, "description": "Email body" }
      ],
      "auth": { "type": "bearer", "header": "Authorization" },
      "sourceUrl": "https://api.example.com/v1/emails",
      "sourceType": "openapi"
    }
  ]
}

已测试

  • Swagger宠物店 --已提取19个端点
  • GitHub REST API --已提取1080个端点
  • 重新发送文档 (Mintlify)-检测到框架,抓取页面,准备进行AI提取