swagger-api-mcp-server

swagger-api-mcp-server

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.

Category
访问服务器

README

Swagger API MCP Server

License Build & Test npm version npm downloads Node.js Version MCP Badge

English | 中文

An MCP (Model Context Protocol) server that parses Swagger 2.0 and OpenAPI 3.x specifications, exposing API structure through MCP tools. Features a local file-cache architecture that reduces token usage by 85-95% compared to inline responses.

Features

  • Swagger 2.0 & OpenAPI 3.x — Full dual-format support
  • Smart Caching — Spec parsed once, stored as local JSON files; tools return compact summaries + file paths (~200 chars vs 5-20KB)
  • 11 MCP Tools — Load, browse, search, call APIs, and manage auth dynamically
  • 3 MCP Prompts — Guided workflows for exploring, searching, and integrating APIs
  • 3 MCP Resources — Direct access to cached API info, endpoints, and schemas
  • Two Transport Modes — stdio (for CLI/IDE integration) and HTTP (for multi-session web use)
  • 2-Phase API Calls — Preview requests before executing them
  • Zero External Parsers — Custom $ref resolver with circular reference protection

Prerequisites

  • Node.js >= 24

Quick Start

Install from npm

npm install -g swagger-api-mcp-server

Or clone and build

git clone https://github.com/NekoTarou/swagger-api-mcp-server.git
cd swagger-api-mcp-server
npm install
npm run build

Run

# stdio mode (default) — for MCP clients like Claude Desktop
npm start

# Auto-load a spec on startup
SWAGGER_URL=https://petstore.swagger.io/v2/swagger.json npm start

# HTTP mode — multi-session with Express
npm run start:http

MCP Client Configuration

Claude Desktop

Add to your Claude Desktop config file (claude_desktop_config.json):

{
  "mcpServers": {
    "swagger-api": {
      "command": "npx",
      "args": ["-y", "swagger-api-mcp-server"],
      "env": {
        "SWAGGER_URL": "https://petstore.swagger.io/v2/swagger.json"
      }
    }
  }
}

Cursor / VS Code

Add to your MCP settings:

{
  "mcpServers": {
    "swagger-api": {
      "command": "npx",
      "args": ["-y", "swagger-api-mcp-server"],
      "env": {
        "SWAGGER_URL": "https://your-api.example.com/openapi.json"
      }
    }
  }
}

Tools

Tool Description
swagger_load_spec Load a Swagger/OpenAPI spec from URL, parse and cache it
swagger_update_cache Re-fetch spec and rebuild cache
swagger_get_info Get API metadata (title, version, servers, auth schemes)
swagger_list_tags List all tags with endpoint counts
swagger_list_paths List endpoints with filtering (tag, method, keyword) and pagination
swagger_get_endpoint Get endpoint summary + cached file path for full details
swagger_list_schemas List schema definitions with filtering and pagination
swagger_get_schema Get schema summary + cached file path for full definition
swagger_search Search across endpoints and schemas by keyword
swagger_call_api Execute HTTP requests with 2-phase confirmation
swagger_set_auth Dynamically set or clear the Authorization header at runtime

Prompts

Prompt Arguments Description
swagger_explore_api url Guided workflow to load and fully explore an API spec
swagger_find_endpoint keyword Search for endpoints by keyword and view full details
swagger_integrate_api url, task Find the right endpoint for a task and execute an API call

Resources

Resource URI Description
api-info swagger://api/info API basic information (title, version, servers, auth)
api-endpoints swagger://api/endpoints Index of all API endpoints
api-schemas swagger://api/schemas Index of all schema/model definitions

Cache Architecture

When a spec is loaded, it's parsed once and stored as structured JSON files:

.swagger-cache/
├── meta.json              # Cache metadata (URL, counts, timestamp)
├── info.json              # Full API info (title, servers, auth)
├── tags.json              # Tag list with endpoint counts
├── paths-index.json       # Endpoint index for fast lookup
├── schemas-index.json     # Schema index for fast lookup
├── endpoints/             # One file per endpoint (deep-resolved)
│   └── GET__users__{id}.json
└── schemas/               # One file per schema (deep-resolved)
    └── User.json

Tools return brief summaries with file paths. The LLM reads full details on demand via the Read tool — saving 85-95% of tokens per call.

Environment Variables

Variable Default Description
SWAGGER_URL (empty) Auto-load spec on startup
TRANSPORT stdio Transport mode: stdio or http
MCP_PORT 3000 HTTP server port
MCP_HOST 0.0.0.0 HTTP server host
API_BASE_URL (empty) Override API base URL for calls
API_AUTH_TOKEN (empty) Initial Authorization header value (can be updated at runtime via swagger_set_auth)
CACHE_DIR .swagger-cache Custom cache directory path
SESSION_TIMEOUT_MS 1800000 HTTP session timeout (30 min)
MAX_SESSIONS 100 Max concurrent HTTP sessions

Development

npm run dev            # Dev mode with auto-reload (tsx watch)
npm test               # Run tests
npm run build          # TypeScript compilation → dist/
npm run clean          # Remove dist/

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选