Skip to main content
Glama

MCP Swagger Reader

MCP工具,用于读取和解析Swagger/OpenAPI规范,帮助你快速查看项目接口信息。

功能

  • 支持配置多个项目的Swagger地址(支持URL和本地文件)

  • 获取所有API接口列表

  • 获取指定接口的详细信息

  • 获取数据模型/Schemas

  • 搜索API接口

  • 根据接口路径和方法生成TypeScript类型(请求参数、Body、响应)

Related MCP server: Swagger MCP (Multi-API Edition)

安装

cd mcp-swagger-reader
npm install
npm run build

MCP配置

Cursor/Claude Desktop配置

在 ~/.cursor/mcp.json 或 ~/Library/Application Support/Claude/mcp.json 中添加:

{
  "mcpServers": {
    "swagger-reader": {
      "command": "node",
      "args": [
        "/Users/momei/code/my_project/mcp-swagger-reader/dist/index.mjs"
      ],
      "env": {}
    }
  }
}

环境变量预置项目

可以通过 SWAGGER_PROJECTS 环境变量预置项目:

{
  "mcpServers": {
    "swagger-reader": {
      "command": "node",
      "args": ["/path/to/dist/index.mjs"],
      "env": {
        "SWAGGER_PROJECTS": "[{\"name\":\"my-api\",\"swaggerUrl\":\"http://example.com/swagger.json\"}]"
      }
    }
  }
}

支持多个项目:

"SWAGGER_PROJECTS": "[{\"name\":\"api1\",\"swaggerUrl\":\"http://...\"},{\"name\":\"api2\",\"swaggerUrl\":\"http://...\"}]"

数据存储

项目配置保存在 ~/.mcp-swagger-reader/projects.json,重启后自动加载。

工具列表

add_swagger_project

添加一个项目的Swagger配置。

参数:

  • name: 项目名称

  • swaggerUrl: Swagger/OpenAPI JSON文件的URL地址或本地文件路径

示例:

await add_swagger_project({
  name: "my-project",
  swaggerUrl: "https://api.example.com/v2/api-docs",
});

list_swagger_projects

列出所有已配置的Swagger项目。

get_api_endpoints

获取指定项目的所有API接口列表。

参数:

  • projectName: 项目名称

get_api_detail

获取指定接口的详细信息。

参数:

  • projectName: 项目名称

  • path: API路径,如 /users/{id}

  • method: HTTP方法,如 GET, POST

get_schemas

获取指定项目的所有数据模型/Schemas。

参数:

  • projectName: 项目名称

search_apis

根据关键词搜索API接口。

参数:

  • projectName: 项目名称

  • keyword: 搜索关键词

reload_swagger

重新加载项目的Swagger规范。

参数:

  • projectName: 项目名称

generate_ts_by_endpoint

根据 API 接口路径和方法生成 TypeScript 类型(请求参数、Body、响应)。

参数:

  • projectName: 项目名称

  • path: API路径,如 /access/packageUnit/queryList

  • method: HTTP方法,如 GET, POST, PUT, DELETE

返回:

  • T{Endpoint}Params - 请求参数接口

  • T{Endpoint}Response - 响应类型接口

使用示例

  1. 首先添加项目配置:

await add_swagger_project({
  name: "user-service",
  swaggerUrl: "https://petstore.swagger.io/v2/swagger.json",
});
  1. 查看所有接口:

await get_api_endpoints({ projectName: "user-service" });
  1. 获取某个接口详情:

await get_api_detail({
  projectName: "user-service",
  path: "/pet/{petId}",
  method: "GET",
});
  1. 搜索接口:

await search_apis({
  projectName: "user-service",
  keyword: "user",
});

Available Tools

9 tools
add_swagger_projectC

添加一个项目的Swagger/OpenAPI配置

Inputs: name (required), swaggerUrl (required).

clear_type_cacheA

清除指定项目的类型缓存,强制重新生成

Inputs: projectName.

generate_ts_by_endpointC

根据 API 接口路径和方法生成 TypeScript 类型(请求参数、Body、响应),作为模型输入,可以进一步调整并输出

Inputs: path (required), method (required), projectName (required).

get_api_detailC

获取指定接口的详细信息

Inputs: path (required), method (required), projectName (required).

get_api_endpointsA

获取指定项目的所有API接口列表

Inputs: projectName (required).

get_schemasB

获取指定项目的所有数据模型/Schemas

Inputs: projectName (required).

list_swagger_projectsA

列出所有已配置的Swagger项目

Inputs: no named parameters.

reload_swaggerB

重新加载项目的Swagger规范,同时清除类型缓存

Inputs: projectName (required).

search_apisB

根据关键词搜索API接口

Inputs: keyword (required), projectName (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 9 tools

    Disambiguation4/5

    Most tools target distinct resources and actions: endpoints, schemas, projects, and type generation are clearly separated. The only potential confusion is between reload_swagger and clear_type_cache, as reload also clears the type cache, but the descriptions clarify that reload additionally re-fetches the spec.

    Naming Consistency4/5

    Tool names consistently follow a snake_case verb_noun pattern (get_, list_, add_, search_, clear_, generate_). Minor inconsistencies exist, such as 'get_schemas' missing an 'api' prefix and 'list_swagger_projects' plural versus 'add_swagger_project' singular, but the overall pattern is predictable.

    Tool Count5/5

    With 9 tools, the server is well-scoped for its purpose. Each tool serves a distinct function within the Swagger/OpenAPI management and code generation workflow, without unnecessary redundancy or bloat.

    Completeness4/5

    Core workflows are well covered: project setup, listing, reloading, endpoint discovery, schema inspection, and TypeScript generation. The main gap is that projects can be added but not deleted or updated, which may be a minor limitation for full project lifecycle management.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      F
      maintenance
      Enables AI to interact with multiple Swagger/OpenAPI specifications by listing endpoints, exploring models, and generating TypeScript code. It centralizes the management of various APIs through a configuration file, allowing for seamless integration of documentation into AI workflows.
      174 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Loads and queries OpenAPI/Swagger documents, providing tools to list APIs, get details, search endpoints, and manage schemas for efficient API exploration.
      4
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Parses Swagger 2.0 and OpenAPI 3.x specifications, exposing API endpoints, schemas, and authentication through MCP tools with local caching to reduce token usage.
      11
      10 npm
      1
      MIT