Generate from an OpenAPI spec
OpenAPI is mcpgen’s highest-fidelity input. Each operation becomes one MCP tool, with parameters, request bodies, auth, and (when present) response schemas carried straight into the IR.
Supported
- OpenAPI 3.0 and 3.1, JSON or YAML.
- Local file path or — in the web UI — pasted text or an
http(s)URL the server fetches. $refs are dereferenced (via@readme/openapi-parser) before parsing.
Generate
npx mcpgenx generate ./openapi.yaml --out ./my-serverInspect first if you want to see the tool set:
npx mcpgenx inspect ./openapi.yamlHow operations map to tools
| OpenAPI | IR / generated tool |
|---|---|
operationId | sanitized into the MCP tool name ([A-Za-z0-9_-], deduped) |
summary / description | the tool description shown to the agent |
| path / query / header / cookie params | tool input fields with matching location |
requestBody | body input field(s), Zod-validated |
responses content schema | the tool’s outputSchema (used to mock the upstream during verify) |
security + securitySchemes | the server’s auth wiring (see Adding auth) |
servers[].url | default MCPGEN_API_BASE_URL |
No operationId? mcpgen derives a stable name from the method and path (e.g.
GET /pets/{petId} → getPetsPetId) and guarantees uniqueness.
Tips
- Base URL — if the spec has no
servers, setMCPGEN_API_BASE_URLin the generated.envbefore running. - Large specs — hundreds of operations generate fine; use
inspectto sanity check the tool count first. - Response schemas help verification — specs that describe responses get better mocked-upstream smoke tests, since mcpgen can sample realistic results.
Next
Last updated on