UNPKG

@dollhousemcp/mcp-server

Version:

DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.

93 lines 3.69 kB
/** * MCP-safe logger that avoids writing to stdout/stderr during protocol communication * * In MCP servers, stdout and stderr are reserved for JSON-RPC protocol messages. * Any non-protocol output will cause "Unexpected token" errors in the MCP client. * * This logger: * - Writes to stderr ONLY during server initialization (before MCP connection) * - Stores all logs in memory during runtime * - Provides methods to retrieve logs via MCP tools if needed */ import { ILogger, LogEntry } from '../types/ILogger.js'; declare class MCPLogger implements ILogger { private logs; private isMCPConnected; private minLevel; private static readonly LEVEL_ORDER; private logListener?; addLogListener(fn: (entry: LogEntry) => void): () => void; private static readonly MAX_DEPTH; private static readonly EXACT_MATCH_PATTERNS; private static readonly SUBSTRING_PATTERNS; private static readonly EXACT_MATCH_REGEX; private static readonly SUBSTRING_REGEX; private static readonly MESSAGE_SENSITIVE_PATTERNS; /** * Call this after MCP connection is established to stop console output */ setMCPConnected(): void; /** * Set minimum log level for console output. * Entries below this level are still stored in memory but not printed. */ setMinLevel(level: 'debug' | 'info' | 'warn' | 'error'): void; /** * Check if a field name contains sensitive patterns * Uses both exact matching and substring matching for better precision * @param fieldName - The field name to check * @returns true if the field name matches sensitive patterns */ private isSensitiveField; /** * Safely assign a value, ensuring sensitive data is never exposed * This function makes it explicit to CodeQL that sensitive values are replaced * @param key - The object key * @param value - The value to potentially sanitize * @param depth - Current recursion depth for performance protection * @param seen - Set of seen objects to prevent circular references * @returns Safe value that can be logged */ private safeAssign; /** * Sanitize an object or array recursively with performance optimizations * @param obj - Object or array to sanitize * @param depth - Current recursion depth (defaults to 0) * @param seen - Set of seen objects to detect circular references * @returns Sanitized copy with sensitive fields redacted */ private sanitizeObject; /** * Sanitize sensitive data before logging * Security fix: Prevents exposure of OAuth tokens, API keys, passwords, etc. * @param data - Data to sanitize (can be any type) * @returns Sanitized copy with sensitive fields replaced with '[REDACTED]' */ private sanitizeData; /** * Sanitize sensitive information from log messages * Security fix: Prevents exposure of credentials that may be embedded in message strings * @param message - The log message to sanitize * @returns Sanitized message with sensitive data replaced with '[REDACTED]' */ private sanitizeMessage; /** * Internal logging method */ private log; debug(message: string, data?: any): void; info(message: string, data?: any): void; warn(message: string, data?: any): void; error(message: string, data?: any): void; /** * Get recent logs (for MCP tools to retrieve) */ getLogs(count?: number, level?: LogEntry['level']): LogEntry[]; /** * Clear logs */ clearLogs(): void; } export { MCPLogger }; export declare const logger: MCPLogger; //# sourceMappingURL=logger.d.ts.map