/** * MCP Response Formatters * * Provides helpers for formatting MCP tool responses. * Includes structured error classification and logging for tool handlers. */ export interface McpContent { type: "text"; text: string; } export interface McpResponse { [key: string]: unknown; content: McpContent[]; isError: boolean; } /** * Return type for MCP tool handler functions. * Structurally identical to McpResponse — extracted here to avoid duplication * across tool modules (task.ts, sync.ts, learning.ts). */ export type McpToolResult = McpResponse; export interface StructuredError { errorType: string; message: string; stack: string; tool: string; args: Record; timestamp: string; } /** * Safely stringify a value, handling circular references. * Circular references are replaced with "[Circular]". */ export declare const safeStringify: (value: unknown) => string; /** * Extract the error type tag from an error. * Effect-TS tagged errors have a `_tag` property. * Falls back to the constructor name or "UnknownError". */ export declare const classifyError: (error: unknown) => string; /** * Extract the error message from an error value. */ export declare const extractErrorMessage: (error: unknown) => string; /** * Format an error with its full stack trace preserved. * Handles Error instances, Effect-TS tagged errors, and arbitrary thrown values. * * - Effect-TS tagged errors: replaces generic "Error" header with _tag + message, preserves stack * - Error instances: uses `.stack` (which includes name + message + trace) * - Objects without stack: uses classifyError + extractErrorMessage + safeStringify * - Primitives: converts to string */ export declare const formatErrorWithStack: (error: unknown) => string; /** * Format a successful MCP response with text summary and JSON data. */ export declare const mcpResponse: (text: string, data: unknown) => McpResponse; /** * Format an error MCP response with structured error data. */ export declare const mcpError: (error: unknown) => McpResponse; /** * Build a structured error object with full context. */ export declare const buildStructuredError: (tool: string, args: Record, error: unknown) => StructuredError; /** * Log a structured error to stderr. * MCP uses stdio for protocol communication so stderr is the correct channel. */ export declare const logToolError: (structured: StructuredError) => void; /** * Handle a tool error: log structured context to stderr and return * a structured MCP error response with error type and details. * * Use this in tool handler catch blocks instead of inline error formatting. */ export declare const handleToolError: (tool: string, args: Record, error: unknown) => McpResponse; //# sourceMappingURL=response.d.ts.map