Tools

openapi_query & openapi_diff

Query OpenAPI specs in a read-only QuickJS sandbox and compare two specs for breaking changes.

OpenAPI MCP exposes two read-only MCP tools: openapi_query for inspecting resolved specs and openapi_diff for comparing two spec versions.

openapi_query

Runs a synchronous JavaScript expression, arrow function, or function body with return inside an isolated QuickJS WASM sandbox. Inside the sandbox, you have read-only access to the frozen, $ref-resolved spec object and built-in helpers.

Common Query Examples

// 1. Inspect an endpoint's merged parameters, request body, responses, and effective security
helpers.op('POST', '/orders')

// 2. Generate a deterministic JSON sample payload for a specific status code
helpers.example('POST', '/orders', '422')

// 3. Find every endpoint that references a shared schema
helpers.schemaRefs('ProblemDetails')

// 4. Run custom filtering directly on the resolved spec
Object.keys(spec.paths).filter((p) => p.startsWith('/v2/'))

How the Built-in Helpers Work

  • helpers.op(method, path): Merges path-level and operation-level parameters and resolves effective security requirements for that operation.
  • helpers.example(method, path, status?): Builds a deterministic sample JSON payload by walking schema fields in priority order: example → const → default → enum → format → type.
  • helpers.schemaRefs(schemaName): Returns all endpoints that reference a given component schema.

Parameters

ParameterTypeDefaultDescription
codestring (required)—Synchronous JS query (up to 16,384 characters).
rootstringserver rootWorkspace root directory.
spec_pathstringdefault specRelative path to a specific spec file (useful in monorepos).
max_bytesinteger16384Maximum UTF-8 output size (up to 1 MiB).

Sandbox Limits & Budgets

  • Timeouts: 2,000 ms setup cap for parsing and freezing the spec, plus a 150 ms execution timeout per query.
  • Memory & stack: Capped at 64 MiB memory and 512 KiB stack. Async functions and Promises are rejected.
  • Response budget: Output defaults to 16 KiB UTF-8. If a query returns too much data, the tool returns RESPONSE_BUDGET_EXCEEDED along with available keys and hints to narrow the expression.

openapi_diff

Compares two local OpenAPI specs (base_spec_path vs. target_spec_path) and separates changes into breaking and nonBreaking.

{
  "base_spec_path": "openapi.yml",
  "target_spec_path": "docs/openapi-v2.yml"
}

How Changes Are Classified

CategoryExamples
BreakingRemoved endpoints, removed response status codes or media types, new required parameters or request fields, optional-to-required request fields, required-to-optional response fields, schema type changes, removed request enum values, added response enum values.
Non-breakingAdded endpoints, newly deprecated endpoints, new optional parameters or request fields, added response status codes or fields, new request media types.