Skip to main content
Glama

swagger-connect-mcp

npm version Node.js License

将 Swagger/OpenAPI 文档连接到 Codex、Claude Code、Qoder、Trae、Cursor、OpenCode 和 CodeBuddy。

中文 | English

中文

要求

  • Node.js >= 20

  • npm 或 pnpm

安装

npm install --save-dev swagger-connect-mcp

pnpm 项目使用:

pnpm add -D swagger-connect-mcp

初始化

在业务项目根目录执行。tool 支持:codex、claude-code、qoder、trae、cursor、opencode、codebuddy、all。

按需配置单个 Agent:

# Codex
npx swagger-connect-mcp init --tool codex --url https://example.com/v3/api-docs

# Claude Code
npx swagger-connect-mcp init --tool claude-code --url https://example.com/v3/api-docs

# Qoder
npx swagger-connect-mcp init --tool qoder --url https://example.com/v3/api-docs

# Trae
npx swagger-connect-mcp init --tool trae --url https://example.com/v3/api-docs

# Cursor
npx swagger-connect-mcp init --tool cursor --url https://example.com/v3/api-docs

# OpenCode
npx swagger-connect-mcp init --tool opencode --url https://example.com/v3/api-docs

# CodeBuddy
npx swagger-connect-mcp init --tool codebuddy --url https://example.com/v3/api-docs

任意命令增加 --with-instructions 可同时生成对应 Agent 的联调规则;使用 all 可生成全部配置。

同时生成所有 Agent 配置和联调规则:

npx swagger-connect-mcp init \
  --tool all \
  --with-instructions \
  --url https://example.com/v3/api-docs

init 会生成或合并:

  • swagger-mcp.config.json

  • 对应 Agent 的 MCP 配置

  • 使用 --with-instructions 时生成 AGENTS.md、CLAUDE.md、CODEBUDDY.md 或对应规则文件

不会执行 postinstall,安装包不会自动修改业务项目。

多个 Swagger 文档

npx swagger-connect-mcp add billing \
  --url https://example.com/billing/v3/api-docs \
  --base-url https://example.com/billing

npx swagger-connect-mcp remove billing

配置示例:

{
  "sources": {
    "default": {
      "url": "https://example.com/v3/api-docs"
    },
    "billing": {
      "url": "https://example.com/billing/v3/api-docs",
      "baseUrl": "https://example.com/billing"
    }
  },
  "allowRequests": false
}

支持 OpenAPI 3.x、Swagger 2.0、JSON、YAML 和 Swagger UI 地址。

认证

不要提交明文 token,使用环境变量引用:

{
  "sources": {
    "private": {
      "url": "https://example.com/v3/api-docs",
      "headers": {
        "Authorization": "Bearer ${SWAGGER_TOKEN}"
      }
    }
  }
}
$env:SWAGGER_TOKEN = "your-token"

MCP 工具

默认只读:

  • swagger_list_sources

  • swagger_list_operations

  • swagger_get_operation

  • swagger_get_schema

  • swagger:///openapi

兼容工具:fetch_swagger_info、list_endpoints、get_endpoint_details、validate_api_response。

业务接口请求默认关闭。设置 allowRequests 为 true 后才提供 swagger_request 和 execute_api_request。

简洁用法

生成 AGENTS.md 后,只需要告诉 code agent:

按 Swagger 联调结算单详情接口,接入当前页面,不要猜字段。

开发与发布

npm run build
npm test
npm pack --dry-run
npm publish --registry=https://registry.npmjs.org

Related MCP server: Swagger MCP Server

English

Requirements

  • Node.js >= 20

  • npm or pnpm

Install

npm install --save-dev swagger-connect-mcp

For pnpm projects:

pnpm add -D swagger-connect-mcp

Initialize

Run from the target project root. Supported tools: codex, claude-code, qoder, trae, cursor, opencode, codebuddy, and all.

Configure one Agent as needed:

# Codex
npx swagger-connect-mcp init --tool codex --url https://example.com/v3/api-docs

# Claude Code
npx swagger-connect-mcp init --tool claude-code --url https://example.com/v3/api-docs

# Qoder
npx swagger-connect-mcp init --tool qoder --url https://example.com/v3/api-docs

# Trae
npx swagger-connect-mcp init --tool trae --url https://example.com/v3/api-docs

# Cursor
npx swagger-connect-mcp init --tool cursor --url https://example.com/v3/api-docs

# OpenCode
npx swagger-connect-mcp init --tool opencode --url https://example.com/v3/api-docs

# CodeBuddy
npx swagger-connect-mcp init --tool codebuddy --url https://example.com/v3/api-docs

Add --with-instructions to generate integration rules for the selected Agent. Use all to generate every configuration.

All agents with integration instructions:

npx swagger-connect-mcp init \
  --tool all \
  --with-instructions \
  --url https://example.com/v3/api-docs

init creates or merges swagger-mcp.config.json, the selected agent configuration, and—when --with-instructions is used—AGENTS.md, CLAUDE.md, CODEBUDDY.md, or native rule files.

There is no postinstall script. Installing the package does not modify the project automatically.

Multiple Swagger documents

npx swagger-connect-mcp add billing \
  --url https://example.com/billing/v3/api-docs \
  --base-url https://example.com/billing

npx swagger-connect-mcp remove billing

Example:

{
  "sources": {
    "default": { "url": "https://example.com/v3/api-docs" },
    "billing": {
      "url": "https://example.com/billing/v3/api-docs",
      "baseUrl": "https://example.com/billing"
    }
  },
  "allowRequests": false
}

Supports OpenAPI 3.x, Swagger 2.0, JSON, YAML, and Swagger UI URLs.

Authentication

Use environment variables instead of committing tokens:

{
  "sources": {
    "private": {
      "url": "https://example.com/v3/api-docs",
      "headers": {
        "Authorization": "Bearer ${SWAGGER_TOKEN}"
      }
    }
  }
}
$env:SWAGGER_TOKEN = "your-token"

MCP tools

Read-only tools:

  • swagger_list_sources

  • swagger_list_operations

  • swagger_get_operation

  • swagger_get_schema

  • swagger:///openapi

Compatibility aliases: fetch_swagger_info, list_endpoints, get_endpoint_details, validate_api_response.

Business API requests are disabled by default. Set allowRequests to true to enable swagger_request and execute_api_request.

Short prompt

After generating AGENTS.md:

Integrate the settlement detail API using Swagger. Do not guess fields.

Development and publishing

npm run build
npm test
npm pack --dry-run
npm publish --registry=https://registry.npmjs.org

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Exposes Swagger/OpenAPI API documentation to AI models, enabling exploration, search, and interaction with endpoints, schemas, and execution of API calls.
    14
    1 npm
    2
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to discover, search, and call any REST API described by an OpenAPI or Swagger document. Supports multiple API endpoints with authentication and parameter handling.
    6 npm
    MIT