Skip to main content
Glama

mcp-swagger-schema

一个 MCP (Model Context Protocol) 服务器,用于查询 Swagger 规范中的接口 schema。

功能

  • 根据 API 路径获取请求和响应的 JSON Schema

  • 自动解析 $ref 引用

  • 支持路径参数匹配(如 /api/users/{id}

  • 内置缓存机制

Related MCP server: swagger-json-mcp

快速开始

第一步:找到你的 Swagger JSON 地址

你需要先获取项目的 Swagger/OpenAPI 规范地址,通常是类似这样的 URL:

  • https://your-api.com/v3/api-docs

第二步:配置 MCP 服务器

在你的 MCP 配置文件中(通常是 .mcp/config.json 或类似的配置),添加如下配置:

{
  "mcpServers": {
    "swagger-schema": {
      "command": "npx",
      "args": ["-y", "mcp-swagger-schema"],
      "env": {
        "SWAGGER_SPEC_URL": "替换成你的swagger地址"
      }
    }
  }
}

⚠️ 常见问题:找不到 npx 命令

如果启动失败,提示找不到 npx,按以下步骤解决:

步骤 1:打开终端,运行以下命令

which npx

你会看到类似这样的输出:

/Users/你的用户名/.nvm/versions/node/v20.0.0/bin/npx

步骤 2:复制 bin 目录路径

把上面输出的路径,去掉最后的 /npx,得到 bin 目录:

/Users/你的用户名/.nvm/versions/node/v20.0.0/bin

步骤 3:修改配置,添加 PATH

{
  "mcpServers": {
    "swagger-schema": {
      "command": "npx",
      "args": ["-y", "mcp-swagger-schema"],
      "env": {
        "SWAGGER_SPEC_URL": "替换成你的swagger地址",
        "PATH": "步骤2得到的路径:/usr/bin:/bin"
      }
    }
  }
}

例如:

{
  "mcpServers": {
    "swagger-schema": {
      "command": "npx",
      "args": ["-y", "mcp-swagger-schema"],
      "env": {
        "SWAGGER_SPEC_URL": "https://api.example.com/swagger.json",
        "PATH": "/Users/zhangsan/.nvm/versions/node/v20.0.0/bin:/usr/bin:/bin"
      }
    }
  }
}

使用方法

配置完成后,在对话中直接说:

获取 /api/users 接口的 schema

AI 会调用工具返回该接口的请求参数和响应结构。

工具参数说明

参数

必填

说明

path

接口路径,如 /api/users

method

HTTP 方法(get/post/put/delete),不填会自动选择

返回示例

{
  "found": true,
  "path": "/api/users",
  "method": "post",
  "summary": "创建用户",
  "request": {
    "body": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "email": { "type": "string" }
      }
    }
  },
  "response": {
    "type": "object",
    "properties": {
      "id": { "type": "integer" },
      "name": { "type": "string" }
    }
  }
}

环境变量

变量名

必填

说明

SWAGGER_SPEC_URL

Swagger/OpenAPI JSON 规范的 URL

SWAGGER_CACHE_TTL_MS

缓存过期时间(毫秒),默认 60000

License

MIT

Available Tools

1 tool
get_api_schemaC

根据接口路径获取 Swagger/OpenAPI 的请求和响应 schema

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes接口路径,如 /api/paymentPackage/updatePaymentPackageMaterialConfig
methodNoHTTP 方法,可选,如 post/get;不填则自动选一个存在的方法

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions fetching schemas but lacks details on error handling, authentication needs, rate limits, or output format. For a tool with no annotation coverage, this leaves significant gaps in understanding how it behaves in practice.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized for a simple tool, though it could be slightly more structured by front-loading key information more explicitly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It does not explain what the tool returns (e.g., schema format, error responses) or behavioral aspects like permissions or limitations. For a tool with no structured support, the description should provide more context to be fully helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for both parameters in the input schema. The description adds no additional meaning beyond what the schema provides, such as examples or edge cases. With high schema coverage, the baseline score of 3 is appropriate, as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据接口路径获取 Swagger/OpenAPI 的请求和响应 schema' (Get Swagger/OpenAPI request and response schema based on API path). It specifies the verb '获取' (get) and the resource 'schema', making the purpose understandable. However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or constraints. It simply states what the tool does without context about its application or limitations, such as when it's appropriate to fetch schemas or what happens if the path is invalid.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev1.1.0
    • First observedget_api_schema

TDQS

B3.1/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool has a clear, singular purpose of retrieving API schemas based on interface paths.

Naming Consistency5/5

The single tool name 'get_api_schema' follows a clear verb_noun pattern (get + api_schema). Since there is only one tool, consistency is inherently perfect with no deviations to assess.

Tool Count2/5

A single tool is too few for a server named 'mcp-swagger-schema', which suggests a broader scope related to Swagger/OpenAPI schemas. One tool feels thin and limits functionality, such as lacking operations for listing, updating, or validating schemas.

Completeness2/5

The tool surface is severely incomplete for the implied domain of Swagger/OpenAPI schema management. While 'get_api_schema' provides retrieval, there are obvious gaps like creating, updating, deleting, or listing schemas, which are essential for full coverage.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers