Skip to content

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.

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.

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.

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 CLI list and describe include deprecated;
  • MCP clients see a description that starts with Deprecated since 2.0.0: Superseded by the triage flow. and a Replacement: 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.

  1. 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",
    },
    },
    },
    });
  2. Release a minor version. Both IDs work, and every channel shows the deprecation on the old one.

  3. Remove the old ID in the next major version of the engine.

@invokta/tooling records the public contract of a built engine and compares it with the accepted baseline:

Terminal window
yarn add --dev @invokta/tooling
yarn build
npx invokta contract snapshot ./dist/engine.js --output contract.json
git add contract.json

In CI, snapshot the current build and diff it against the committed baseline:

Terminal window
npx invokta contract snapshot ./dist/engine.js --output contract.next.json
npx invokta contract diff contract.json contract.next.json

The 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.