/** * Strict-args validation for retriever-shaped tools. * * Why this exists: callers (autonomous agents, chain walkers, tests) routinely * pass argument keys that the tool's Zod schema does NOT declare. Today the * MCP SDK builds `z.object(shape)` with the default `strip` semantics — so an * undeclared key like `pattern_hash: "FU1__vh8hbY"` is silently dropped, the * tool runs with `args.pattern === undefined`, and the caller waits ~3 minutes * for a zero-event result that should have been a fast unknown_arg error. * * Concretely: a `retriever_query` call with an undeclared `pattern_hash` arg * runs for minutes and returns 0 events with no error, no warning, and no hint * that the arg was discarded. That's the foot-gun this helper closes. * * Usage at the executor entry point: * * const strict = validateStrictArgs('log10x_retriever_query', retrieverQuerySchema, args); * if (strict.error) return strict.error; * // args is the validated, strict-mode object — extra keys would have errored. * * The returned `error` is a fully-formed chassis error envelope (status: * 'error', error_type: 'unknown_arg', retryable: false) — agents read the * `hint` field to learn which key(s) were rejected. * * NOTE: we run the strict check AT the executor entry, not at the registration * boundary. The SDK boundary path produces an MCP protocol error rather than * our typed envelope; doing it here keeps the chassis envelope shape and also * catches direct callers (tests, chain walkers, eval harnesses) that bypass * the SDK validation entirely. */ import { type ZodRawShape } from 'zod'; import { type ChassisEnvelope } from './chassis-envelope.js'; export interface StrictArgsResult { /** Strictly-validated args; only present when the input had no unknown keys. */ args?: T; /** Pre-built chassis error envelope to return when unknown keys are present. */ error?: ChassisEnvelope; } /** * Validate `args` against `shape` with `.strict()` semantics. Unknown keys * yield a chassis error envelope; valid args are returned in-place. * * The `shape` is the same plain-object Zod raw shape the tools export today * (e.g. `retrieverQuerySchema`). We wrap it with `z.object(...).strict()` * just for the validation pass — the registration path keeps its own * coercive wrapper unchanged. */ export declare function validateStrictArgs(tool: string, shape: ZodRawShape, args: unknown): StrictArgsResult;