Evolving capability contracts
Every capability an engine publishes is a contract: its ID, input and output schemas, access kind, timeout, and annotations. Agents, CLI scripts, and applications depend on it. This guide shows how to change that contract without surprising them.
Version the engine
Section titled “Version the engine”Give the engine a Semantic Versioning version and bump it by the strongest
change in a release:
| Change | Engine version |
|---|---|
| Remove or rename a capability; add a required input property; narrow an input; widen or drop part of an output; make access stricter | Major |
| Add a capability or an optional input property; widen an input; add an output property; deprecate a capability | Minor, with a notice for an added output property |
| Fix a handler without changing the contract | Patch |
Changing what an existing field means is breaking even when no schema changes; tooling cannot see it.
Add output properties carefully
Section titled “Add output properties carefully”Zod closes every output object with additionalProperties: false. MCP clients
built on the official SDK, including connectMcpClient, validate each result
against the output schema they cached from tools/list, and the stateless HTTP
adapter never tells them the list changed. After a deploy that adds an output
property, those clients reject every call to the tool until they list tools
again.
contract diff therefore reports the addition as potentially breaking
(CLOSED_OUTPUT_PROPERTY_ADDED). Ship it in a minor version with a changelog
notice, and ask MCP consumers to reconnect or list tools again after the
deploy. Direct callers that ignore unknown properties are unaffected, and an
output object that already allowed additional properties can gain properties
freely.
Deprecate before removing
Section titled “Deprecate before removing”Mark the capability with a notice. Its behavior does not change.
export const classifyTicket = defineCapability({ description: "Classify a support ticket.", input, output, access: "authenticated", deprecated: { reason: "Superseded by the triage flow.", since: "2.0.0", replacement: "support.triage-ticket", }, run,});Consumers see the notice everywhere the contract is published:
engine.list(),engine.describe(), and CLIlistanddescribeincludedeprecated;- MCP clients see a description that starts with
Deprecated since 2.0.0: Superseded by the triage flow.and aReplacement:line, and the same object under_meta["dev.invokta/deprecated"]; and - the engine logger receives one
Deprecated capability invoked.warning the first time each deprecated capability is called, so you can tell whether a consumer still depends on it.
reason is required and limited to 1,024 characters, since to 64, and
replacement to 256. Invalid notices fail createEngine.
Rename without breaking
Section titled “Rename without breaking”-
Register the same definition under the new ID.
const engine = createEngine({name: "support-engine",version: "2.1.0",capabilities: {"support.triage-ticket": triageTicket,"support.classify-ticket": {...triageTicket,deprecated: {reason: "Renamed to support.triage-ticket.",since: "2.1.0",replacement: "support.triage-ticket",},},},}); -
Release a minor version. Both IDs work, and every channel shows the deprecation on the old one.
-
Remove the old ID in the next major version of the engine.
Gate releases in CI
Section titled “Gate releases in CI”@invokta/tooling records the public contract of a built engine and compares
it with the accepted baseline:
yarn add --dev @invokta/toolingyarn buildnpx invokta contract snapshot ./dist/engine.js --output contract.jsongit add contract.jsonIn CI, snapshot the current build and diff it against the committed baseline:
npx invokta contract snapshot ./dist/engine.js --output contract.next.jsonnpx invokta contract diff contract.json contract.next.jsonThe diff exits 1 when it finds a breaking change. Add
--fail-on-potentially-breaking to also stop on changes that need review, such
as a shorter timeout, a lost readOnly guarantee, an output property added to
a closed object, or a JSON Schema change the tool cannot decide ($ref, unions
and discriminated unions in anyOf or oneOf, allOf, not, a replaced
pattern, and similar keywords). Nullable values are still compared through
their non-null schema. Engines that use unions or $ref should always pass
the flag. When a release intentionally changes the
contract, bump the engine version and commit the new snapshot as the baseline.
The same check runs in a test:
import { readFile } from "node:fs/promises";
import { createContractSnapshot, diffContractSnapshots,} from "@invokta/tooling";
const baseline = JSON.parse(await readFile("contract.json", "utf8"));const diff = diffContractSnapshots(baseline, createContractSnapshot(engine));
expect(diff.breaking).toBe(0);See the @invokta/tooling reference for every change
code and the stability policy for the framework’s own
commitments.