Agents
How a coding agent uses contractdiff: explain one operation resolved and size-capped instead of reading the whole spec, lint a contract or an MCP tool list for agent-readiness, and drive every command through --json, --schema and the --mcp server.
A coding agent that calls an API from memory gets parameter names and required fields wrong. A
contract has the answer, but a whole OpenAPI document rarely fits in a context window, and its
$refs point everywhere. contractdiff gives an agent the piece it needs, and tells it how good the
contract is for its purposes.
One operation, resolved: explain
contractdiff explain <operation> --json prints one operation, message or tool with every $ref
resolved, as one JSON value:
{"ok":true,"data":{"id":"getPet","format":"openapi","source":"#/paths/~1pets~1{id}/get","method":"GET","path":"/pets/{id}","payloads":[{"name":"param:path:id","direction":"request","required":true,"schema":{"type":"string"}},{"name":"response:200:application/json","direction":"response","required":true,"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"tag":{"type":"string"}}}}]},"meta":{"provenance":{"input":{"source":"flag","location":"--input"}}}}--listprints the ids, one per line, so an agent can find the one it needs first.--max-bytes <n>cuts the deepest schemas first until the JSON fits, and lists the cuts undertruncated. When even an emptied operation does not fit, the error says the smallest budget that would, as afix::
error: "getPet" does not fit in 150 bytes even with every schema emptied (364 bytes)
fix: pass --max-bytes 364 or more
{"error":{"kind":"usage","code":2,"message":"\"getPet\" does not fit in 150 bytes even with every schema emptied (364 bytes)"}}Without --json, explain prints the same thing as Markdown, a heading per payload with its schema
in a fenced block, ready to paste into a prompt. The markdown generator writes that page for every
operation, plus an llms.txt; see Code generation.
Is this contract usable as tools?
The agent-ready ruleset checks what an agent needs to pick and call an operation: an id and a
description on each, descriptions on parameters and properties, descriptions long enough and
distinct enough to choose between, and examples that match. It reads MCP tool lists too:
{
"tools": [
{
"name": "search_pets",
"description": "Find pets by name",
"inputSchema": {
"type": "object",
"required": ["query"],
"properties": {
"query": { "type": "string" },
"limit": { "type": "integer" }
}
}
}
]
}tools.json
warn property-description #/tools/0 arguments/properties/limit limit: `description` is missing
fix: add a `description` saying what the property holds, with its unit if it has one
warn property-description #/tools/0 arguments/properties/query query: `description` is missing
fix: add a `description` saying what the property holds, with its unit if it has one
0 error(s), 2 warning(s). Checked 7 rule(s) on 1 input(s), 8 node(s); not carried: none.
agent-ready: 75% (6 of 8 checks passed)A committed tools.json snapshot also makes a tool's schema change a reviewable diff; see
Input formats.
Driving contractdiff from an agent
contractdiff is declared once on burgee, so every command has the same machine surface:
--jsonprints one envelope on stdout:{ "ok": true, "data": … }, or"ok": falsewith the error'skind, exitcodeand a message that ends in afix:.--schemaprints every command, option, default and exit code as JSON, in one call.contractdiff --mcpserves the commands as MCP tools.- Exit codes are the contract:
0ok,1a finding,2a usage error,3a config that did not load. An agent branches on them without parsing text. - Every finding names its fix, the same record in text,
--jsonand SARIF.
The package's AGENTS.md is the guide for an agent writing a plugin; Write a plugin
covers the same ground.
CI gate
A GitHub Actions job that fails a pull request on a breaking contract change, a lint rule at error or generated code that is out of date, and uploads the findings as SARIF to code scanning.
Property tests from the contract
contractdiff props draws values from each payload's schema and checks four properties with no server: the validator agrees with the schema, values survive JSON, normalise is idempotent, and what diff calls compatible really is; replayable by seed, with fast-check arbitraries for your own tests.