Generate Model Context Protocol (MCP) servers from OpenAPI specifications.
This CLI tool automates the generation of MCP-compatible servers that proxy requests to existing REST APIsβenabling AI agents and other MCP clients to seamlessly interact with your APIs using your choice of transport methods.
tsconfig.json
, package.json
, and entry point.npm install -g openapi-mcp-generator
You can also use
yarn global add openapi-mcp-generator
orpnpm add -g openapi-mcp-generator
# Generate an MCP server (stdio) openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir # Generate an MCP web server with SSE openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --transport=web --port=3000 # Generate an MCP StreamableHTTP server openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --transport=streamable-http --port=3000Option Alias Description Default
--input
-i
Path or URL to OpenAPI specification (YAML or JSON) Required --output
-o
Directory to output the generated MCP project Required --server-name
-n
Name of the MCP server (package.json:name
) OpenAPI title or mcp-api-server
--server-version
-v
Version of the MCP server (package.json:version
) OpenAPI version or 1.0.0
--base-url
-b
Base URL for API requests. Required if OpenAPI servers
missing or ambiguous. Auto-detected if possible --transport
-t
Transport mode: "stdio"
(default), "web"
, or "streamable-http"
"stdio"
--port
-p
Port for web-based transports 3000
--force
Overwrite existing files in the output directory without confirmation false
You can also use this package programmatically in your Node.js applications:
import { getToolsFromOpenApi } from 'openapi-mcp-generator'; // Extract MCP tool definitions from an OpenAPI spec const tools = await getToolsFromOpenApi('./petstore.json'); // With options const filteredTools = await getToolsFromOpenApi('https://example.com/api-spec.json', { baseUrl: 'https://api.example.com', dereference: true, excludeOperationIds: ['deletePet'], filterFn: (tool) => tool.method.toLowerCase() === 'get', });
For full documentation of the programmatic API, see PROGRAMMATIC_API.md.
The generated project includes:
<output_directory>/
βββ .gitignore
βββ package.json
βββ tsconfig.json
βββ .env.example
βββ src/
β βββ index.ts
β βββ [transport-specific-files]
βββ public/ # For web-based transports
βββ index.html # Test client
Core dependencies:
@modelcontextprotocol/sdk
- MCP protocol implementationaxios
- HTTP client for API requestszod
- Runtime validationjson-schema-to-zod
- Convert JSON Schema to ZodCommunicates with MCP clients via standard input/output. Ideal for local development or integration with LLM tools.
Launches a fully functional HTTP server with:
Implements the MCP StreamableHTTP transport which offers:
Configure auth credentials in your environment:
Auth Type Variable Format API KeyAPI_KEY_<SCHEME_NAME>
Bearer BEARER_TOKEN_<SCHEME_NAME>
Basic Auth BASIC_USERNAME_<SCHEME_NAME>
, BASIC_PASSWORD_<SCHEME_NAME>
OAuth2 OAUTH_CLIENT_ID_<SCHEME_NAME>
, OAUTH_CLIENT_SECRET_<SCHEME_NAME>
, OAUTH_SCOPES_<SCHEME_NAME>
βΆοΈ Running the Generated Server
cd path/to/output/dir npm install # Run in stdio mode npm start # Run in web server mode npm run start:web # Run in StreamableHTTP mode npm run start:httpTesting Web-Based Servers
For web and StreamableHTTP transports, a browser-based test client is automatically generated:
http://localhost:<port>
Contributions are welcome!
git checkout -b feature/amazing-feature
npm run format.write
to format your codegit commit -m "Add amazing feature"
π Repository: github.com/harsha-iiiv/openapi-mcp-generator
MIT License β see LICENSE for full details.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4