UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

48 lines (47 loc) 2.3 kB
/** * MCP Output Normalizer * * Single responsibility: intercept a raw MCP `CallToolResult`, measure it, * and apply the configured strategy so that oversized payloads never reach * caches, Redis, or LLM context windows raw. * * Two strategies: * - "inline" Pass through unchanged. The full payload enters the LLM * context as-is. Emit a warning above warnBytes. * - "externalize" Write the full payload to the ArtifactStore, return a * compact surrogate with a head/tail preview and an artifact * ID. The model uses `retrieve_context` with that ID to read * the full output on demand, with offset/limit pagination. * * The surrogate result is shaped as an MCP `CallToolResult` so it passes * transparently through any downstream code that expects that format. * A `_meta` extension carries the artifact ID for structured extraction in * `redisConversationMemoryManager`. * * @module mcp/mcpOutputNormalizer */ import type { ArtifactStore, McpOutputNormalizerConfig, McpOutputContext, NormalizedMcpOutput } from "../types/index.js"; /** Default byte ceiling above which externalize fires (100 KB). */ export declare const DEFAULT_MAX_MCP_OUTPUT_BYTES: number; /** Default byte threshold for emitting a warning while still inline (50 KB). */ export declare const DEFAULT_WARN_MCP_OUTPUT_BYTES: number; /** Metadata key embedded in surrogate `_meta` and used by memory manager. */ export declare const NEUROLINK_ARTIFACT_ID_KEY = "neurolinkArtifactId"; /** * Stateless normalizer (state lives in the injected ArtifactStore). * * Construct once per NeuroLink instance and set via * `ToolDiscoveryService.setOutputNormalizer()`. */ export declare class McpOutputNormalizer { private readonly config; private readonly artifactStore?; constructor(config: McpOutputNormalizerConfig, artifactStore?: ArtifactStore | undefined); /** * Measure `callResult`, apply strategy if oversized, return normalized output. * * Never throws: on any internal failure the raw result is returned unchanged * with a warning log so tool execution is never broken by the normalizer. */ normalize(callResult: unknown, context: McpOutputContext): Promise<NormalizedMcpOutput>; }