22
33OpenAPI 3.x to MCP server bridge in TypeScript.
44
5- This project takes an OpenAPI spec and exposes every operation as an MCP tool, while proxying calls to the original REST API.
6-
7- ## Feature checklist
8-
9- - OpenAPI 3.0+ support
10- - Loads YAML/JSON, dereferences ` $ref ` , compiles operations into MCP tools.
11- - Proxy behavior
12- - ` tools/call ` executes real HTTP requests against your API and returns structured results.
13- - Authentication support (env-driven)
14- - API key, Bearer, Basic, OAuth2/OpenID Connect token injection.
15- - Zod validation
16- - Generates Zod schemas from OpenAPI-derived JSON Schema for runtime input validation.
17- - Typed server
18- - Fully typed TypeScript codebase with strict compile checks.
19- - Multiple transports
5+ ` mcp-openapi ` takes an OpenAPI spec and turns it into an MCP server where each OpenAPI operation is an MCP tool. Tool calls are proxied to the original REST API with runtime validation and auth handling.
6+
7+ ## Capabilities
8+
9+ - OpenAPI 3.0+ support (YAML/JSON, ` $ref ` dereference, operation compilation)
10+ - Proxy behavior to upstream REST API
11+ - Authentication via env vars:
12+ - API keys (` in: header|query|cookie ` )
13+ - HTTP Bearer
14+ - HTTP Basic
15+ - OAuth2 / OpenID Connect (static token or client credentials token fetch)
16+ - Runtime validation:
17+ - Zod validation generated from OpenAPI-derived JSON Schema
18+ - AJV JSON Schema validation
19+ - Response schema validation by HTTP status
20+ - Typed TypeScript implementation
21+ - Multiple transports:
2022 - ` stdio `
2123 - ` streamable-http ` (Hono)
22- - deprecated ` sse ` (Hono + SDK SSE transport)
23- - Project scaffold
24- - Includes ` tsconfig.json ` , ` package.json ` , scripts, entrypoint, tests.
25- - Built-in HTML test clients
26- - ` /test/streamable ` and ` /test/sse ` for browser-based interaction testing.
24+ - ` sse ` (legacy compatibility transport)
25+ - Built-in browser test clients:
26+ - ` /test/streamable `
27+ - ` /test/sse `
28+ - Project scaffold (` init ` ) that generates:
29+ - ` package.json `
30+ - ` tsconfig.json `
31+ - ` src/server.ts `
32+ - ` .env.example `
33+ - ` README.md `
34+ - ` Dockerfile `
2735
2836## Install
2937
@@ -33,13 +41,13 @@ npm install
3341
3442## Run
3543
36- ### 1) stdio transport (default)
44+ ### stdio
3745
3846``` bash
3947npm run dev -- --spec ./openapi.yaml
4048```
4149
42- ### 2) StreamableHTTP transport (Hono)
50+ ### StreamableHTTP
4351
4452``` bash
4553npm run dev -- --spec ./openapi.yaml --transport streamable-http --port 3000
@@ -48,10 +56,11 @@ npm run dev -- --spec ./openapi.yaml --transport streamable-http --port 3000
4856Endpoints:
4957
5058- ` http://localhost:3000/health `
59+ - ` http://localhost:3000/metrics `
5160- ` http://localhost:3000/mcp `
5261- ` http://localhost:3000/test/streamable `
5362
54- ### 3) SSE transport (deprecated, for compatibility )
63+ ### SSE (legacy )
5564
5665``` bash
5766npm run dev -- --spec ./openapi.yaml --transport sse --port 3000
@@ -60,99 +69,52 @@ npm run dev -- --spec ./openapi.yaml --transport sse --port 3000
6069Endpoints:
6170
6271- ` http://localhost:3000/health `
72+ - ` http://localhost:3000/metrics `
6373- ` http://localhost:3000/sse `
6474- ` http://localhost:3000/messages?sessionId=... `
6575- ` http://localhost:3000/test/sse `
6676
67- ## Common options
77+ ## CLI
6878
6979``` bash
70- --server-url < url> Override OpenAPI server URL
71- --timeout-ms < ms> HTTP timeout per attempt (default: 20000)
72- --retries < n> Retries on 408/429/5xx + transient network errors (default: 2)
73- --retry-delay-ms < ms> Base retry delay (default: 500)
74- --watch-spec Reload tools when spec changes
80+ mcp-openapi --spec < openapi-file> [options]
81+ mcp-openapi init [dir]
7582```
7683
77- ## Authentication env vars
78-
79- - API key: ` MCP_OPENAPI_API_KEY `
80- - Bearer: ` MCP_OPENAPI_BEARER_TOKEN `
81- - Basic: ` MCP_OPENAPI_BASIC_USERNAME ` , ` MCP_OPENAPI_BASIC_PASSWORD `
82- - OAuth2/OIDC bearer token: ` MCP_OPENAPI_OAUTH2_ACCESS_TOKEN `
83- - Per-scheme override: ` MCP_OPENAPI_<SCHEME_NAME>_TOKEN `
84-
85- ## Validation model
86-
87- Input validation pipeline for ` tools/call ` :
88-
89- 1 . Zod validation (generated from OpenAPI-derived schema)
90- 2 . JSON Schema validation (Ajv)
91-
92- Success responses can also be validated against OpenAPI response schemas, and tool output is validated against MCP ` outputSchema ` .
93-
94- ## Generated tool shape
95-
96- Each OpenAPI operation becomes an MCP tool with:
97-
98- - ` name `
99- - ` description `
100- - ` inputSchema `
101- - ` outputSchema ` (when available)
102- - tool annotations (` readOnlyHint ` , ` idempotentHint ` , etc.)
103-
104- Input argument groups:
105-
106- ``` json
107- {
108- "path" : {},
109- "query" : {},
110- "header" : {},
111- "cookie" : {},
112- "body" : {},
113- "pagination" : {
114- "enabled" : false ,
115- "mode" : " autoCursor" ,
116- "maxPages" : 5 ,
117- "cursorParam" : " cursor" ,
118- "nextCursorPath" : " next_cursor" ,
119- "pageParam" : " page" ,
120- "startPage" : 1
121- }
122- }
123- ```
124-
125- ## Request/response features
126-
127- - Query/path/header/cookie style-aware serialization
128- - Request body content types:
129- - ` application/json `
130- - ` application/x-www-form-urlencoded `
131- - ` multipart/form-data `
132- - ` application/octet-stream `
133- - Pagination helpers:
134- - cursor mode
135- - incrementing page mode
136- - Retry with ` Retry-After ` support
137- - Progress notifications via MCP ` _meta.progressToken `
138- - Cancellation support via MCP cancellation
139-
140- ## Build/test/smoke
84+ Options:
85+
86+ - ` --server-url <url> `
87+ - ` --cache-path <file> `
88+ - ` --print-tools `
89+ - ` --validate-spec `
90+ - ` --transport stdio|streamable-http|sse `
91+ - ` --port <n> `
92+ - ` --watch-spec `
93+ - ` --timeout-ms <ms> `
94+ - ` --retries <n> `
95+ - ` --retry-delay-ms <ms> `
96+ - ` --max-response-bytes <n> `
97+ - ` --max-concurrency <n> `
98+ - ` --allow-hosts host1,host2 `
99+
100+ ## Auth env vars
101+
102+ - ` MCP_OPENAPI_API_KEY `
103+ - ` MCP_OPENAPI_BEARER_TOKEN `
104+ - ` MCP_OPENAPI_BASIC_USERNAME `
105+ - ` MCP_OPENAPI_BASIC_PASSWORD `
106+ - ` MCP_OPENAPI_OAUTH2_ACCESS_TOKEN `
107+ - ` MCP_OPENAPI_OAUTH2_CLIENT_ID `
108+ - ` MCP_OPENAPI_OAUTH2_CLIENT_SECRET `
109+ - ` MCP_OPENAPI_<SCHEME_NAME>_TOKEN `
110+ - ` MCP_OPENAPI_<SCHEME_NAME>_CLIENT_ID `
111+ - ` MCP_OPENAPI_<SCHEME_NAME>_CLIENT_SECRET `
112+
113+ ## Build and verify
141114
142115``` bash
143116npm run check
144117npm run build
145118npm test
146119npm run smoke
147120```
148-
149- ` npm run smoke ` starts a full MCP client/server+HTTP flow and verifies that an OpenAPI spec is transformed into callable MCP tools.
150-
151- ## Browser test clients
152-
153- After launching a web transport:
154-
155- - StreamableHTTP client: ` http://localhost:<port>/test/streamable `
156- - SSE client: ` http://localhost:<port>/test/sse `
157-
158- These pages let you initialize, list tools, and call tools directly in-browser.
0 commit comments