/** * Response fingerprinting for structural drift detection. * * Analyzes MCP tool responses to create deterministic fingerprints * that capture response structure, shape, and characteristics without * requiring LLM analysis. */ import type { MCPToolCallResult } from '../transport/types.js'; import type { EnhancedErrorAnalysis } from './error-analyzer.js'; /** * Content type classification for responses. */ export type ResponseContentType = 'text' | 'object' | 'array' | 'primitive' | 'empty' | 'error' | 'mixed' | 'binary'; /** * Size classification for responses. */ export type ResponseSize = 'tiny' | 'small' | 'medium' | 'large'; /** * Fingerprint of a tool's response structure. */ export interface ResponseFingerprint { /** Hash of the response structure (keys, types, nesting) */ structureHash: string; /** Primary content type of the response */ contentType: ResponseContentType; /** Top-level field names if response is an object */ fields?: string[]; /** Structure hash of array items (if array response) */ arrayItemStructure?: string; /** Approximate response size category */ size: ResponseSize; /** Whether the response is empty/has no meaningful content */ isEmpty: boolean; /** Number of successful responses used to build this fingerprint */ sampleCount: number; /** Confidence score (0-1) based on response consistency */ confidence: number; } /** * Inferred JSON schema from response samples. */ export interface InferredSchema { type: string; properties?: Record; items?: InferredSchema; required?: string[]; nullable?: boolean; enum?: unknown[]; } /** * Normalized error pattern for drift detection. */ export interface ErrorPattern { /** Normalized error category */ category: 'validation' | 'not_found' | 'permission' | 'timeout' | 'internal' | 'unknown'; /** Pattern hash for comparison */ patternHash: string; /** Example error message (first occurrence) */ example: string; /** Count of occurrences */ count: number; } /** * Result of analyzing multiple tool responses. */ export interface ResponseAnalysis { /** Aggregated response fingerprint */ fingerprint: ResponseFingerprint; /** Inferred schemas for each successful response */ schemas: InferredSchema[]; /** Inferred output schema from successful responses */ inferredSchema?: InferredSchema; /** Error patterns observed */ errorPatterns: ErrorPattern[]; /** Enhanced error analyses with root cause and remediation */ enhancedErrorAnalyses?: EnhancedErrorAnalysis[]; /** Whether responses were consistent across samples */ isConsistent: boolean; } /** * Analyze multiple tool responses to create a comprehensive fingerprint. */ export declare function analyzeResponses(responses: Array<{ response: MCPToolCallResult | null; error: string | null; }>): ResponseAnalysis; /** * Infer a JSON schema from a sample value. */ export declare function inferSchemaFromValue(value: unknown): InferredSchema; /** * Compare two response fingerprints and return differences. */ export interface FingerprintDiff { /** Whether the fingerprints are identical */ identical: boolean; /** List of changes detected */ changes: FingerprintChange[]; /** Overall significance of changes */ significance: 'none' | 'low' | 'medium' | 'high'; } export interface FingerprintChange { aspect: 'structure' | 'content_type' | 'fields' | 'array_items' | 'size' | 'emptiness'; description: string; before: string; after: string; breaking: boolean; } /** * Compare two response fingerprints. */ export declare function compareFingerprints(previous: ResponseFingerprint | undefined, current: ResponseFingerprint | undefined): FingerprintDiff; /** * Compare error patterns between baselines. */ export interface ErrorPatternDiff { /** New error patterns that didn't exist before */ added: ErrorPattern[]; /** Error patterns that no longer occur */ removed: ErrorPattern[]; /** Whether error behavior changed significantly */ behaviorChanged: boolean; } export declare function compareErrorPatterns(previous: ErrorPattern[] | undefined, current: ErrorPattern[] | undefined): ErrorPatternDiff; /** * Compute a hash for the inferred schema for comparison. */ export declare function computeInferredSchemaHash(schema: InferredSchema | undefined): string; //# sourceMappingURL=response-fingerprint.d.ts.map