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.
- π§ OpenAPI 3.0 Support: Converts any OpenAPI 3.0+ spec into an MCP-compatible server.
- π Proxy Behavior: Proxies calls to your original REST API while validating request structure and security.
- π Authentication Support: API keys, Bearer tokens, Basic auth, and OAuth2 supported via environment variables.
- π§ͺ Zod Validation: Automatically generates Zod schemas from OpenAPI definitions for runtime input validation.
- βοΈ Typed Server: Fully typed, maintainable TypeScript code output.
- π Multiple Transports: Communicate over stdio, SSE via Hono, or StreamableHTTP.
- π§° Project Scaffold: Generates a complete Node.js project with
tsconfig.json,package.json, and entry point. - π§ͺ Built-in HTML Test Clients: Test API interactions visually in your browser (for web-based transports).
- π Analytics & Telemetry: Optional MCPcat analytics and OpenTelemetry support for monitoring and debugging.
npm install -g openapi-mcp-generatorYou can also use
yarn global add openapi-mcp-generatororpnpm 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=3000
# Generate with MCPcat analytics enabled
openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --with-mcpcat
# Generate with OpenTelemetry tracing enabled
openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --with-otel
# Generate with both MCPcat analytics and OpenTelemetry
openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --with-mcpcat --with-otel| Option | 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 |
--default-include |
Default behavior for x-mcp filtering. Accepts true or false (case-insensitive). true = include by default, false = exclude by default. |
true |
|
--with-mcpcat |
Enable MCPcat product analytics for usage insights and debugging | false |
|
--with-otel |
Enable OpenTelemetry (OTLP) exporters for distributed tracing and logging | false |
|
--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 Zod- Transport-specific deps (Hono, uuid, etc.)
Communicates with MCP clients via standard input/output. Ideal for local development or integration with LLM tools.
Launches a fully functional HTTP server with:
- Server-Sent Events (SSE) for bidirectional messaging
- REST endpoint for client β server communication
- In-browser test client UI
- Multi-connection support
- Built with lightweight Hono framework
Implements the MCP StreamableHTTP transport which offers:
- Stateful JSON-RPC over HTTP POST requests
- Session management using HTTP headers
- Proper HTTP response status codes
- Built-in error handling
- Compatibility with MCP StreamableHTTPClientTransport
- In-browser test client UI
- Built with lightweight Hono framework
| Feature | stdio | web (SSE) | streamable-http |
|---|---|---|---|
| Protocol | JSON-RPC over stdio | JSON-RPC over SSE | JSON-RPC over HTTP |
| Connection | Persistent | Persistent | Request/response |
| Bidirectional | Yes | Yes | Yes (stateful) |
| Multiple clients | No | Yes | Yes |
| Browser compatible | No | Yes | Yes |
| Firewall friendly | No | Yes | Yes |
| Load balancing | No | Limited | Yes |
| Status codes | No | Limited | Full HTTP codes |
| Headers | No | Limited | Full HTTP headers |
| Test client | No | Yes | Yes |
Configure auth credentials in your environment:
| Auth Type | Variable Format |
|---|---|
| API Key | API_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> |
MCPcat provides product analytics and live debugging tools specifically designed for MCP servers. When enabled with --with-mcpcat, your generated server will include:
- Usage tracking and analytics
- Tool call monitoring
- Error detection and reporting
- Performance insights
To use MCPcat:
- Sign up for free at mcpcat.io
- Get your project ID
- Set the
MCPCAT_PROJECT_IDenvironment variable
Enable distributed tracing and logging with --with-otel to integrate with your existing observability stack:
- OTLP trace exporters
- Distributed request tracing
- Performance metrics
- Integration with popular observability platforms (Datadog, New Relic, Grafana, etc.)
Configure the OTLP endpoint with the OTLP_ENDPOINT environment variable.
Use both flags together (--with-mcpcat --with-otel) to get the benefits of both MCPcat's MCP-specific analytics and OpenTelemetry's broader observability ecosystem.
Configure analytics and telemetry:
| Variable | Description | Required When |
|---|---|---|
MCPCAT_PROJECT_ID |
Your MCPcat project ID from mcpcat.io | --with-mcpcat |
OTLP_ENDPOINT |
OpenTelemetry collector endpoint URL | --with-otel |
You can control which operations are exposed as MCP tools using a vendor extension flag x-mcp. This extension is supported at the root, path, and operation levels. By default, endpoints are included unless explicitly excluded.
- Extension:
x-mcp: true | false - Default:
true(include by default) - Precedence: operation > path > root (first non-undefined wins)
- CLI option:
--default-include falseto change default to exclude by default
Examples:
# Optional root-level default
x-mcp: true
paths:
/pets:
x-mcp: false # exclude all ops under /pets
get:
x-mcp: true # include this operation anyway
/users/{id}:
get:
# no x-mcp -> included by defaultThis uses standard OpenAPI extensions (x-β¦ fields). See the OpenAPI Extensions guide for details.
Note: x-mcp must be a boolean or the strings "true"/"false" (case-insensitive). Other values are ignored in favor of higher-precedence or default behavior.
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:httpFor web and StreamableHTTP transports, a browser-based test client is automatically generated:
- Start the server using the appropriate command
- Open your browser to
http://localhost:<port> - Use the test client to interact with your MCP server
- Node.js v20 or later
Contributions are welcome!
- Fork the repo
- Create a feature branch:
git checkout -b feature/amazing-feature - Run
npm run format.writeto format your code - Commit your changes:
git commit -m "Add amazing feature" - Push and open a PR
π Repository: github.com/harsha-iiiv/openapi-mcp-generator
MIT License β see LICENSE for full details.