suhailtajshaik/swagger-to-mcp
3.1
If you are the rightful owner of swagger-to-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This tool converts Swagger/OpenAPI specifications into a dynamic Model Context Protocol (MCP) server, enabling seamless integration and interaction with API endpoints.
Swagger to MCP Server
Convert any Swagger/OpenAPI specification into a dynamic Model Context Protocol (MCP) server.
Features
- 🚀 Automatically generates MCP tools from Swagger/OpenAPI specs
- 📘 Supports both local files (.yaml, .yml, .json) and remote URLs
- ✅ Built-in JSON schema validation using AJV
- 🔄 Dynamic endpoint mapping with path parameters
- 🪶 Generates MCP manifest (mcp.json) for easy integration
Installation
pnpm install
Usage
Start the MCP server
pnpm start
Or with a custom Swagger file:
node server.js --swagger=./path/to/your/spec.yaml
Generate manifest only (without starting server)
node server.js --swagger=./petstore.yaml --manifest-only
Use a remote Swagger URL
node server.js --swagger=https://petstore.swagger.io/v2/swagger.json
Configuration
Create a .env file to configure the server:
MCP_PORT=4000
How It Works
- Load Swagger/OpenAPI spec - From local file or URL
- Parse endpoints - Extract all paths and operations
- Generate MCP tools - Each endpoint becomes an MCP tool with:
- Input schema validation
- Output schema definition
- HTTP request handler
- Start MCP server - Listen on configured port and handle tool requests
Example
The included petstore.yaml provides a simple example:
openapi: 3.0.1
info:
title: Swagger Petstore
version: 1.0.0
servers:
- url: https://petstore.swagger.io/v2
paths:
/pet/{petId}:
get:
summary: Find pet by ID
operationId: getPetById
parameters:
- name: petId
in: path
required: true
schema:
type: integer
responses:
'200':
description: successful operation
This generates an MCP tool that can fetch pet information by ID.
License
MIT