npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mcp-swagger-schema

v1.1.1

Published

MCP server for querying Swagger schema - get request/response schemas by API path

Readme

mcp-swagger-schema

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

功能

  • 根据 API 路径获取请求和响应的 JSON Schema
  • 自动解析 $ref 引用
  • 支持路径参数匹配(如 /api/users/{id}
  • 内置缓存机制

快速开始

第一步:找到你的 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