From 74712cde2b45693953d36bf295eccaea80face3b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 16:00:19 +0800 Subject: [PATCH] refactor(catalog): consolidate digest presentation (#17447) --- src/contracts/catalog/catalogIdentity.ts | 42 +++++++----------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/contracts/catalog/catalogIdentity.ts b/src/contracts/catalog/catalogIdentity.ts index 52b13c0e459..886c6332d81 100644 --- a/src/contracts/catalog/catalogIdentity.ts +++ b/src/contracts/catalog/catalogIdentity.ts @@ -128,14 +128,19 @@ export const digestCatalogProjection = (value: unknown): string => sha256Hex(canonicalJson(value)); /** Digests of the presented tool and prompt catalog. */ -const digestPresentedCatalogs = ( - catalog: ReturnType, +const digestCatalogs = ( + catalog: ReturnType, prompts: ReturnType, outputSchemaProfile: McpOutputSchemaProfile, + compactPresentation?: CompactInputSchemaPresentation, ) => { + const presentation = advertisedToolPresentation( + outputSchemaProfile, + compactPresentation, + ); const tools = canonicalJson({ output_schema_profile: outputSchemaProfile, - catalog, + catalog: presentToolCatalog(catalog, presentation), }); const promptCatalog = canonicalJson(prompts); // RFC 8785 writes an object as its members in key order, each value in its @@ -149,21 +154,6 @@ const digestPresentedCatalogs = ( } as const; }; -const digestCatalogs = ( - catalog: ReturnType, - prompts: ReturnType, - compactPresentation: CompactInputSchemaPresentation, - outputSchemaProfile: McpOutputSchemaProfile, -) => - digestPresentedCatalogs( - presentToolCatalog( - catalog, - advertisedToolPresentation(outputSchemaProfile, compactPresentation), - ), - prompts, - outputSchemaProfile, - ); - /** * Catalog digests over the given tool contracts. Exported so tests can prove * which contract fields the identity covers; production uses @@ -180,8 +170,8 @@ export const createCatalogDigests = ( digestCatalogs( createToolCatalog(sortByName(contracts)), createPromptCatalog(promptContracts), - compactPresentation, outputSchemaProfile, + compactPresentation, ); /** Build-time identities share schema conversion across both output profiles. */ @@ -192,18 +182,8 @@ export const createCatalogDigestProfiles = ( const catalog = createToolCatalog(sortByName(contracts)); const prompts = createPromptCatalog(promptContracts); return { - off: digestCatalogs( - catalog, - prompts, - COMPACT_INPUT_SCHEMA_PRESENTATION, - "off", - ), - compact: digestCatalogs( - catalog, - prompts, - COMPACT_INPUT_SCHEMA_PRESENTATION, - "compact", - ), + off: digestCatalogs(catalog, prompts, "off"), + compact: digestCatalogs(catalog, prompts, "compact"), }; };