Contracts and differs
A contract is a file that clients depend on, such as an OpenAPI document or an MCP tool catalog. When a pull request changes a contract in a breaking way, the check requires an entry that bumps the major version.
Declare a contract
Add contract to a surface. It names the file and the differ that compares two versions of it:
surfaces:
app:
paths: [app/views/**, app/javascript/**, config/routes.rb]
api:
title: API changes
paths: [app/controllers/api/**]
contract: { file: openapi.json, differ: openapi }
mcp:
title: MCP tools
contract: { file: contract/mcp_tools.json, differ: mcp_tools }
| Key | Meaning |
|---|---|
file |
The contract file, relative to the root. |
differ |
openapi, mcp_tools, or the constant name of a custom differ. |
The contract file belongs to its surface. A change to it needs an entry for that surface, even if paths does not list it.
How the check uses a differ
The check reads the contract file at the base and at HEAD. It runs the differ only when the file exists on both sides and its content differs. A contract file that the diff deletes is one breaking finding, contract file removed. A contract file that the diff adds is not compared.
The check prints every finding as a note. If any finding is breaking, the diff must add an entry that includes the surface and bumps the major version:
mcp: BREAKING delete_widget: tool removed
mcp: BREAKING list_widgets: input.account_id is now required
mcp: change get_widget: tool added
mcp: change list_widgets: description changed
mcp: change list_widgets: output.next_page added
✗ breaking: mcp has 2 breaking change(s); add an entry with surfaces [mcp] that bumps the major version, or undo the change
An entry like this one satisfies the check, because bump: major sets the level:
title: Remove the delete_widget tool
kind: changed
surfaces: [mcp]
bump: major
With the default schema, kind: removed also bumps the major version. See Versioning.
The openapi differ
The openapi differ runs oasdiff with oasdiff breaking base.json head.json --format json. Install oasdiff in CI. Shipnotes looks for it in this order:
- The
--oasdiff PATHoption ofshipnotes check. - The
OASDIFFenvironment variable. - An executable called
oasdiffonPATH.
If it finds none, the check prints a note and skips the REST diff:
api: breaking-change diff skipped: oasdiff not found (install it, set OASDIFF or pass --oasdiff)
If oasdiff is set but cannot run, or exits with an error, the check stops with exit status 1.
Each oasdiff result becomes one finding:
- The subject is the operation and the path, for example
GET /widgets. - The finding is breaking when the oasdiff level is 3 or higher.
- The finding is labelled
[internal]when the operation hasx-internal: truein either version. An internal finding still counts as breaking.
The mcp_tools differ
The mcp_tools differ reads an MCP tools/list result: {"tools": [...]}, or a bare list of tools. Each tool needs a name. It compares tools by name.
| Change | Breaking |
|---|---|
| A tool is removed | yes |
| A tool is added | no |
A tool’s title, description or annotations change |
no |
For a tool in both versions, the differ compares inputSchema and outputSchema as JSON Schemas. It compares from the side of the caller. An input change breaks when a call that was valid becomes invalid. An output change breaks when a field that the caller reads disappears or changes type.
| Change | inputSchema |
outputSchema |
|---|---|---|
type changes, including from no type to a type |
breaking | breaking |
| A property is removed | breaking | breaking |
| A property is added | not breaking; if it is also required, see the next row | not breaking |
A name is added to required |
breaking | not compared |
A name is removed from required |
not compared | breaking |
A value is removed from enum |
breaking | not compared |
A value is added to an existing enum |
not compared | breaking |
enum is added where there was none |
breaking | not compared |
Only other keywords change, such as description |
not breaking | not breaking |
The differ applies these rules to every nested property and to array items. The finding names the path, such as input.filters.status or output.widgets[]. An output with no declared type promised nothing, so adding an outputSchema to a tool that had none is not breaking. Each of its properties is an added finding.
The catalog must be valid JSON. The differ does not report an invalid file as a finding.
Custom differs
A differ is any Ruby object that responds to call(base, head, options):
baseandheadare the two versions of the contract file, as strings.optionsis a hash. It holds:oasdiff, the value of--oasdiffornil.- It returns an array of
Shipnotes::Findingvalues.
Shipnotes::Finding has four fields. Give all four:
| Field | Meaning |
|---|---|
subject |
What changed, for example a type or an operation. |
breaking |
true when the change breaks clients. |
internal |
true to label the finding [internal] in the output. It does not change breaking. |
message |
A short description of the change. |
Raise Shipnotes::Differs::Skipped when the differ cannot run in this environment. The check prints the message as a note and goes on. Raise Shipnotes::Error to stop the check with exit status 1.
List the file that defines the differ under require. Set differ to its constant name, with namespaces if any. Shipnotes loads the require files only when it needs a differ that is not built in.
Worked example: a GraphQL schema
Suppose the api surface serves GraphQL from schema.graphql. This differ reports a removed type as breaking and an added type as a change. It reads only lines that start with type.
# lib/acme/graphql_differ.rb
module Acme
module GraphqlDiffer
module_function
def call(base, head, _options)
removed = type_names(base) - type_names(head)
added = type_names(head) - type_names(base)
removed.map { |name| Shipnotes::Finding.new(subject: name, breaking: true, internal: false, message: "type removed") } +
added.map { |name| Shipnotes::Finding.new(subject: name, breaking: false, internal: false, message: "type added") }
end
def type_names(schema) = schema.scan(/^type (\w+)/).flatten
end
end
# .shipnotes.yml
surfaces:
app:
paths: [app/views/**, app/javascript/**, config/routes.rb]
api:
title: API changes
paths: [app/graphql/**]
contract: { file: schema.graphql, differ: Acme::GraphqlDiffer }
require: [lib/acme/graphql_differ.rb]
A branch replaces the Gadget type with a Sprocket type. Without an entry, the check fails:
$ shipnotes check main
api: BREAKING Gadget: type removed
api: change Sprocket: type added
✗ entry: this diff needs a changelog entry (surfaces: api); add one with `shipnotes new`
✗ breaking: api has 1 breaking change(s); add an entry with surfaces [api] that bumps the major version, or undo the change
Add an entry that bumps the major version and commit it:
shipnotes new --title "Replace Gadget with Sprocket" --kind removed --surfaces api
git add changelog
git commit -m "Changelog entry"
The check now passes:
$ shipnotes check main
api: BREAKING Gadget: type removed
api: change Sprocket: type added
✓ shipnotes check passed against main
If differ names a constant that does not exist, the check stops with exit status 1:
shipnotes: unknown differ Acme::GraphqlDifer; use openapi or mcp_tools, or a class loaded through `require`
If a require file is missing or raises while it loads, the check stops with exit status 1 and names the file and the error:
shipnotes: could not load lib/acme/graphql_differ.rb from `require`: NameError: uninitialized constant Acme::Schema
An MCP catalog that is not valid JSON, or a tool without a name, also stops the check with a message, such as the head MCP tool catalog is not valid JSON: ....