Manuscript Offprint
arXiv:2610.33108ToolContractGate: Versioned Trusted Contracts for Drift-Safe Agent Tool Invocation
Sachin Gupta
Independent Researcher
San Jose, California, USA
Abstract—Agent tool approval and input validation do not, by themselves, bind a request to an approved source artifact. ToolContractGate provides a deterministic runtime contract evaluator for OpenAPI-derived agent tools. Each versioned ToolContract combines a stored OpenAPI fingerprint with access, schema, and behavioral declarations. The full evaluator applies ten checks, including a cached boot-time provenance result; four execution modes and five evaluation configurations support baseline, ablation, and non-blocking shadow analysis. On a synthetic benchmark of 45 cases (35 unsafe cases across 12 drift classes and 10 safe cases), the full pipeline detects all 35 faults: 29 BLOCK, 3 REVIEW, and 3 WARN decisions, with no false blocks on the safe cases. The archived run reports a mean gate latency of 0.18ms and a 95th percentile (p95) of 2ms using integer-millisecond measurements. The open-source artifact includes seven OpenAPI specifications, twelve enterprise contracts, 29 unit tests, and a 900-record evaluation. Results characterize contract-decision coverage; downstream enforcement requires a host that honors the returned decision. Production traffic, semantic backend drift, and dynamic provenance refresh remain evaluation and integration opportunities.
Index Terms—agent runtimes, tool invocation, Model Context Protocol, OpenAPI, contract testing, drift detection, runtime policy, provenance
I. INTRODUCTION
Large language model (LLM) agents increasingly invoke external tools through structured interfaces such as the Model Context Protocol (MCP) [1]. An operator may approve a tool name while the surrounding API, access requirements, or declared side effects evolve. Approval of a name alone does not establish that a subsequent request is consistent with the operator's approved specification and policy.
Three failure classes motivate this work. First, structural drift: a request uses an obsolete version or invalid enum value, or omits a required field. Second, misbinding: a request references a contract for ticket.create but names ticket.close. Third, declared escalation: the request reports stronger side effects or weaker confirmation than its contract permits. These are observable contract discrepancies. A backend that changes behavior while preserving all visible declarations is a separate semantic-drift problem.
We propose a trusted runtime contract: a versioned Tool-Contract associated with an approved OpenAPI artifact and evaluated for each request. Its fingerprint links the contract to the approved file bytes verified at startup; typed predicates compare the supplied request with contract policy. An integrating host can then allow, warn, hold for review, or suppress the invocation. Our contributions are:
-
A contract model combining version compatibility, tool binding, scopes, input schema, side effects, confirmation, payload limits, audit class, and OpenAPI provenance, with configurable violation severity.
-
A deterministic ten-check evaluator with documented severity precedence, four execution modes, and configurable ablations, including a shadow mode that preserves would-be decisions while always returning runtime permission.
-
A boot-time SHA-256 verifier and a reproducible 45-case benchmark evaluated under four modes and five configurations (900 evaluations), with open code, contracts, tests, and recorded results.
Identity and prompt injection. SPIFFE provides workload identities [3]; identity establishes who is communicating rather than whether a particular tool request matches an approved contract. Greshake et al. [4] demonstrate indirect prompt injection through attacker-controlled content. Contract evaluation complements content defenses but does not reject every malicious intent expressed through an otherwise permitted tool call.
Generation and offline governance. Mastouri et al. [5] study REST-to-MCP wrapping and automated server generation. ToolContractGate addresses the downstream decision point; its released contracts are manually seeded rather than automatically derived. OpenAPI-diff [6] compares specification revisions, while Pact [7] tests consumer–provider compatibility before deployment. These techniques can supply
Author-accepted manuscript. Accepted for publication in the 2026 International Conference on Computer and Applications (ICCA).
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works.

Fig. 1. Implemented contract evaluation and its deployment boundary. SHA-256 verification occurs at startup. The dashed block identifies host responsibilities; the benchmark endpoint returns decisions without implementing downstream execution, review routing, or durable audit storage.
evidence for contract updates but do not themselves implement this per-call policy. Diffy [8] compares service behavior using shadow testing; our shadow mode instead records contract decisions without changing runtime permission.
Risk and provenance frameworks. NIST AI RMF [9] and OWASP's LLM risk guidance [10] motivate governance, measurement, and controls on excessive agency. Syed et al. [11] study provenance-aware prompt-injection defense, a different use of provenance from the artifact-digest linkage here. Panwar and Abdelrahman [12] review agentic-AI cybersecurity. Table I locates the respective control points; these mechanisms are complementary rather than interchangeable.
III. SYSTEM MODEL
Figure 1 separates the implemented evaluator from the host responsibilities needed for enforcement. The trusted registry holds approved contracts and compiled schemas. A request supplies contract identity/version, tool name, scopes, payload, and optional behavioral metadata. The evaluator returns a structured decision; an enforcing host must obtain trustworthy metadata and honor that decision before forwarding the call.
A. ToolContract
A ToolContract has nine typed sections (Figure 2). The contract records identity and ownership; required scopes and audit class; limits; behavioral declarations; compatible versions; drift policy; provenance; MCP-aligned annotations; and input schema. The side-effect order is read_only < write < destructive; audit classes are routine < internal < sensitive < regulated. Payload size is checked against max_payload_bytes; max_rps is metadata without a rate counter in this prototype.
B. Checks, decisions, and actions
Table II summarizes the ten checks in evaluation order. A violation records its type, severity, expected value, and observed value. The final decision is the maximum under
BLOCK > REVIEW > WARN > ALLOW.
contracts/catalog.search.vl.yaml
id: catalog.search version: v1 tool: catalog.search owner: catalog-platform audit_class: internal required_scopes: [catalog.read] limits: max_payload_bytes: 4096 side_effect_level: read_only requires_confirmation: false idempotent: true compatibility: allowed_versions: [v1] drift_policy: version_mismatch: block audit_class_change: review, ... provenance: source_path: .../catalog.yaml openapi_sha256: 0aaf9e9b... annotations: readOnlyHint: true destructiveHint: false, ... input_schema: {type: object, ...}
Identity
Access
Limits
Behavior
Compatibility
Drift policy
Provenance
MCP Annot.
Input Schema
Fig. 2. Anatomy of a ToolContract. Annotated excerpt from the contract YAML catalog.search.vl.yaml (under gateway/src/main/resources/contracts/). Colored brackets group the nine typed sections referenced throughout the paper. The openapi_sha256 field is verified at boot by Algorithm 2; the annotations block is field-aligned with MCP ToolAnnotations [1].
The last visited violation tied at that maximum supplies reasonCode; all violations remain available. For an enforcing host, BLOCK suppresses the call, REVIEW holds it for review, and WARN permits it with a warning. The absence of violations yields ALLOW. These are integration semantics; a decision response alone does not execute, suppress, or review a downstream call.
C. Modes and per-call configuration
Figure 3 relates four modes to five measured configurations. NO_GATE returns ALLOW immediately. SCHEMA_ONLY validates the payload only when the contract resolves and schema checking is enabled. TOOL_CONTRACT_GATE evaluates all enabled checks and sets runtimeDecision=decision. SHADOW_GATE evaluates the same checks but forces runtimeDecision=ALLOW, retaining the would-be decision.
GateConfig has five check flags (version, schema, provenance, scope, annotation) plus warn_only. The annotation flag controls both side-effect and confirmation checks. The five measured presets are full, no_version, no_provenance, no_schema, and warn_only; scope and annotation ablations are available but not measured here. warn_only changes BLOCK and REVIEW violations to WARN at construction, including early-return paths. Production use requires a trusted host to choose modes/flags; the experimental endpoint does not authenticate their source.
IV. ALGORITHMS
Algorithm 1 evaluates predicates in Table II order. Only baseline modes and unresolved-contract handling return early. The helper ADD creates a violation using the policy key
TABLE I
COMPLEMENTARY CONTROLS AND THE ROLE OF CONTRACT EVALUATION. ENTRIES DESCRIBE THEIR STATED CONTROL POINTS RATHER THAN AN EXHAUSTIVE COMPARISON OF PRODUCTS.
| Control | Point of application | Relationship to contract evaluation |
|---|---|---|
| Host approval and tool filtering | Host, per invocation | Approval controls whether a call proceeds; a contract adds explicit artifact and typed-policy checks. |
| MCP interceptor proposal [2] | Client/server hooks | Draft validation and observation mechanism; a contract policy can be implemented at a hook. |
| OpenAPI-diff [6]; Pact [7] | CI / provider testing | Specification differences and compatibility tests inform approved contract revisions. |
| Diffy [8] | Shadow service testing | Compares service behavior; our shadow mode compares invocation declarations against a contract. |
| SPIFFE [3] | Workload identity | Establishes caller identity; authorization and contract admission require additional policy. |
| Prompt-injection research [4] | Agent input/context | Studies attacks and mitigation limits; contract checks address invocation-policy discrepancies. |
| ToolContractGate | Per-call evaluator | Ten checks combine contract policy with cached startup integrity of an approved OpenAPI artifact. Host integration must enforce the result. |
TABLE II
TEN RUNTIME CHECKS IN PIPELINE ORDER. DEFAULTS APPLY WITH THE FULL CONFIGURATION AND DEFAULT DRIFT POLICY; THE INTEGRATING HOST IMPLEMENTS THE INDICATED ACTION.
| # | Check | Violation condition | Emitted type | Default/action |
|---|---|---|---|---|
| 1 | Identity | No contract resolves for the supplied ID. | contract_not_found | BLOCK / deny |
| 2 | Version | Requested version is not in the allowed set. | version_mismatch | BLOCK / deny |
| 3 | Tool binding | Requested tool name differs from the bound name. | tool_mismatch | BLOCK / deny |
| 4 | Scope | A required scope is absent from supplied scopes. | scope_violation | BLOCK / deny |
| 5 | Input schema | Payload fails the compiled JSON Schema. | schema_violation | BLOCK / deny |
| 6 | Provenance | Provenance is present; cached validity is false. | provenance_mismatch | BLOCK / deny |
| 7 | Side effect | Non-null declared level exceeds the contract level. | side_effect_change | BLOCK / deny |
| 8 | Confirmation | Contract requires it; supplied flag is explicitly false. | confirmation_change | BLOCK / deny |
| 9 | Payload limit | Serialized JSON UTF-8 bytes exceed the limit. | payload_limit_violation | WARN / permit |
| 10 | Audit class | Non-null declared class is below the contract class. | audit_class_change | REVIEW / hold |
Rows 1 and 6 start at hardcoded BLOCK; other severities use contract policy. Row 9 uses policy key limit_change. warn_only downgrades BLOCK/REVIEW to WARN, including rows 1 and 6. Version, scope, schema, and provenance flags control rows 2, 4, 5, and 6; the annotation flag controls rows 7–8. Rows 1, 3, 9, and 10 have no individual disable flag. No violation yields ALLOW.
associated with its emitted type, then applies warn_only. Contract absence and invalid provenance start at BLOCK independently of contract policy. Payload overflow emits payload_limit_violation but looks up severity using limit_change. FINISH aggregates severity and attaches the mode-specific runtime decision.
Algorithm 2 runs at startup. If provenance is present, the registry reads the referenced file from the working directory or classpath and compares its SHA-256 with the stored digest. Missing files or mismatching digests set the cached validity bit to false. The contract remains registered; an enabled full-pipeline provenance check subsequently emits a violation. The verifier does not compare an OpenAPI operation's semantics with a contract schema or a deployed backend.
V. IMPLEMENTATION
The artifact uses Java 21, Spring Boot 3.3.4, and networkkt JSON Schema Validator 1.5.2 with JSON Schema 2020-12. At boot, YAML contracts load from the classpath; schemas compile once, and provenance validity is cached. Seven OpenAPI 3.1 files support twelve enterprise contracts across catalog, inventory, profile, ticket, notifications, audit, and feature-flag services. Three additional legacy contracts support the demo and have no provenance block; they are excluded from the 45-case benchmark.
POST /v1/decide accepts the gate input and returns a Decision, including violations, reason, runtime decision, and server-measured gateLatencyMs. Well-formed evaluations return HTTP 200 even for BLOCK: the consumer must inspect the body. The endpoint logs a short decision summary, not a persistent structured audit record, and does not forward calls or implement a human-review channel. The experiment supplies scopes and metadata directly, rather than extracting them from authenticated production traffic.
The legacy /v1/invoke endpoint validates JSON Web Tokens (JWTs) and performs early contract, version, tool, scope, and schema checks, then returns a stub result. Its later call to the new evaluator records the additional gate result; it does not condition the stub response on that result.
Request + mode + configuration
Five measured configurations full: all checks, normal severity no_version / no_provenance / no_schema: disable the named check warn_only: BLOCK / REVIEW → WARN
Select evaluation path NO_GATE: bypass checks, ALLOW SCHEMA_ONLY: schema check if enabled and resolved TOOL_CONTRACT_GATE, SHADOW_GATE: ten-check pipeline with configured flags
Aggregate violations → decision BLOCK > REVIEW > WARN > ALLOW
Non-shadow modes runtimeDecision = decision
Shadow mode runtimeDecision = ALLOW
Fig. 3. Modes and configurations are separate choices. NO_GATE returns early; the remaining paths retain their decision for analysis. Schema-only respects schema_check and warn_only. Shadow preserves would-be severity but always permits runtime execution. Host enforcement and audit persistence are outside this evaluator.
Thus the benchmark evaluates decision coverage, not complete downstream enforcement.
A. Blocked-invocation audit example
Listing 1 shows captured output from the existing legacy mismatch demo. The request references metrics@v1, which binds prom_query, but asks for vault.read_secret. The tool-name check rejects the invocation with HTTP 403 before reaching the stub. The diagnostic gives expected and requested names; the audit line records the denial category, and the response carries a trace identifier for correlation. This operational example uses the legacy logger's deny terminology, distinct from the gate-only endpoint's structured BLOCK decision. It demonstrates diagnostic output, not durable or tamper-evident audit storage.
Listing 1. Captured denial: log and HTTP response excerpts, reflowed for readability.
[gateway] tool.MISMATCH requested=vault.read_secret contract.tool=prom_query [audit] write class=sensitive decision=deny reason=tool_mismatch
HTTP 403 {"error": "contract_tool_mismatch", "trace_id": "b3db08ca"}
The source and archived results are available at https://github.com/sachinkg12/toolcontractgate, commit 3eb1f67. The camera-ready review preserves this implementation baseline.
Algorithm 1 Runtime contract evaluation
Require: Input x; configuration g (full if absent)
Ensure: Decision and mode-specific runtime decision
1: ▷ Ordered violation list
2: if x.mode = NO_GATE then
3: return FINISH(V, x)
4: end if
5:
6: if x.mode = SCHEMA_ONLY then
7: if and g.schemaCheck then
8: CHECKSCHEMA(c, x, g, V)
9: end if
10: return FINISH(V, x)
11: end if
12: if then
13: ADD(V, contract_not_found, BLOCK, g)
14: return FINISH(V, x)
15: end if
16: for in Table II order do
17: if check j is enabled and its violation predicate holds then
18: emitted violation type for j
19: BLOCK if , else contract policy
20: ADD(V, t, s, g)
21: end if
22: end for
23: return FINISH(V, x)
ADD attaches the expected/observed values for the predicate; if g.warnOnly and , it changes s to WARN before appending. CHECKSCHEMA uses the same helper for a schema failure. FINISH collapses by maximum severity (last equal-severity reason wins), then forces runtime ALLOW only for SHADOW_GATE. Otherwise runtime equals decision. Null guards and flag mappings are given in Table II.
Algorithm 2 Boot-time provenance and schema initialization
Require: YAML contract resources R 1: for do 2: FROMYAML(r) 3: if c.provenance then 4: READFILEORCLASSPATH(c.sourcePath) 5: valid and storedDigest) 6: end if 7: Register c and initialize its current-version entry 8: Compile and cache c's input schema 9: end for
VI. EVALUATION
A. Case design and metrics
The benchmark tests deterministic predicate coverage rather than population-level drift prevalence. Its 45 YAML cases comprise 35 unsafe cases across twelve drift classes, five happy paths, and five safe-compatibility variants. Safe variants include extra scopes, voluntary confirmation, and a stronger declared audit class. Table III gives category counts. Large-payload placeholders are expanded by the runner; enum and required-field cases exercise schema validation. Wrong-operation-binding cases change the supplied tool name; they do not test unchanged-name backend substitution.
Each case runs under four modes and five presets, yielding 900 records. We distinguish three metrics. Detected means a non-ALLOW evaluator decision on an unsafe case, including
TABLE III DETECTION RATE BY FAULT TYPE, ABLATION = FULL. A CASE IS DETECTED WHEN THE GATE RETURNS ANY NON-ALLOW DECISION; THE TWO SAFE BUCKETS REPORT RUNTIME BLOCK/REVIEW COUNTS, WHICH ARE ZERO IN ALL MODES. TCG ABBREVIATES THE TOOL_CONTRACT_GATE MODE (NOT THE SYSTEM TOOLCONTRACTGATE).
| Fault type | N | NG | SO | SG | TCG |
|---|---|---|---|---|---|
| Unsafe drift (35 cases) | |||||
| tool_mismatch | 4 | 0/4 | 0/4 | 4/4 | 4/4 |
| version_mismatch | 3 | 0/3 | 0/3 | 3/3 | 3/3 |
| schema_violation | 4 | 0/4 | 4/4 | 4/4 | 4/4 |
| missing_scope | 4 | 0/4 | 0/4 | 4/4 | 4/4 |
| side_effect_change | 3 | 0/3 | 0/3 | 3/3 | 3/3 |
| confirmation_change | 3 | 0/3 | 0/3 | 3/3 | 3/3 |
| payload_limit | 3 | 0/3 | 0/3 | 3/3 | 3/3 |
| audit_class_change | 3 | 0/3 | 0/3 | 3/3 | 3/3 |
| destr. w/o conf. | 2 | 0/2 | 0/2 | 2/2 | 2/2 |
| enum_drift | 2 | 0/2 | 2/2 | 2/2 | 2/2 |
| required_field_added | 2 | 0/2 | 2/2 | 2/2 | 2/2 |
| wrong_op. binding | 2 | 0/2 | 0/2 | 2/2 | 2/2 |
| Drift subtotal | 35 | 0/35 | 8/35 | 35/35 | 35/35 |
| Safe (10 cases): runtime BLOCK/REVIEW | |||||
| none (happy) | 5 | 0/5 | 0/5 | 0/5 | 0/5 |
| safe_change | 5 | 0/5 | 0/5 | 0/5 | 0/5 |
| Safe subtotal | 10 | 0/10 | 0/10 | 0/10 | 0/10 |
NG = NO_GATE; SO = SCHEMA_ONLY; SG = SHADOW_GATE. Names abbreviated for layout; full identifiers in experiments/cases.yaml.
WARN. The B/R count includes evaluator BLOCK or REVIEW decisions on unsafe cases; in shadow mode these are would-block/review decisions. The false-block count includes safe cases from either bucket that receive runtime BLOCK or REVIEW. These metrics are computed from the CSV fields; the runner's printed counters omit safe-change cases from its false-block denominator and therefore are not used as the metric definition.
B. Detection and ablation results
The full gate detects 35/35 unsafe cases: 29 BLOCK, three REVIEW, and three WARN decisions. The three warnings are payload-limit cases under the default policy. All ten safe cases return ALLOW. The schema-only baseline detects 8/35 unsafe cases; the no-gate baseline detects none. These outcomes establish coverage for the supplied cases, not a false-positive rate for production workloads.
Table IV reports all twenty mode/preset combinations. Disabling version checking removes three detections; disabling schema checking removes eight. warn_only retains all 35 detections while eliminating BLOCK/REVIEW decisions. Disabling provenance has no effect because no provenance-mismatch case occurs in the 45-case set; startup integrity is checked separately.
Shadow mode matches the full gate's evaluator outcomes, including 32 BLOCK/REVIEW decisions under full, while all 45 runtime decisions remain ALLOW. Consequently its runtime false blocks are zero by construction, and its B/R count does not represent suppressed calls. For the full gate, the runtime decision equals the evaluator decision, but actual suppression still depends on the host.
The archived CSV also contains a correct field. Its schema-only oracle ignores ablation settings, so no_schema and warn_only each show 37/45 correct despite the expected behavior of their eight affected schema cases. Table IV reports raw outcome counts rather than treating these oracle mismatches as unexpected gate failures.
C. Latency and provenance validation
The archived run gives full-gate mean latency 0.18 ms and p95 2 ms; the largest p95 among its buckets is 4 ms. These are server-side evaluation times from one sequential run on a developer machine. The timer truncates each duration to integer milliseconds, so zero denotes a duration below 1 ms and the mean averages quantized observations. There is no controlled warm-up, repeated-trial confidence interval, concurrency study, or measured production RPC comparison. Differences between full and shadow timing should not be interpreted as an intrinsic speed advantage, since they share the pipeline.
The stored digests in all twelve enterprise contracts match the seven approved files. An isolated integrity exercise confirmed that editing an OpenAPI file after startup leaves decisions unchanged; restarting the gateway marks affected contracts invalid and returns provenance_mismatch under the full configuration. Matching-hash, mismatching-hash, and missing-file unit tests cover the verifier. These checks establish byte-integrity behavior at load time, not detection of live semantic changes.
D. Reproducibility
A clean build uses mvn package from the repository root and runs 29 unit tests. Start the gateway from that root so relative OpenAPI paths resolve. Then invoke the runner with all five presets explicitly, as in Listing 2. Use a fresh output path to preserve the archived CSV. The convenience wrapper at the pinned commit omits the preset argument and therefore defaults to full, producing 180 evaluations; the explicit invocation produces the complete 900-record matrix.
Listing 2. Complete evaluation from the repository root after building. java -jar gateway/target/gateway-0.1.0.jar
In a second terminal:
ABL=full,no_version,no_provenance,no_schema,warn_only
java -jar agent-runner/target/agent-runner.jar
experiments experiments/cases.yaml
/tmp/tcg-camera-ready-results.csv "$ABL"
A fresh camera-ready reproduction at the pinned commit passed all 29 tests and reproduced the decision, runtime-decision, reason-code, and oracle-correctness fields in all 900 archived records. Timing is environment-dependent; the paper retains the archived latency values rather than mixing timings from different runs.
VII. DISCUSSION
A. Security role and trust boundary
Workload identity (e.g., SPIFFE [3]), delegated authorization, and contract admission answer different questions: who is
TABLE IV
ALL CONFIGURATIONS, 45 CASES EACH. DETECTED AND B/R COUNT EVALUATOR NON-ALLOW AND BLOCK/REVIEW ON THE 35 UNSAFE CASES. RUNTIME B/R COUNTS RUNTIME BLOCK/REVIEW ON UNSAFE CASES; THESE ARE RETURNED DECISIONS, NOT MEASURED DOWNSTREAM EFFECTS. FALSE BLOCKS COUNT RUNTIME BLOCK/REVIEW ON THE 10 SAFE CASES. LATENCIES ARE ARCHIVED SERVER-SIDE INTEGER-MILLISECOND MEASUREMENTS.
| Mode | Preset | Detected | B/R | Runtime B/R | False blocks | Mean (ms) | p95 (ms) |
|---|---|---|---|---|---|---|---|
| NO_GATE | full | 0 | 0 | 0 | 0 | 0.02 | 0 |
| NO_GATE | no_version | 0 | 0 | 0 | 0 | 0.00 | 0 |
| NO_GATE | no_provenance | 0 | 0 | 0 | 0 | 0.00 | 0 |
| NO_GATE | no_schema | 0 | 0 | 0 | 0 | 0.00 | 0 |
| NO_GATE | warn_only | 0 | 0 | 0 | 0 | 0.00 | 0 |
| SCHEMA_ONLY | full | 8 | 8 | 8 | 0 | 0.69 | 4 |
| SCHEMA_ONLY | no_version | 8 | 8 | 8 | 0 | 0.02 | 0 |
| SCHEMA_ONLY | no_provenance | 8 | 8 | 8 | 0 | 0.00 | 0 |
| SCHEMA_ONLY | no_schema | 0 | 0 | 0 | 0 | 0.00 | 0 |
| SCHEMA_ONLY | warn_only | 8 | 0 | 0 | 0 | 0.00 | 0 |
| TOOL_CONTRACT_GATE | full | 35 | 32 | 32 | 0 | 0.18 | 2 |
| TOOL_CONTRACT_GATE | no_version | 32 | 29 | 29 | 0 | 0.20 | 0 |
| TOOL_CONTRACT_GATE | no_provenance | 35 | 32 | 32 | 0 | 0.51 | 0 |
| TOOL_CONTRACT_GATE | no_schema | 27 | 24 | 24 | 0 | 0.09 | 0 |
| TOOL_CONTRACT_GATE | warn_only | 35 | 0 | 0 | 0 | 0.00 | 0 |
| SHADOW_GATE | full | 35 | 32 | 0 | 0 | 0.02 | 0 |
| SHADOW_GATE | no_version | 32 | 29 | 0 | 0 | 0.09 | 0 |
| SHADOW_GATE | no_provenance | 35 | 32 | 0 | 0 | 0.04 | 0 |
| SHADOW_GATE | no_schema | 27 | 24 | 0 | 0 | 0.00 | 0 |
| SHADOW_GATE | warn_only | 35 | 0 | 0 | 0 | 0.02 | 0 |
calling, what authority is conveyed, and whether the supplied invocation meets the approved contract. They can be composed, but the artifact does not implement their complete integration. Contract authoring and evaluation provide concrete governance, measurement, and management mechanisms in the spirit of NIST AI RMF [9]. Scope and confirmation checks can support controls on excessive agency [10], provided the host authenticates metadata and enforces decisions.
The trusted base includes the gateway, contracts, approved artifact store, and the integrating host. An attacker able to change both the contract digest and the source file can defeat the digest comparison. The SHA-256 linkage is compatible with artifact identification in in-toto [13] and SLSA [14], but this prototype does not produce or verify those attestations. Contracts are manually seeded; automatic, reviewed contract derivation remains future work.
Modes, ablation flags, scopes, and optional behavior fields must come from a trusted integration. The experimental endpoint does not enforce that boundary. Missing side-effect or audit-class metadata skips the respective comparison; a missing confirmation flag is not an explicit false value. A boolean declaration does not establish that a human approved the call. Legacy contracts without provenance skip that check. Production integration must define required metadata, trusted policy selection, review routing, and audit retention explicitly.
B. Semantic drift
ToolContractGate detects discrepancies exposed by its predicates, including mismatched names, invalid inputs, and declared side-effect escalation. It cannot prove that the actual operation matches its description. For example, a tool may keep its name, input schema, and read-only declaration while its backend begins writing records; that invocation can pass. The stored operation_id is metadata, not a verified binding to the running handler. Likewise, a payload can satisfy the schema while expressing undesirable but permitted behavior. Behavioral probes, reviewed contract regeneration, provider tests, and execution monitoring are complementary future controls; the present benchmark does not evaluate them.
C. Dynamic provenance verification
Startup hashing creates a snapshot. An artifact edited after startup remains unchecked until another load or restart; the prototype exposes no automatic refresh hook. Rehashing per call would reduce the stale interval but add file access and hashing cost, and would still require binding the checked version to the operation actually invoked to avoid time-of-check/time-of-use races. Periodic or event-triggered verification amortizes cost but leaves a bounded or implementation-dependent stale window. An alternative is immutable versioned artifacts with atomic replacement of the approved contract, digest, and compiled schema. A dynamic design must define failure handling, rollback, and the trusted source of new digests. These alternatives are proposed extensions; their latency and integrity tradeoffs have not been measured here.
D. External validity and deployment scale
The 900 records repeat 45 constructed cases across configurations; they are not 900 independent production workloads. Ten safe examples do not characterize rare false blocks, changing usage patterns, or multi-tenant traffic. No live LLM/MCP agent traffic, throughput, concurrent deployment, or human-review workload is evaluated.
A production study should begin with authorized, redacted tool traces, independently reviewed labels, contract/version history, and representative safe and drift cases. Replay would measure detection and false-block rates; subsequent shadow deployment would measure would-block frequency and operator review volume. A separate scale experiment should vary registry size, schema complexity, payload size, and concurrency, recording hardware/JDK, warm-up, repeated trials, throughput, memory, errors, and p50/p95/p99 gate and end-to-end latency. Synthetic load tests would characterize scaling but would not substitute for production validity. Neither study is claimed as completed in this paper.
VIII. Conclusion
ToolContractGate combines versioned trusted contracts, boot-time OpenAPI integrity verification, and a deterministic ten-check evaluator for agent tool requests. Four modes and five evaluation configurations expose decision coverage and shadow behavior. On 35 constructed unsafe cases, the full evaluator detects every fault, producing 29 BLOCK, three REVIEW, and three WARN decisions, while allowing all ten safe cases. The open artifact and explicit reproduction command support inspection of all 900 evaluations. The demonstrated contribution is contract-decision evaluation; reliable deployment also requires trustworthy inputs and a host that enforces results. Future work addresses automated contract derivation, semantic behavior validation, dynamic provenance refresh, and production and scale evaluation.
ACKNOWLEDGMENT
The author thanks the maintainers of Spring Boot, networknt JSON Schema Validator, Jackson, and jjwt, and the contributors to the MCP and SPIFFE specifications.
REFERENCES
[1] Model Context Protocol contributors, “Model context protocol specification,” 2025. [Online]. Available: https://modelcontextprotocol.io/specification/2025-06-18/schema
[2] S. Kothari, “SEP-1763: Interceptors for model context protocol,” 2025, draft proposal, issue 1763. Accessed: Oct. 2, 2026. [Online]. Available: https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1763
[3] SPIFFE Project, “SPIFFE overview,” accessed: Oct. 2, 2026. [Online]. Available: https://spiffe.io/docs/latest/spiffe-about/overview/
[4] K. Greshake, S. Abdelnabi, S. Mishra, C. Endres, T. Holz, and M. Fritz, “Not what you’ve signed up for: Compromising real-world LLM-integrated applications with indirect prompt injection,” in Proc. 16th ACM Workshop on Artificial Intelligence and Security (AISec '23), 2023, pp. 79–90, doi: 10.1145/3605764.3623985. [Online]. Available: https://arxiv.org/abs/2302.12173
[5] M. Mastouri, E. Ksontini, A. Barrak, and W. Kessentini, “From REST to MCP: An empirical study of API wrapping and automated server generation for LLM agents,” arXiv:2507.16044, 2025, doi: 10.48550/arXiv.2507.16044. [Online]. Available: https://arxiv.org/abs/2507.16044
[6] OpenAPITools, “OpenAPI-diff: Utility for comparing two OpenAPI specifications,” accessed: Oct. 2, 2026. [Online]. Available: https://github.com/OpenAPITools/openapi-diff
[7] Pact Foundation, “Pact documentation: Introduction,” accessed: Oct. 2, 2026. [Online]. Available: https://docs.pact.io/
[8] Twitter, “Diffy: Find potential bugs in your services with the power of HTTP,” 2015. [Online]. Available: https://github.com/twitter-archive/diffy
[9] E. Tabassi, “Artificial intelligence risk management framework (AI RMF 1.0),” National Institute of Standards and Technology, Tech. Rep. NIST AI 100-1, January 2023, doi: 10.6028/NIST.AI.100-1. [Online]. Available: https://nvlpubs.nist.gov/nistpubs/ai/nist.ai.100-1.pdf
[10] OWASP Foundation, “LLM06:2025 excessive agency,” OWASP Top 10 for Large Language Model Applications, 2025, accessed: Oct. 2, 2026. [Online]. Available: https://genai.owasp.org/llmrisk/llm062025-excessive-agency/
[11] T. A. Syed, M. A. Almutairi, and M. A. Moaty, “Cross-agent multimodal provenance-aware framework for robust prompt injection defense in large language and vision-language models,” in Proc. 2025 International Conference on Computer and Applications (ICCA), 2025, pp. 1–7, doi: 10.1109/ICCA66035.2025.11430791.
[12] S. Panwar and H. Abdelrahman, “Agentic AI in cybersecurity review of autonomous threat detection and adaptive defense mechanisms,” in Proc. 2025 International Conference on Computer and Applications (ICCA), 2025, pp. 1–9, doi: 10.1109/ICCA66035.2025.11431003.
[13] in-toto contributors, “in-toto attestation framework: Statement layer specification,” version 1. Accessed: Oct. 2, 2026. [Online]. Available: https://github.com/in-toto/attestation/blob/main/spec/v1/statement.md
[14] Open Source Security Foundation, “SLSA v1.2: Build provenance,” 2025, accessed: Oct. 2, 2026. [Online]. Available: https://slsa.dev/spec/v1.2/build-provenance