fix: dereference MCP tool schema $ref/$defs and suppress Ajv format warnings (#276)

- Add dereferenceJsonSchema() that inlines local $ref pointers and strips
  $defs/definitions from MCP tool schemas before they reach LLM providers.
  Previously, Anthropic's convertTools() extracted only properties/required,
  dropping $defs and leaving dangling $ref — the LLM never saw the actual
  type definitions (e.g. SourceAnchorInput enum values from nucleus).

- Silence Ajv logger (logger: false) on all three instances that use
  strict: false. MCP servers may declare non-standard format keywords
  (e.g. "uint") that caused console.warn() to corrupt TUI output.

- Cache compiled Ajv validators per schema object identity in validation.ts,
  eliminating redundant recompilation on every tool call.

Co-authored-by: Miroslav Drbal <miroslav.drbal@gendigital.com>
This commit is contained in:
Miroslav Drbal [ApoC]
2026-03-03 22:52:41 +01:00
committed by GitHub
co-authored by Miroslav Drbal
parent 8d33fed6e4
commit a0fe672ca2
8 changed files with 382 additions and 55 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ import {
} from "./types";
const MCP_CALL_TIMEOUT_MS = 60_000;
const ajv = new Ajv({ allErrors: true, strict: false });
const ajv = new Ajv({ allErrors: true, strict: false, logger: false });
/** Agent event types to forward for progress tracking. */
const agentEventTypes = new Set<AgentEvent["type"]>([