Skip to Content
GuidesFrom an OpenAPI spec

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-server

Inspect first if you want to see the tool set:

npx mcpgenx inspect ./openapi.yaml

How operations map to tools

OpenAPIIR / generated tool
operationIdsanitized into the MCP tool name ([A-Za-z0-9_-], deduped)
summary / descriptionthe tool description shown to the agent
path / query / header / cookie paramstool input fields with matching location
requestBodybody input field(s), Zod-validated
responses content schemathe tool’s outputSchema (used to mock the upstream during verify)
security + securitySchemesthe server’s auth wiring (see Adding auth)
servers[].urldefault 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, set MCPGEN_API_BASE_URL in the generated .env before running.
  • Large specs — hundreds of operations generate fine; use inspect to 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