/** * Input sanitization utilities for prompt injection protection. * * These utilities help prevent malicious content in MCP server responses * from manipulating LLM behavior through prompt injection attacks. */ /** * Result of sanitization with metadata about what was found. */ export interface SanitizeResult { /** The sanitized text */ sanitized: string; /** Whether any potential injection patterns were detected */ hadInjectionPatterns: boolean; /** List of detected patterns (for logging) */ detectedPatterns: string[]; /** Whether structural characters were escaped */ hadStructuralChars: boolean; } /** * Sanitize user-provided text for safe inclusion in LLM prompts. * * This function: * 1. Detects potential prompt injection patterns * 2. Escapes structural characters that could manipulate prompt format * 3. Wraps content in clear data delimiters * * @param text - The text to sanitize (e.g., tool description, schema) * @param options - Sanitization options * @returns Sanitized text safe for prompt inclusion */ export declare function sanitizeForPrompt(text: string, options?: { /** Whether to escape structural characters */ escapeStructural?: boolean; /** Whether to wrap in data delimiters */ wrapInDelimiters?: boolean; /** Custom delimiter name */ delimiterName?: string; /** Whether to strip detected injection patterns */ stripInjections?: boolean; }): SanitizeResult; /** * Sanitize a JSON object for prompt inclusion. * Recursively sanitizes all string values. * * @param obj - The object to sanitize * @returns Sanitized object with all strings processed */ export declare function sanitizeObjectForPrompt(obj: unknown): unknown; /** * Create a safely delimited data section for prompts. * Uses instruction/data separation pattern to prevent injection. * * @param label - Label for the data section * @param content - Content to include * @returns Formatted data section */ export declare function createDataSection(label: string, content: string): string; /** * Sanitize a tool for safe inclusion in prompts. * Returns a structured representation with sanitized fields. * * @param tool - Tool object with name, description, and schema * @returns Sanitized prompt-safe representation */ export declare function sanitizeToolForPrompt(tool: { name: string; description?: string; inputSchema?: unknown; }): { name: string; description: string; schema: string; warnings: string[]; }; /** * Check if text contains potential injection patterns without modifying it. * * @param text - Text to check * @returns True if potential injection detected */ export declare function hasInjectionPatterns(text: string): boolean; /** * Truncate text to a maximum length with indicator. * Useful for limiting context size in prompts. * * @param text - Text to truncate * @param maxLength - Maximum length * @returns Truncated text */ export declare function truncateForPrompt(text: string, maxLength: number): string; //# sourceMappingURL=sanitize.d.ts.map