openapi2mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@openapi2mcpsearch for user creation endpoint and create a user named Alice"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
openapi2mcp
⚠️ Work in progress. This project is early and actively evolving — the API, generated output, and configuration may change without notice. Not production-ready. Expect rough edges; ideas and PRs welcome (see CONTRIBUTING.md).
openapi2mcp generates a standalone, Dockerizable MCP server that exposes a whole
REST API via just search and execute, following the
Code Mode pattern popularized by
Cloudflare. The model writes a little JavaScript; the server runs it safely. The
result: a fixed ~1–2k token footprint that never grows with your API.
your OpenAPI spec ──► openapi2mcp ──► a runnable MCP server (2 tools, ~1–2k tokens)The problem
Every endpoint you expose as a normal MCP tool fills the model's context window. For a large API this breaks entirely:
Approach | Tools | Tokens (200k context) |
Raw spec in prompt | — | ~2,000,000 (977%) |
Native MCP — full schemas | 2,500 | 1,170,000 (585% ❌) |
Native MCP — minimal schemas | 2,500 | 244,000 (122%) |
Code Mode — this project | 2 | ~1,200 (0.5% ✅) |
Code Mode inverts the model: instead of picking from thousands of fixed tools, the agent writes code that says what it wants, and the server executes it.
Related MCP server: OpenAPI MCP Server
Quickstart
git clone https://github.com/dspachos/openapi2mcp.git openapi2mcp && cd openapi2mcp
npm install
# Generate a server from the canonical Petstore spec (no creds needed)
npm run example
# Run it
cd generated/petstore-mcp && npm install && npm start # → http://localhost:8787/mcpConnect any MCP client:
{
"mcpServers": {
"petstore": { "type": "http", "url": "http://localhost:8787/mcp" }
}
}Then just ask your agent: "find the endpoints for managing orders, then list the
stored orders." It will search the spec, then execute the calls.
How it works
┌──────────┐ tools/call(search) ┌────────────────────────┐
│ │ ─────────────────────► │ Generated MCP server │
│ Agent │ tools/call(execute) │ ┌──────────────────┐ │
│ (LLM) │ ◄───────────────────── │ │ sandbox │ │
│ │ results only │ │ (isolated-vm) │ │
│ │ (the spec never │ │ • no fs / env │ │
│ │ reaches the agent) │ │ • no free fetch │ │
└──────────┘ │ └────────┬─────────┘ │
│ │ api.request │
│ ┌────────▼─────────┐ │
│ │ host process │ │
│ │ • injects auth │───► your API
│ │ • host allow- │ │
│ │ list (fetch) │ │
│ └──────────────────┘ │
└────────────────────────┘search({ code })— read-only JavaScript over the resolved OpenAPI spec (spec.paths). The agent discovers the endpoints it needs; the full spec never enters its context.execute({ code })— JavaScript that callsapi.request({ method, path, query, body })to hit the API, compose calls, paginate, filter results, and return just what's needed.
Security model
This tool executes model-authored code at runtime, so the sandbox is the whole
game. Each generated server runs untrusted code in a hardened
isolated-vm V8 isolate — not Node's
vm module, which is not a security boundary.
Threat | Mitigation |
Secret exfiltration ( | No |
Data exfiltration ( | No |
Token leakage | The API secret is injected by the host and is never visible to sandboxed code |
DoS ( | Per-call memory limit + wall-clock timeout; a fresh isolate per call |
Where AI fits
At generation time only — zero LLM cost per request. If you provide an
OpenAI-compatible endpoint, the generator analyzes your spec and writes tailored
search/execute descriptions, grounded examples using real API paths, and
notes on response envelopes / pagination / auth quirks. If unavailable, it falls
back to deterministic descriptions. Disable with --no-ai.
Works with any OpenAI-compatible provider — OpenAI, Azure, OpenRouter, LiteLLM, Ollama, a local gateway, etc.:
export OPENAI_API_KEY=sk-...
export OPENAI_BASE_URL=https://api.openai.com/v1 # or your gatewayOAuth 2.1 — per-user, downscoped access
For multi-user deployments, generate with --oauth and the server becomes its own
OAuth 2.1 authorization server (the model Cloudflare uses):
openapi2mcp generate --spec ... --oauth --auth bearer --auth-env API_TOKENEach end-user then authorizes via a browser consent flow instead of sharing one baked-in token:
The MCP client hits
/mcpunauthenticated →401+ Protected Resource Metadata.It discovers
/.well-known/oauth-authorization-server, registers a client (/register— Dynamic Client Registration), and runs authorization-code + PKCE (S256).The consent page asks the user for their upstream API token and which scopes to grant. Scopes are derived from the spec automatically —
<product>:<read|write>, e.g.orders:read,billing:write.The server issues a short-lived RS256 JWT access token + refresh token, storing the user's upstream token server-side (it never enters the sandbox).
On every
executethe granted scopes are enforced — the agent cannot call operations the user didn't approve.
Endpoints: /.well-known/oauth-protected-resource,
/.well-known/oauth-authorization-server (RFC 8414), /authorize, /token,
/register, /revoke, /jwks.
⚠️ Security notes. Access tokens are signed by a per-process key (restart invalidates them; refresh tokens survive). The token store is in-memory / single-instance — swap in Redis/KV/Postgres for multi-instance. The paste-token consent model trusts the resource owner to paste into a flow they initiated. This is a focused MCP subset — security review recommended before production.
Usage
npx tsx src/index.ts generate \
--spec https://api.example.com/openapi.json \
--name example \
--base-url https://api.example.com \
--auth bearer --auth-env EXAMPLE_API_TOKEN \
--out ./generated/example-mcpFlag | Purpose |
| OpenAPI spec (required) |
| server / output name (required) |
| output dir (default |
| target API base URL (else spec |
| env var to read the base URL at runtime (preferred) |
| auth scheme (default: auto-detect from |
| env var holding the target API secret (default |
| header for apikey auth (default |
| enable OAuth 2.1 authorization-server mode (per-user, downscoped tokens) |
| skip AI augmentation |
| LLM base (default |
| LLM key (default |
| model id (default: auto-detect via |
The generated server
<name>-mcp/
├── spec.json # resolved, trimmed OpenAPI spec (for the search tool)
├── meta.json # auth, base URL, AI-generated descriptions & examples
├── package.json
├── Dockerfile
└── src/
├── index.ts # MCP server + streamable HTTP transport
├── sandbox.ts # isolated-vm runner (the security boundary)
├── search.ts # search tool (read-only over the spec)
└── execute.ts # execute tool (locked-down api.request)cd generated/example-mcp
cp .env.example .env # set base URL + secret + PORT
npm install && npm start # → http://0.0.0.0:8787/mcpDocker:
docker build -t example-mcp .
docker run -p 8787:8787 \
-e BASE_URL=https://api.example.com \
-e API_TOKEN=secret \
example-mcpThe runtime is fixed code — only spec.json and meta.json vary per API. It
runs on plain Node + Docker (no Cloudflare Workers dependency; isolated-vm
replaces their Dynamic Worker Loader).
Project structure
openapi2mcp/
├── src/ # the generator
│ ├── spec/ # fetch · $ref resolver · spec trimmer
│ ├── analyze.ts # detect base URL + auth scheme
│ ├── ai.ts # optional AI augmentation (OpenAI-compatible)
│ ├── emit.ts # scaffold from template/ + inject spec.json/meta.json
│ └── generator.ts # orchestration
└── template/ # the runtime, copied verbatim into every generated serverHow it compares
Approach | Token cost | Scales to huge APIs | Sandbox needed | Agent-side changes |
Native MCP (one tool / endpoint) | high (grows with API) | ❌ | no | none |
CLI-per-server (progressive disclosure) | low | ✅ | shell (larger surface) | needs a shell |
Dynamic tool search | medium | ⚠️ | no | needs a search fn |
openapi2mcp (Code Mode) | ~1–2k fixed | ✅ | isolated-vm | none |
Contributing
Contributions welcome — see CONTRIBUTING.md for setup, where things live, and PR conventions.
Roadmap
OAuth 2.1 per-user, downscoped authorization-server mode ✅
Durable / multi-instance token store (Redis, KV, Postgres) + persisted signing key
B1 path: delegated upstream OAuth (GitHub/Google-style refresh-token storage)
Streaming / chunked responses for large payloads
Heuristic response-envelope + pagination auto-handling
Published as an
npx-able npm packageTests across more OpenAPI edge cases (Swagger 2.0,
allOf/oneOf, webhooks)
Acknowledgements
Inspired by Cloudflare's Code Mode and Anthropic's Code Execution with MCP. Security is built on isolated-vm by Karl Miller. MCP via the official Model Context Protocol SDK.
License
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityDmaintenanceAutomatically converts Swagger/OpenAPI specifications into MCP servers, enabling AI agents to interact with any REST API through natural language by exposing endpoints as AI-friendly tools.Last updated3
- Alicense-qualityCmaintenanceA generic MCP server that dynamically converts OpenAPI-defined REST APIs into tools for LLMs like Claude. It supports multiple authentication methods and transport protocols, enabling seamless interaction with any OpenAPI-compliant API.Last updated28MIT
- AlicenseAqualityDmaintenanceA generic MCP server that dynamically exposes any OpenAPI-documented REST API to LLMs by auto-discovering endpoints. It provides tools for exploring API capabilities and making authenticated requests directly through natural language interfaces.Last updated22MIT
- AlicenseCqualityCmaintenanceMCP server that turns OpenAPI specs into tools and calls APILast updated1115MIT
Related MCP Connectors
MCP server exposing the Backtest360 engine API as tools for AI agents.
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
Markdown-first MCP server for Notion API with 8 composite tools and 39 actions.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/dspachos/openapi2mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server