Skip to content

Class: StateSyncLayer

Defined in: packages/core/src/state-sync/StateSyncLayer.ts:46

Constructors

Constructor

ts
new StateSyncLayer(config): StateSyncLayer;

Defined in: packages/core/src/state-sync/StateSyncLayer.ts:76

Construct a StateSyncLayer from user configuration.

Eagerly validates all policies and defaults at construction time. If any policy is invalid, construction fails immediately with a descriptive error.

Parameters

ParameterTypeDescription
configStateSyncConfigState sync configuration (policies + optional defaults)

Returns

StateSyncLayer

Throws

If any policy or default is invalid

Methods

decorateResult()

ts
decorateResult(toolName, result): ToolResponse;

Defined in: packages/core/src/state-sync/StateSyncLayer.ts:110

Decorate a tool call response with causal invalidation signals.

Called after every tools/call execution. If the tool's policy has invalidates patterns and the call succeeded (isError !== true), prepends a [System: Cache invalidated for X — caused by Y] block at content index 0.

Parameters

ParameterTypeDescription
toolNamestringThe name of the tool that was called
resultToolResponseThe tool call result from the handler

Returns

ToolResponse

Decorated result (with System block) or unchanged result


decorateTools()

ts
decorateTools(tools): {
  _meta?: {
   [key: string]: unknown;
  };
  annotations?: {
     destructiveHint?: boolean;
     idempotentHint?: boolean;
     openWorldHint?: boolean;
     readOnlyHint?: boolean;
     title?: string;
  };
  description?: string;
  execution?: {
     taskSupport?: "optional" | "required" | "forbidden";
  };
  icons?: {
     mimeType?: string;
     sizes?: string[];
     src: string;
     theme?: "light" | "dark";
  }[];
  inputSchema: {
   [key: string]: unknown;
     properties?: {
      [key: string]: object;
     };
     required?: string[];
     type: "object";
  };
  name: string;
  outputSchema?: {
   [key: string]: unknown;
     properties?: {
      [key: string]: object;
     };
     required?: string[];
     type: "object";
  };
  title?: string;
}[];

Defined in: packages/core/src/state-sync/StateSyncLayer.ts:94

Decorate all tool descriptions with their resolved Cache-Control directives.

Called during tools/list to append [Cache-Control: X] to each tool's description. Tools without a matching policy (and no defaults) are returned unchanged.

Uses per-tool caching to avoid redundant decoration on repeated calls.

Parameters

ParameterTypeDescription
tools{ _meta?: { [key: string]: unknown; }; annotations?: { destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; readOnlyHint?: boolean; title?: string; }; description?: string; execution?: { taskSupport?: "optional" | "required" | "forbidden"; }; icons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark"; }[]; inputSchema: { [key: string]: unknown; properties?: { [key: string]: object; }; required?: string[]; type: "object"; }; name: string; outputSchema?: { [key: string]: unknown; properties?: { [key: string]: object; }; required?: string[]; type: "object"; }; title?: string; }[]Original MCP tool definitions from the registry

Returns

{ _meta?: { [key: string]: unknown; }; annotations?: { destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; readOnlyHint?: boolean; title?: string; }; description?: string; execution?: { taskSupport?: "optional" | "required" | "forbidden"; }; icons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark"; }[]; inputSchema: { [key: string]: unknown; properties?: { [key: string]: object; }; required?: string[]; type: "object"; }; name: string; outputSchema?: { [key: string]: unknown; properties?: { [key: string]: object; }; required?: string[]; type: "object"; }; title?: string; }[]

Decorated tool definitions (cached shallow copies where modified)