Manuscript Offprint

arXiv:2610.33108

ToolContractGate: Versioned Trusted Contracts for Drift-Safe Agent Tool Invocation

Sachin Gupta

Sachin Gupta

Independent Researcher

San Jose, California, USA

sachinkg12@gmail.com

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.