import { isBoom } from '@hapi/boom' import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js' import { isProblemDetails, isProblemError } from '@reclaimprotocol/client/api' import { errorAsToolText } from '../tools/registry.ts' // One error shape for every MCP tool. The text comes from errorAsToolText // (shared with the cloud loop); Boom problems also attach structuredContent. export const remapErrorAsResponse = ( err: unknown, ): CallToolResult => { const text = errorAsToolText(err) const data = isProblemError(err) ? err.data : isBoom(err) && err.output?.statusCode && isProblemDetails(err.data) ? err.data : undefined if(!data) { return { isError: true as const, content: [{ type: 'text' as const, text }], } } return { isError: true as const, structuredContent: data, content: [{ type: 'text' as const, text }], } }