[Feature][MCP] Track tool contract versions with compatibility diffs and pinning
Goal
Make MCP tool schema changes reviewable and allow clients/operators to select a known contract before a changing remote tool breaks an agent workflow.
Existing capabilities and boundary
Agent Gateway already has remote catalog refresh, schema validation and generation fencing. Extend those capabilities with immutable contract snapshots and evolution workflows; do not replace catalog refresh or confuse a refresh generation with an externally stable contract version. #6365 concerns client-admin registration protocols, not MCP tool contracts.
MVP
- Snapshot each tool's identity and the input/output schema and capability metadata actually exposed by the supported MCP implementation. Use a stable digest/canonical representation and retain source/generation provenance.
- Show structural differences and classify a conservative subset: removed tool, newly required input, removed accepted input/enum value or incompatible type. Treat unknown JSON Schema constructs as requiring review rather than claiming a complete compatibility theorem.
- Allow an operator to approve and pin an exposed tool contract/version. Define tool listing/call behavior when the source changes or a pinned contract becomes unavailable.
- Store bounded, redacted regression examples for schema validation. Actual tool execution is opt-in and needs a safe test target; a matching schema is not proof of unchanged semantics.
- Integrate with existing catalog publication and generation fencing so lists, validators and invocations observe a coherent approved generation.
Acceptance criteria
- [ ] Tests cover additive/required/type/enum/removal changes and unsupported schema features, with explicit backward-compatibility direction.
- [ ] Canonically equivalent schemas do not generate spurious versions; snapshot history and per-tool/example sizes have retention limits.
- [ ] Concurrent refresh/pin/unpin does not mix tool metadata and validators from different generations.
- [ ] A pinned snapshot does not pretend to restore an old remote implementation. If the provider cannot serve the pinned contract, calls fail with a documented compatibility/unavailability result or an explicitly configured adapter.
- [ ] Tenant/namespace permissions apply to history, pinning and examples; credentials and private source metadata are redacted.
- [ ] Existing unpinned behavior remains compatible; legacy tools without output schemas are represented accurately.
Related: #7923 (OpenAPI-derived HTTP tool plan preview), #6365 (separate registration protocol work). This is contract governance, not general remote-service version control.
Two data points that may help scope the pinning design, both from reading the current master.
-
What a pin would cover today.
ShenyuToolDefinitioncarriesname,description,requestConfigandinputSchema(shenyu-plugin-mcp-server/.../definition/ShenyuToolDefinition.java);ShenyuMcpServerToolcarriesname,description,requestConfigandparameters. The MCPTooltype also hastitle,annotationsandoutputSchema, none of which appear in these classes yet. If the pin is defined over the current four fields it will silently miss those three the day they are added, so it may be worth defining the pinned set over the fullToolshape from the start, with absent fields hashed as absent.requestConfig(URL, method, headers, argument positions) is the part that actually changes behaviour for a caller and should be inside the pin, not beside it. -
How often tool definitions change in the wild. From a small daily read-only
tools/listcomparison I run against a handful of public MCP servers (4 servers, 2 recorded days so far; 16 changes across the whole index): 3 tools added, 2 removed, 5 description changes, 4 inputSchema changes, 2 annotation-only changes. The sample is tiny, but annotation-only and schema-only changes were not rare relative to description changes, which argues for pinning all of them rather than the description alone.
Two concrete suggestions for the behaviour part of the issue: (a) hash over a canonical serialization (RFC 8785) so key order in inputSchema does not produce false drift; (b) on mismatch, hold only the changed tool and surface a diff, rather than failing the whole server listing, and treat "pinned contract unavailable" as unavailable-for-that-tool rather than as unchanged. Happy to share the comparison script if useful.
Hi @Aias00,
Your proposal for versioned MCP tool contracts is closely aligned with a problem I've been working on in [ChangeProof](https://github.com/jajazpua/ChangeProof).
ChangeProof compares versioned MCP/OpenAPI contract snapshots, identifies structural changes and potential compatibility risks, and generates integrity-checked reports.
I'd like to offer a free, manually supervised comparison of two public or sanitized tools/list snapshots for one representative MCP tool.
The report would focus on changed input/output schemas, required fields, removed properties, and conservative compatibility classifications. It would not claim to prove runtime behavior, concurrency safety, or the correctness of contract pinning.
Here's an example report from a real OpenAPI migration:
https://github.com/jajazpua/ChangeProof/blob/main/ChangeProof_UniFi_68_Validated_Pilot_Report.md
Would a small independent before/after report be useful as an additional test case for #7935?
No credentials, installation, private data, or payment required.
@zsobpeter-code, thanks, these suggestions help clarify the pinning scope.
We should distinguish the client-visible MCP tool contract from ShenYu’s invocation configuration. The snapshot should cover all supported tool metadata, including optional fields, while changes to requestConfig should also be tracked using redacted configuration and credential references.
Canonical serialization makes sense for avoiding key-order-only drift. We should distinguish that from schema-semantic equivalence, which canonical JSON alone does not establish.
I also agree that drift should normally be isolated to the affected tool, with a visible diff and an explicit unavailable state when the pinned contract cannot be served. Pinning metadata must not imply that ShenYu can restore an older remote implementation.
Please share the comparison script and a small public or synthetic before/after fixture, especially an annotation-only change. That would help define reproducible acceptance tests for #7935.
@jajazpua, thanks for the offer. A small before/after MCP example would be useful as an additional regression fixture for #7935.
Please include both public or synthetic JSON snapshots, machine-readable findings, and the expected compatibility direction for inputs and outputs. Unsupported schema constructs should be marked as requiring review.
A useful first case would combine a newly required input, an output enum expansion, and an annotation-only change, keeping structural changes separate from compatibility judgments.
Please post the artifacts here so the results can be independently reviewed. Runtime behavior, generation consistency, and pinning correctness remain separate acceptance criteria.
@Aias00, thank you for your reply. The requested synthetic MCP regression fixture is now published:
https://github.com/jajazpua/ChangeProof/tree/11bb0c33d70e0211e5649c27566da7069c0f0824/pilots/shenyu-7935
The package includes:
- Before/after JSON snapshots.
- Machine-readable structural findings and expected compatibility directions for inputs and outputs.
- A combined case with a newly required input, an output enum expansion, and an annotation change.
- Separate annotation-only, key-order-only, and unsupported-composition controls.
Structural facts are kept separate from compatibility judgments. The unsupported composition is explicitly marked INDETERMINATE and requires review.
A standalone fixture verifier and instructions are included; its recorded run passed 38 checks. The commercial ChangeProof engine source is not included.
Runtime behavior, generation consistency, and pinning correctness remain separate acceptance criteria.
I'd welcome your review of the expected compatibility directions and whether this fixture would be suitable for the #7935 regression suite.
@Aias00 thanks. Instead of the internal script I mentioned, here is the same comparison in our public CLI; it runs locally, with no key and no network call. Run on the synthetic fixture jajazpua published (pilots/shenyu-7935/snapshots at 11bb0c3), with coderifts version 8.8.2:
npx -y [email protected] tools-check --base before.tools-list.json --head annotation_only.after.tools-list.json
npx -y [email protected] lock --check --locked-manifest before.tools-list.json --live-manifest annotation_only.after.tools-list.json
| after file | tools-check | exit | lock --check | exit |
|---|---|---|---|---|
| combined | BREAKS_DETECTED, breaking 2 | 2 | drift | 3 |
| annotation_only | NO_BREAK_DETECTED, breaking 0 | 0 | drift | 3 |
| key_order_only | NO_BREAK_DETECTED | 0 | unchanged | 0 |
| unsupported (allOf / not) | ANALYSIS_FAILED | 1 | drift | 3 |
The annotation-only case, verbatim:
outcome: NO_BREAK_DETECTED
breaking: 0
TOOL_ANNOTATION_CHANGED fixture_lookup readOnlyHint true→false (riskier)
The two commands answer different questions. tools-check asks whether an existing caller breaks: the hint flip is printed as a review row but is not a schema break, so exit 0. lock --check is a drift monitor: any change to the pinned definition is drift (exit 3), and the hint flip is scored toward riskier.
On combined, tools-check gives three rows: OPTIONAL_TO_REQUIRED workspace_id (input), response-property-enum-value-added status value paused (output, flagged for approval because a strict old consumer may reject it), and the hint flip. On unsupported it does not pass a change it cannot model: ANALYSIS_FAILED, with /inputSchema/allOf and /inputSchema/allOf/0/not named.
To your point on equivalence: "unchanged" on key_order_only means the two definitions are equal as canonical JSON (RFC 8785), nothing more; it is not a claim of schema-semantic equivalence.
Disclosure: version 8.8.1 got four of these cases wrong (it passed the allOf/not change with exit 0, reported key order alone as drift, missed the output enum value, and counted the hint flip as breaking). This fixture found them; 8.8.2 fixes all four. One known gap remains: lock --check still words an optional parameter made required as "new required parameter".
Every tools-check output ends with what it does not prove: a tools/list as served to this client and authorization scope; another client or scope may have been served a different list.
Hi @Aias00 and @zsobpeter-code,
Thank you for independently exercising the synthetic MCP fixture and documenting the regression findings.
For #7935, I suggest keeping these acceptance criteria separate:
- Newly required input: potential caller compatibility break.
- Expanded output enum: potential incompatibility for exhaustive response consumers.
- Annotation-only change: descriptor/pin drift requiring review, but not automatically an input-schema break.
- JSON key-order-only change: no canonical descriptor drift.
- Unsupported schema composition: explicit indeterminate result, never an unqualified compatibility PASS.
Canonical JSON equality should not be confused with schema-semantic equivalence. Contract-level findings should also remain separate from runtime pinning correctness.
The reproducible fixture is available here: https://github.com/jajazpua/ChangeProof/tree/11bb0c33d70e0211e5649c27566da7069c0f0824/pilots/shenyu-7935
I haven't independently rerun coderifts; these observations are based on the results shared in this thread.
Thanks again for testing against the fixture and making the results reproducible.
@jajazpua, thanks for providing the fixtures and clarifying the compatibility directions. I agree with the five distinctions in your latest comment: newly required inputs can reject old callers; an expanded output enum can affect strict or exhaustive old consumers; annotation changes require metadata review without automatically becoming schema breaks; object key order alone should not create canonical descriptor drift; and unsupported composition must remain indeterminate.
I reviewed the package at 11bb0c33d70e0211e5649c27566da7069c0f0824 and ran the public fixture verifier locally: all 38 checks passed with Python 3.9.6 and jsonschema 4.25.1. This validates the fixture checks and recorded-report consistency; I did not rerun the commercial engine or verify ShenYu runtime pinning.
The synthetic cases would be useful regression inputs for #7935. Please consider submitting a small PR with the before/after fixtures, expected structural changes and directional compatibility expectations, plus focused tests that can run through the project's normal test workflow. Preserve the strict-consumer qualification on the output enum case and the explicit unknown result for unsupported constructs. Include fixture provenance, and keep the tests independently runnable without a proprietary engine dependency.
We can review that contribution separately from the larger snapshot/approval/pinning implementation. Generation consistency, authorization scope and actual invocation behavior remain acceptance criteria for the runtime work.
@zsobpeter-code, thanks for exercising the shared fixture and documenting both the results and the earlier regressions. I agree that compatibility analysis and descriptor drift should be reported separately. In particular, an annotation-only change can require pin review while leaving both schemas unchanged, and canonical JSON equality should not be presented as general schema-semantic equivalence. The distinction between an existing optional input becoming required and an entirely new required input is also useful to preserve in the findings.
Please consider a focused PR contributing independently runnable canonicalization/drift regression cases and expected findings for ShenYu. The cases should distinguish metadata drift, directional compatibility risks and unsupported analysis, while preserving the client/authorization-scope boundary you noted. The current ASCII key-order fixture is a useful start; tests for an RFC 8785 implementation should additionally exercise the relevant number and Unicode canonicalization rules before claiming that coverage.
Please coordinate with @jajazpua on the shared fixture resources so contributions complement each other. The CLI results are useful supporting evidence; the ShenYu regression suite should run without requiring an external CLI, and runtime enforcement of a pinned contract remains a separate implementation step.
Thanks, that scope works. I will open a focused PR with independently runnable regression cases for ShenYu: before/after fixtures with expected structural findings, directional compatibility expectations, and an explicit INDETERMINATE for unsupported composition, kept separate from descriptor drift. For RFC 8785 coverage the cases will exercise the number and Unicode canonicalization rules in addition to key order, with provenance for every fixture. The tests will run through the project's normal workflow with no external CLI; the coderifts results stay as supporting evidence only. I will coordinate with @jajazpua so the fixture sets complement each other rather than overlap, and leave runtime pinning as the separate step you describe.
Opened #8481 with the RFC 8785 canonicalization set: number, escaping and Unicode key-order fixtures, a test-scoped reference canonicalizer, provenance for every fixture, no external CLI. @jajazpua it deliberately does not repeat the combined / annotation-only / unsupported cases from #8309 and copies nothing from the pilot package, so the two sets complement each other; say so if you see an overlap. Runtime pinning and the compatibility-direction cases stay separate, as @Aias00 described.
Thanks @zsobpeter-code for coordinating!
I compared #8481 with #8309 and found no duplicate test files or fixtures. The two contributions complement each other:
- #8309: MCP contract changes and compatibility regression tests.
- #8481: RFC 8785 canonicalization tests covering numbers, escaping, and Unicode key ordering.
@Aias00, could you please review #8309 separately as the contract-compatibility regression contribution?
I'm happy to address any remaining feedback.
Thanks!