Skip to main content
Glama
swagger-codegen-mcp

swagger-codegen-mcp

by aehyok

Swagger API 代码生成器 MCP

从 Swagger/OpenAPI 文档自动生成 TypeScript API 代码的 MCP 服务器。

功能

  • list_services - 列出所有可用的 API 服务及其 Swagger URL

  • list_tags - 列出 Swagger 中所有的 API 分组(tags)

  • list_endpoints - 列出指定 tag 下的所有接口

  • get_endpoint_detail - 获取单个接口的详细信息

  • generate_api_code - 生成 TypeScript 代码(支持按 tag 或单个接口)

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

支持的服务

MCP 服务器预配置了以下 API 服务,会根据 API 路径自动推断使用哪个服务:

服务名

Swagger URL

匹配路径示例

village

/api/village/swagger.json

/api/village/VillageNursing/...

basic

/api/basic/swagger.json

/api/basic/User/...

ffp

/api/ffp/swagger.json

/api/ffp/Project/...

dynamic

/api/dynamic/swagger.json

/api/dynamic/Form/...

customform

/api/customform/swagger.json

/api/customform/Template/...

ncdp

/api/ncdp/swagger.json

/api/ncdp/Report/...

gis

/api/gis/swagger.json

/api/gis/Map/...

query

/api/query/swagger.json

/api/query/Data/...

提示:当你传入 path 参数时(如 /api/village/VillageNursing/GetNursingStats),服务器会自动从路径中提取 village 并使用对应的 swagger.json,无需手动指定 swagger_url。

安装

cd C:\Users\Administrator\.gemini\mcp\swagger-codegen-mcp
npm install

配置 Gemini CLI

在 settings.json 中添加此 MCP 服务器:

{
  "mcpServers": {
    "swagger-codegen": {
      "command": "node",
      "args": [
        "C:\\Users\\Administrator\\.gemini\\mcp\\swagger-codegen-mcp\\src\\index.js"
      ]
    }
  }
}

使用示例

1. 列出所有可用服务

list_services()

返回示例:

{
  "success": true,
  "total": 8,
  "services": [
    {
      "name": "village",
      "url": "https://dvs-dev2.utuapp.cn/api/village/swagger.json"
    },
    {
      "name": "basic",
      "url": "https://dvs-dev2.utuapp.cn/api/basic/swagger.json"
    }
  ],
  "hint": "使用 path 参数时会自动根据路径推断服务"
}

2. 列出所有 API 分组

list_tags()

返回示例:

{
  "success": true,
  "swaggerUrl": "https://dvs-dev2.utuapp.cn/api/village/swagger.json",
  "total": 50,
  "tags": [
    { "name": "VillageNursing", "description": "" },
    { "name": "Accusation", "description": "" }
  ]
}

3. 列出指定分组的接口

list_endpoints(tag: "VillageNursing")

4. 获取接口详情(自动推断服务)

get_endpoint_detail(
  path: "/api/village/VillageNursing/GetNursingStats",
  method: "get"
)

无需指定 swagger_url,会自动从 path 中提取 village 并使用 village 服务的 swagger.json。

5. 生成整个模块的代码

generate_api_code(tag: "VillageNursing")

生成两个文件:

  • villagenursing.types.ts - 类型定义

  • villagenursing.ts - API 函数

6. 生成单个接口的代码(自动推断服务)

generate_api_code(
  path: "/api/basic/User/GetList",
  method: "get"
)

会自动使用 basic 服务的 swagger.json。

生成的代码风格

生成的代码兼容项目的 request.js 封装:

import request from "@/common/utils/request";
import type {
  GetPageListParams,
  VillageNursingListDto,
} from "./villagenursing.types";

/** 查询列表 */
export function getPageList(
  params: GetPageListParams
): Promise<VillageNursingListDto[]> {
  return request("/api/village/VillageNursing/GetPageList", {
    method: "get",
    params: { RegionId, Limit, Page, Keyword },
  });
}

配置文件

服务端点配置位于 src/swagger-config.js,可以根据需要添加更多服务:

const SWAGGER_SERVICES = {
  village: `${API_BASE_URL}/village/swagger.json`,
  basic: `${API_BASE_URL}/basic/swagger.json`,
  // 添加更多服务...
};

测试

# 运行配置测试
node test/test-config.js

# 查找模型定义
node test/find-model.js

Available Tools

5 tools
generate_api_codeA

生成TypeScript API代码。可以按tag生成整个模块,或按单个接口生成。会根据path自动推断对应的服务。

Inputs: tag, path, method, swagger_url.

get_endpoint_detailA

获取单个API接口的详细信息,包括参数和响应定义。会根据path自动推断对应的服务(如/api/village/...会使用village服务)。

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

list_endpointsA

列出指定tag下的所有API接口。每次调用都会获取最新的Swagger文档。

Inputs: tag (required), swagger_url.

list_servicesA

列出所有可用的API服务及其Swagger URL。用于了解有哪些服务可用。

Inputs: no named parameters.

list_tagsA

列出Swagger文档中所有的API分组(tags)。每次调用都会获取最新的Swagger文档。

Inputs: swagger_url.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool targets a distinct layer: service discovery, tag listing, endpoint listing, endpoint detail, and code generation. The descriptions make the hierarchy clear, so there is no meaningful overlap between tools.

    Naming Consistency5/5

    All tool names follow a consistent snake_case verb_noun pattern: list_* for enumeration, get_ for detail retrieval, and generate_ for code generation. There are no mixed naming styles or vague verbs.

    Tool Count5/5

    Five tools is well within the ideal scope for a focused Swagger codegen server. Each tool earns its place by contributing one necessary step in the discovery-to-generation workflow.

    Completeness4/5

    The set covers the full discovery-to-codegen flow: services, tags, endpoints, endpoint details, and code generation. It lacks whole-service generation and direct schema/model introspection, but agents can work around these by iterating tags or relying on generated code.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A server based on Model Context Protocol that parses Swagger/OpenAPI documents and generates TypeScript types and API client code for different frameworks (Axios, Fetch, React Query).
      12
      16
      MIT
    • 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.
      MIT