mcp-use/mcp-use/openapi-to-mcp
Claude Code and agent skill by mcp-use/mcp-use
- community
Checking that the SKILL.md file is still in the repository.
Build and deploy an MCP server from an OpenAPI / Swagger spec using the mcp-use TypeScript SDK. Use this skill whenever the user wants to "turn this OpenAPI spec into an MCP server", "make this API usable from Claude/ChatGPT", "wrap this Swagger doc as MCP tools", "expose this REST API to an LLM", "generate MCP tools from a spec", or pastes/attaches an `openapi.yaml`, `openapi.json`, or `swagger.json` and asks for a Claude-compatible version. Trigger even if the user doesn't say "MCP" — if they describe an existing HTTP API (REST endpoints, an internal service, a third-party API they have a key for) and want an LLM to call it, this is the right skill. Covers spec ingestion (file path, URL, or pasted), operation-to-tool mapping, auth wiring (apiKey, bearer, basic, OAuth bearer), scaffolding with `create-mcp-use-app`, tool generation with proper zod schemas, live testing in the mcp-use inspector, and deploying to Manufact / mcp-use cloud.
Install
npx vskill@latest install mcp-use/mcp-use/openapi-to-mcpSKILL.md
The same SKILL.md was published earlier as mcp-use/mcp-use/openapi-to-mcp.
Build an MCP server from an OpenAPI spec
Turn an existing REST API — described by an OpenAPI 3.x or Swagger 2.0 document — into an MCP server. Each operation in the spec becomes one MCP tool the LLM can call. The server runs locally for testing and ships to Manufact / mcp-use cloud with one command.
This skill is the end-to-end recipe: scope → ingest spec → map operations → scaffold → generate tools → wire auth → test → deploy.
Core philosophy: the spec is the contract
The OpenAPI document is the source of truth. Tool names, descriptions, parameter shapes, and auth requirements all come from the spec — they should not be invented. This matters because:
- The LLM trusts descriptions. If the spec says
summary: "Get current weather for a city", that's exactly what the LLM will read when deciding whether to call the tool. Hand-rolled summaries drift; spec-derived summaries stay in sync if the API changes. - Zod schemas mirror OpenAPI schemas. Every parameter — path, query, body — becomes a field in one zod object. Required/optional, enums, min/max, and descriptions all carry over. The LLM uses the schema to figure out what to ask the user for.
- Auth lives outside the spec. OpenAPI declares the auth scheme but never the secret. Secrets come from env vars; the spec tells you which env vars to require.
When in doubt, prefer mechanical fidelity to the spec over creativity. The LLM is doing the creative part — talking to the user — and only needs a faithful, well-typed handle on the API.
Process
1. Scope the request (use AskUserQuestion)
Before writing code, lock five things via the AskUserQuestion tool. All five are about the API and what to build — deployment is a separate question we ask later in step 10, when the user can actually evaluate it against a working server.
- Spec source: a file path in the workspace, a URL (e.g.,
https://api.example.com/openapi.json), or pasted into chat. If pasted, save it toopenapi.yamloropenapi.jsonfirst. - Server base URL: take it from
servers[0].urlin the spec if present; otherwise ask. Multipleserversentries are common (prod / staging) — confirm which one. - Auth scheme: read
components.securitySchemes. If multiple, ask which to use. If the API needs an API key or token, ask which env var should hold it (API_KEY,OPENAI_API_KEY, etc.). Don't ask for the secret itself — never put it in the conversation or commit it. - Operation filter: large specs (Stripe, GitHub) have hundreds of endpoints. Ask whether to expose all operations, a tag (
pets,users), or a hand-picked list. Default to "all" for specs under ~30 operations; ask above that. Seereferences/mapping-rules.mdfor filtering patterns. - Widgets: ask whether any operations should render a widget in the chat (a React component shown inline next to the LLM's reply), or whether this is a pure tools-only server. The default for an OpenAPI wrapper is tools-only — the LLM reads JSON and talks. Pick widgets only when the user wants a richer UI for specific responses (a map for a geocoding endpoint, a chart for a metrics endpoint, a card list for a search result). This answer drives the scaffold template in step 3: tools-only →
--template blank, any widgets →--template mcp-apps(which ships theresources/widget infrastructure pre-wired). If the user wants widgets on most operations, themcp-apps-builderskill is usually a better fit than this one — flag that and confirm before proceeding.
Don't skip this step. Generating 200 tools the user doesn't need pollutes the LLM's tool list and slows it down.
2. Acquire and dereference the spec
Get the spec into a single dereferenced JSON object on disk. Dereferencing inlines $refs so downstream code never has to chase pointers.
For URL specs, swagger-parser accepts the URL directly. For pasted YAML, write it to openapi.yaml first, then dereference. If the spec is Swagger 2.0, run it through swagger2openapi first (npx swagger2openapi --outfile openapi.yaml swagger.yaml).
Sanity-check the dereferenced file: open it, search for "$ref" — there should be none. If there are, the spec has circular refs and swagger-parser keeps them as-is; treat those refs as opaque object types in zod.
3. Scaffold with create-mcp-use-app
Pick the template based on the widget answer from step 1:
Let the scaffold install dependencies and git init — both are useful (npm install runs mcp-use generate-types postinstall, and a git repo is required by npm run deploy later). The skill installs companion coding-agent skills by default too; that's fine.
Verify the template catalog with npx create-mcp-use-app@latest --list-templates if it's been a while — the available set is blank, mcp-server, mcp-apps as of this writing. Use blank for OpenAPI-first servers; mcp-server includes sample tools you'd rip out.
After scaffolding, add the two extra deps the OpenAPI flow needs:
What you get from blank (mcp-apps is a superset with resources/ + widget infrastructure):
index.tsat the root with a configuredMCPServerinstance —name,title,version,description. Commented-out examples for tools, resources, and prompts. Listens onprocess.env.PORT(default 3000).package.jsonwith scripts wired to themcp-useCLI:dev(hot reload + inspector),build,start,deploy.tsx,zod, andtypescriptare already in dev/regular deps; don't reinstall them.tsconfig.jsonpre-configured for ESM ("type": "module").public/with a favicon and an SVG icon — served as static assets.- A
.gitdirectory and an initial commit.
The scaffold reserves the env var MCP_URL for the MCP server's own public base URL (used for widget asset URLs and similar). That is not the upstream API's base URL — name your upstream var BASE_URL (or API_BASE_URL if you want to be explicit) to avoid stepping on it.
4. Plan project structure
Keep the tree shallow and predictable. The point is that someone reading the project for the first time can find the OpenAPI client, the tool wiring, and the auth in three obvious files.
For tiny specs (<10 operations) you can inline client.ts, auth.ts, and operations.ts into index.ts. For anything bigger, split — the LLM works better when each file has one job.
5. Map operations to tools
For every operation in the spec, you produce one server.tool({...}, handler) call. The mapping is mechanical:
| OpenAPI field | MCP tool field | |
|---|---|---|
operationId (preferred) or ${method}_${path} sluggified | tool name (snake_case) | |
summary + description | tool description | |
parameters (path + query) + requestBody.content."application/json".schema | merged zod object → tool schema | |
responses.200.content."application/json".schema | optional zod object → tool outputSchema | |
security (or root-level fallback) | which auth headers the handler attaches |
Read references/mapping-rules.md for the full rules — including how to name tools when operationId is missing, how to handle oneOf / anyOf / nullable types in zod, how to flatten multi-content request bodies, and how to deal with the response-shape gotchas (binary downloads, streaming, paginated lists).
6. Generate the zod schemas
OpenAPI types map to zod as follows. The full converter lives in src/schema.ts — see references/code-templates.md for the implementation. Key choices:
type: stringwithenum→z.enum([...]). Use the OpenAPIdescriptionas the.describe()arg so the LLM sees it.type: integer/type: number→z.number().int()/z.number(). Carry overminimum,maximum,multipleOf.type: array→z.array(<itemType>). IfminItems/maxItemsexist, chain.min()/.max().type: object→z.object({...}). Required props are non-optional; others wrap in.optional().oneOf/anyOf→z.union([...]).allOfwith object-only members → merge into onez.object.nullable: true(OpenAPI 3.0) ortype: ["string", "null"](3.1) →.nullable().
Always call .describe(openapi.description ?? openapi.summary ?? "") on every field so the LLM gets human-readable hints when filling args.
7. Build the HTTP client and auth layer
src/client.ts exposes one function: callOperation(operationId, args) → Promise<unknown>. Internally it:
- Looks up the operation in the dereferenced spec.
- Substitutes path params into the URL template (
/users/{id}+{id: 42}→/users/42). - Appends query params as
?key=value. - Adds auth headers from
src/auth.ts. - Serializes the request body as JSON (or
application/x-www-form-urlencodedif the spec says so). - Sends the request; throws on non-2xx with the server's error body included.
- Returns parsed JSON (or text, for non-JSON responses).
src/auth.ts reads from process.env based on the spec's securitySchemes. See references/auth.md for the four common schemes and how each becomes a header. Required env vars belong in .env.example — that's the contract for whoever runs the server later.
8. Wire tools in index.ts
The registration loop is small. Pseudocode:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/openapi-to-mcp/SKILL.md
Popularity
- Repository stars
- 10,677
- Repository forks
- 1,475
- 7-day trend score
- 46
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mcp-use/mcp-use/openapi-to-mcp)