/** * Tool handler wrapper factory — error sanitization, structured error responses, * and automatic `extractFields` projection on success. * * Each consumer MCP server has its own auth/error class shapes; pass them via * `errorExtractors`. The shared core handles MCP response shaping + redaction. */ export type ToolTextResult = { content: Array<{ type: "text"; text: string; }>; isError?: boolean; }; export type StructuredError = Record & { message: string; }; /** * Result returned by an `ErrorExtractor`. * - `structured`: build a JSON-stringified MCP error response (sanitized by default). * - `passthrough`: return the raw text as-is, no JSON wrap, no sanitization. * Use for cases where the message is already safe and JSON wrapping would * degrade UX (e.g. `WriteBlockedError`). */ export type ErrorHandling = { kind: "structured"; data: StructuredError; sanitize?: boolean; } | { kind: "passthrough"; text: string; }; export interface ErrorExtractor { match: (error: unknown) => boolean; extract: (error: unknown) => ErrorHandling; } export interface CreateWrapToolHandlerOptions { /** * Regex patterns merged with `DEFAULT_REDACTION_PATTERNS`. Matches are replaced * with `[REDACTED]` in error messages and structured error string fields. */ redactionPatterns?: RegExp[]; /** * Ordered list of custom error extractors. The first matching extractor wins. * Falls back to a generic `{ message: error.message }` shape when none match. */ errorExtractors?: ErrorExtractor[]; /** Param name read for auto field projection on success. Default: `extractFields`. */ extractFieldsParam?: string; } /** Common secret patterns redacted by default. */ export declare const DEFAULT_REDACTION_PATTERNS: readonly RegExp[]; /** * Build a wrapToolHandler tailored to a consumer MCP server. * * @example * ```ts * const wrapToolHandler = createWrapToolHandler({ * redactionPatterns: [/DD_API_KEY/i], * errorExtractors: [ * { * match: (e) => e instanceof WriteBlockedError, * extract: (e) => ({ kind: "passthrough", text: (e as Error).message }), * }, * { * match: (e) => e instanceof DatadogApiError, * extract: (e) => { * const err = e as DatadogApiError; * return { kind: "structured", data: { message: err.message, status: err.code } }; * }, * }, * ], * }); * ``` */ export declare function createWrapToolHandler(opts?: CreateWrapToolHandlerOptions): (fn: (params: T) => Promise) => (params: T) => Promise; /** Default-configured wrapper — uses only built-in redaction patterns. */ export declare const wrapToolHandler: (fn: (params: T) => Promise) => (params: T) => Promise; //# sourceMappingURL=wrap-tool-handler.d.ts.map