OpenAPI Contract MCP
Provides tools for checking requests against a live OpenAPI contract, including finding endpoints by docs anchor or path, reading request and response schemas, and diffing request payloads against the schema to identify missing, unknown, or invalid fields.
Click on "Deploy 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., "@OpenAPI Contract MCPdiff my POST /pet request body against the Petstore contract"
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.
openapi-contract-mcp
An MCP server that lets a coding agent check requests against a live OpenAPI contract instead of guessing.
Five read-only tools: find an endpoint by docs anchor or path, read what it accepts and returns, and diff a real request body against the schema. Tested with unit tests, protocol-level tests, and agent-level evals that measure whether a model actually picks the right tool.
Why
On a multi-tenant CRM I work on, a large share of "frontend bugs" turned out to be contract bugs, and the arguments about them went in circles because both sides reasoned from memory. Two things kept wasting time:
The docs anchor is not the path. A colleague links
#/accounts/change-email, you search the code forchange-emailand find nothing, because the operationId ischange-emailand the path is/auth/set_email/.Copying fields from a GET response into a PUT body.
idandcreated_atcome back from the server but must not be sent;firstNamevsfirst_namegets silently dropped by the backend.
The workflow started as a Claude Code skill I use on that project, with a small Python script. This server is the same idea as a proper tool any MCP client can use, with the answers computed rather than eyeballed.
Related MCP server: OpenAPI MCP Server
Tools
Tool | Use it when |
| Someone names an endpoint by docs anchor, operationId, path fragment or tag. Matches operationId first. |
| Writing a request: parameters (path, query, header) and body, |
| Reading a response, per status code. |
| A request fails with 400 or a field is "ignored". Lists missing required fields, unknown fields (with the closest valid name), wrong types, enum violations, |
| Checking which schema version is loaded; |
Example, against the public Petstore schema:
// diff_payload { method: "POST", path: "/pet", payload: { "name": "Rex", "photoUrl": "x", "status": "sleeping" } }
{
"operation": "POST /pet",
"matchesContract": false,
"issues": [
{ "path": "$.photoUrls", "kind": "missing", "message": "is required but missing" },
{ "path": "$.photoUrl", "kind": "unknown", "message": "is not in the schema, did you mean \"photoUrls\"?" },
{ "path": "$.status", "kind": "enum", "message": "is \"sleeping\", allowed: \"available\", \"pending\", \"sold\"" }
]
}A wrong path returns an error the model can recover from, not a dead end:
No operation DELETE /pets in the schema. Did you mean:
- DELETE /pet/{petId}
- ...Setup
Requires Node 20+. The schema must be OpenAPI 3.x as JSON, from a URL or a local file.
git clone https://github.com/Arag0rn/openapi-contract-mcp && cd openapi-contract-mcp
npm ci && npm run buildClaude Code
claude mcp add openapi-contract -- node /absolute/path/to/openapi-contract-mcp/dist/index.js https://petstore3.swagger.io/api/v3/openapi.jsonCursor / any client with a JSON config
{
"mcpServers": {
"openapi-contract": {
"command": "node",
"args": ["/absolute/path/to/openapi-contract-mcp/dist/index.js", "https://your-api/schema/?format=json"]
}
}
}Setting | Default | |
first CLI argument or | Schema URL or file path | |
|
| How long a downloaded schema is reused |
Design decisions
Read-only by construction. The only network request the server makes is a GET for the schema itself, with a 15 s timeout. No tool calls the API the schema describes. Every tool carries
readOnlyHint: true, destructiveHint: false, and the server sendsinstructionson connect that say so.Short cache, explicit refresh. A stale schema looks authoritative, which makes it worse than none. Concurrent tool calls share one download.
Errors the model can act on. Misses return
isError: truewith suggestions: same path with other methods, then operations with the requested method, singular and plural path forms tried.Context budget. Output is capped at 20 000 characters with a hint on how to narrow the request.
diff_payloadreturns only the problems, not the schema.Logic separate from protocol.
spec.ts,operations.tsanddiff.tsknow nothing about MCP and are tested directly;server.tsonly wires them to tools.Not a full JSON Schema validator.
diff_payloadcovers what breaks requests in practice.allOfis merged,oneOf/anyOfpass if any variant matches (otherwise the closest variant is reported). Formats,min/max, patterns and remote$refs are not checked. Swagger 2.0 and YAML are not supported.
Tests
npm test # 36 unit and protocol tests (vitest)
npm run smoke # starts dist/index.js over stdio and calls every tool against a real schematest/server.test.ts talks to the server through the MCP protocol in memory, so it checks what an agent
actually sees: tool list, annotations, argument validation, recoverable errors.
Evals
Unit tests show the code is right. They do not show that a model picks the right tool, because that depends
on tool names, descriptions and server instructions. evals/ measures exactly that.
Nine scenarios in
evals/cases.ts, each a question a developer would ask: resolving a docs anchor, debugging a 400, aoneOfpayload, a wrong path, a required header, refreshing after a deploy, and a request to delete a user (guardrail).Each run starts Claude Code headless with only this server: built-in tools disabled, user settings, CLAUDE.md and other MCP servers ignored, no hints in the prompt.
Each scenario is graded on the trajectory (the expected tools called in order, with the expected arguments) and the answer (required facts present, forbidden claims absent).
npm run eval -- --model haiku --repeat 3 # uses the logged-in Claude Code account, no API keyResults with Claude Haiku 4.5:
Passed | Trajectory | Answer | |
First run | 6/9 (67%) | 78% | 89% |
After changing descriptions and adding server instructions, 3 runs per case | 26/27 (96%) | 96% | 96% |
What the evals changed:
Asked to debug a 400 with a concrete payload, the agent read the schema and compared by hand instead of calling
diff_payload. The answers were right on small bodies, but that does not scale. Fix: routing sentences in both descriptions ("if you already have a concrete payload, calldiff_payload").Asked to delete a user, the agent offered to "construct and send the DELETE", although the server cannot reach the API and the schema has no such operation. Fix: server
instructionsstating the tools are read-only and telling the agent to check whether an operation is documented at all.The agent quoted
/users/{id}for/users/{id}/. For Django-style backends that is a redirect or a 404. Fix:get_request_schemaadds a note when a path ends with a slash. The eval stays strict on this.
The remaining failure is real: in one of three runs the agent refused the delete correctly but did not check
the schema and mentioned a DELETE /users/{id} that does not exist.
Two grader bugs were fixed along the way, both where the agent had behaved correctly and a regex did not recognise the wording. Regex graders are brittle for meaning; an LLM judge would be the next step. The rule I followed: a grader may only be loosened when the transcript shows the agent was right.
Raw transcripts of every run are in evals/results/.
Project layout
src/
spec.ts loading, caching, $ref resolution
operations.ts endpoint search, request and response contracts, suggestions
diff.ts payload vs schema
server.ts MCP tools and server instructions
index.ts stdio entry point
test/ vitest, fixture schema with the tricky cases
evals/ agent-level scenarios and runner
scripts/smoke.ts stdio smoke testLicense
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Point Gecko at an OpenAPI spec; get first-call-correct, auth-hidden agent tools.
Detect breaking changes, generate changelogs, diff, and validate OpenAPI specs.
Deterministic validation for AI-generated artifacts: JSON Schema, OpenAPI response, SQL syntax.
Turn any task into the right API calls: discover, evaluate, and integrate public APIs.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to load, parse, and query OpenAPI/Swagger documentation from URLs with intelligent search across endpoints, schemas, and authentication methods. Provides 10 specialized tools for comprehensive API exploration including path details, operation lookups, and multi-criteria search capabilities.4-
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to explore and query OpenAPI specifications, allowing natural language interaction with API endpoints, parameters, request bodies, and response schemas from any OpenAPI 3.x spec.10 npmMIT
- FlicenseNot gradedqualityDmaintenanceTurns any OpenAPI/Swagger spec into queryable tools for LLMs, enabling endpoint search, detail retrieval, and schema exploration.1-
- AlicenseBqualityDmaintenanceEnables natural language exploration of OpenAPI/Swagger specs, allowing users to register APIs, browse endpoints, describe schemas, and detect breaking changes through conversational queries.9233 npmMIT