Swagger API Client Generator MCP server

Generates strongly-typed API clients and TypeScript types from Swagger/OpenAPI specifications, streamlining REST API integration with template-based code generation for different client frameworks.
Back to servers
Setup instructions
Provider
tuskermanshu
Release date
Mar 20, 2025
Language
TypeScript
Stats
16 stars

The Swagger MCP Server is a powerful tool for parsing Swagger/OpenAPI documentation and generating TypeScript types and API client code. It leverages the Model Context Protocol (MCP) to make these capabilities easily accessible and integrable with large language models.

Installation

Prerequisites

Before installing, make sure you have Node.js installed on your system.

Setup Instructions

Install the required dependencies:

npm install
# or using pnpm
pnpm install

Starting the Server

Launch the MCP server with:

node start-server.js

By default, the server communicates through standard input/output.

Using the MCP Server

The server offers several tools for working with Swagger/OpenAPI documentation. Here are the main capabilities:

Parsing Swagger/OpenAPI Documentation

Standard Parser

Use the standard parser for basic parsing needs:

{
  "method": "parse-swagger",
  "params": {
    "url": "https://petstore3.swagger.io/api/v3/openapi.json",
    "includeSchemas": true,
    "includeDetails": true
  }
}

Optimized Parser

For more advanced parsing with additional options:

{
  "method": "parse-swagger-optimized",
  "params": {
    "url": "https://petstore3.swagger.io/api/v3/openapi.json",
    "includeSchemas": true,
    "includeDetails": true,
    "useCache": true,
    "skipValidation": true,
    "cacheTTLMinutes": 60,
    "lazyLoading": false,
    "filterTag": "pet"
  }
}

Lightweight Parser

For quicker processing of large documents:

{
  "method": "parse-swagger-lite",
  "params": {
    "url": "https://petstore3.swagger.io/api/v3/openapi.json",
    "includeSchemas": false,
    "includeDetails": false,
    "useCache": true,
    "skipValidation": true
  }
}

Generating TypeScript Types

Standard Type Generator

Generate TypeScript types from your Swagger documentation:

{
  "method": "generate-typescript-types",
  "params": {
    "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json",
    "outputDir": "./generated/types",
    "namespace": "PetStore",
    "strictTypes": true,
    "generateEnums": true,
    "generateIndex": true
  }
}

Optimized Type Generator

For more control and better performance with large APIs:

{
  "method": "generate-typescript-types-optimized",
  "params": {
    "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json",
    "outputDir": "./generated/types",
    "namespace": "PetStore",
    "strictTypes": true,
    "useCache": true,
    "skipValidation": true,
    "lazyLoading": true,
    "includeSchemas": ["Pet", "Order", "User"]
  }
}

Creating API Clients

Standard API Client Generator

Generate client code for your API:

{
  "method": "generate-api-client",
  "params": {
    "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json",
    "outputDir": "./generated/api",
    "clientType": "axios",
    "generateTypeImports": true,
    "typesImportPath": "../types",
    "groupBy": "tag"
  }
}

Optimized API Client Generator

For more advanced client generation with additional options:

{
  "method": "generate-api-client-optimized",
  "params": {
    "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json",
    "outputDir": "./generated/api",
    "clientType": "react-query",
    "generateTypeImports": true,
    "typesImportPath": "../types",
    "groupBy": "tag",
    "useCache": true,
    "skipValidation": true,
    "lazyLoading": true,
    "includeTags": ["pet", "store"]
  }
}

Working with Large API Documents

For efficient processing of large API documentation:

  • Use optimized tools with caching and lazy loading enabled
  • Filter by tags or path prefixes to retrieve only needed operations
  • Include schema definitions only when necessary
  • Set appropriate cache TTL to avoid frequent re-parsing

Supported Client Frameworks

The server can generate client code for these frameworks:

  • Axios: Full-featured Promise-based HTTP client
  • Fetch: Browser's native API with no extra dependencies
  • React Query: Data fetching and caching library for React applications

Cache Management

API documentation is cached in the .api-cache directory. To clear the cache:

  • Delete the .api-cache directory
  • Or set useCache: false in your parameters

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "swagger-mcp-server" '{"command":"node","args":["start-server.js"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "swagger-mcp-server": {
            "command": "node",
            "args": [
                "start-server.js"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "swagger-mcp-server": {
            "command": "node",
            "args": [
                "start-server.js"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later