M
MCP Openapi
by @haasonsaas
OpenAPI 3.x to MCP server bridge in TypeScript with stdio, StreamableHTTP, and SSE transports
Created 2/13/2026
Updated about 9 hours ago
README
Repository documentation and setup instructions
mcp-openapi
OpenAPI 3.x to MCP server bridge in TypeScript.
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.
Capabilities
- OpenAPI 3.0+ support (YAML/JSON,
$refdereference, operation compilation) - Proxy behavior to upstream REST API
- Authentication via env vars:
- API keys (
in: header|query|cookie) - HTTP Bearer
- HTTP Basic
- OAuth2 / OpenID Connect (static token or client credentials token fetch)
- API keys (
- Runtime validation:
- Zod validation generated from OpenAPI-derived JSON Schema
- AJV JSON Schema validation
- Response schema validation by HTTP status
- Typed TypeScript implementation
- Strict lint mode for OpenAPI quality gates (
--strict) - Configurable tool naming template (
--tool-name-template) - Policy engine:
- allow/deny tool patterns
- allow methods/path prefixes
- allow hosts
- Optional response transform hook (
--response-transform <module>) - Multiple transports:
stdiostreamable-http(Hono)sse(legacy compatibility transport)
- Transport hardening:
- graceful shutdown
- SSE session caps/TTL
- Observability:
- Prometheus metrics
- status counters
- latency histogram buckets
- Built-in browser test clients:
/test/streamable/test/sse
- Project scaffold (
init) that generates:package.jsontsconfig.jsonsrc/server.ts.env.exampleREADME.mdDockerfile
Install
npm install
Run
stdio
npm run dev -- --spec ./openapi.yaml
StreamableHTTP
npm run dev -- --spec ./openapi.yaml --transport streamable-http --port 3000
Endpoints:
http://localhost:3000/healthhttp://localhost:3000/metricshttp://localhost:3000/mcphttp://localhost:3000/test/streamable
SSE (legacy)
npm run dev -- --spec ./openapi.yaml --transport sse --port 3000
Endpoints:
http://localhost:3000/healthhttp://localhost:3000/metricshttp://localhost:3000/ssehttp://localhost:3000/messages?sessionId=...http://localhost:3000/test/sse
CLI
mcp-openapi --spec <openapi-file> [options]
mcp-openapi init [dir]
mcp-openapi generate --spec <openapi-file> [--out-dir ./generated]
Options:
--server-url <url>--cache-path <file>--out-dir <dir>--strict--tool-name-template <template>--print-tools--validate-spec--transport stdio|streamable-http|sse--port <n>--watch-spec--timeout-ms <ms>--retries <n>--retry-delay-ms <ms>--max-response-bytes <n>--max-concurrency <n>--allow-hosts host1,host2--allow-tools pattern1,pattern2--deny-tools pattern1,pattern2--allow-methods GET,POST--allow-path-prefixes /v1,/public--response-transform <module-path>--sse-max-sessions <n>--sse-session-ttl-ms <ms>
Template placeholders for --tool-name-template:
{operationId}{method}{path}{tag}
Response transform module example:
export default function transform({ operation, response }) {
return { ...response.body, transformedBy: operation.operationId };
}
Auth env vars
MCP_OPENAPI_API_KEYMCP_OPENAPI_BEARER_TOKENMCP_OPENAPI_BASIC_USERNAMEMCP_OPENAPI_BASIC_PASSWORDMCP_OPENAPI_OAUTH2_ACCESS_TOKENMCP_OPENAPI_OAUTH2_CLIENT_IDMCP_OPENAPI_OAUTH2_CLIENT_SECRETMCP_OPENAPI_<SCHEME_NAME>_TOKENMCP_OPENAPI_<SCHEME_NAME>_CLIENT_IDMCP_OPENAPI_<SCHEME_NAME>_CLIENT_SECRET
Build and verify
npm run check
npm run build
npm test
npm run smoke
Quick Setup
Installation guide for this server
Install Package (if required)
npx @modelcontextprotocol/server-mcp-openapi
Cursor configuration (mcp.json)
{
"mcpServers": {
"haasonsaas-mcp-openapi": {
"command": "npx",
"args": [
"haasonsaas-mcp-openapi"
]
}
}
}
Author Servers
Other servers by haasonsaas