@happyvertical/smrt-app-mcp 0.62.4 → 0.62.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-C704k8Mv.js","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["/** Machine-readable code for a principal policy denial. */\nexport const MCP_TOOL_ACCESS_DENIED_CODE = 'mcp_tool_access_denied';\n\n/** Machine-readable code for a request refused by the endpoint's origin check. */\nexport const MCP_ORIGIN_DENIED_CODE = 'mcp_origin_denied';\n\n/**\n * Metadata that is safe to expose for an app-MCP access failure. Policy\n * implementations must not place principal, scope, tool, or internal-error\n * details here.\n */\nexport interface McpAccessErrorMetadata {\n code?: string;\n retryable?: boolean;\n}\n\n/**\n * Error returned by the MCP app server when a caller tries to use a tool\n * they are not allowed to access. The HTTP layer should map `status` onto\n * the response status code.\n */\nexport class McpAccessError extends Error {\n constructor(\n readonly status: number,\n message: string,\n readonly metadata: McpAccessErrorMetadata = {},\n ) {\n super(message);\n this.name = 'McpAccessError';\n }\n}\n\n/** Stable code for a request naming a tool this server does not publish. */\nexport const MCP_TOOL_NOT_FOUND_CODE = 'mcp_tool_not_found';\n\n/** Stable code for a gated tool called without `arguments.confirm === true`. */\nexport const MCP_CONFIRM_REQUIRED_CODE = 'confirm_required';\n\n/** Stable code for a tool call that needs an authenticated principal. */\nexport const MCP_AUTHENTICATION_REQUIRED_CODE = 'mcp_authentication_required';\n\n/** Stable code for an unmapped handler failure; carries no internals. */\nexport const MCP_TOOL_EXECUTION_FAILED_CODE = 'mcp_tool_execution_failed';\n\n/** The generic message an unmapped handler failure returns. */\nexport const MCP_TOOL_EXECUTION_FAILED_MESSAGE = 'Workflow execution failed.';\n\n/** The agent-safe projection of a tool failure: a stable code and a message. */\nexport interface McpToolErrorInfo {\n code: string;\n message: string;\n /** Optional JSON-safe, non-sensitive structured detail. */\n details?: Record<string, unknown>;\n}\n\n/**\n * Throw from a workflow tool handler to hand the calling agent a typed,\n * authored failure. The `code` and `message` (and optional `details`) reach\n * the agent verbatim, so they must be safe to disclose: never put records,\n * credentials, stack traces, or other tenants' data in them. Any other\n * thrown value stays behind the generic failure message.\n */\nexport class McpToolError extends Error {\n readonly code: string;\n readonly details?: Record<string, unknown>;\n constructor(\n code: string,\n message: string,\n details?: Record<string, unknown>,\n ) {\n super(message);\n this.name = 'McpToolError';\n this.code = code;\n if (details !== undefined) this.details = details;\n }\n}\n\n/** Per-tool mapping of a handler failure to a safe code and message. */\nexport type McpToolErrorMapper = (\n error: unknown,\n) => McpToolErrorInfo | null | undefined;\n\nconst SAFE_CODE = /^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/;\nconst MAX_SAFE_MESSAGE_LENGTH = 500;\nconst MAX_SAFE_DETAILS_BYTES = 4096;\n\nconst GENERIC_TOOL_ERROR: Readonly<McpToolErrorInfo> = Object.freeze({\n code: MCP_TOOL_EXECUTION_FAILED_CODE,\n message: MCP_TOOL_EXECUTION_FAILED_MESSAGE,\n});\n\nfunction validInfo(value: unknown): McpToolErrorInfo | undefined {\n if (!value || typeof value !== 'object') return undefined;\n const { code, message, details } = value as Record<string, unknown>;\n if (typeof code !== 'string' || !SAFE_CODE.test(code)) return undefined;\n if (\n typeof message !== 'string' ||\n !message.trim() ||\n message.length > MAX_SAFE_MESSAGE_LENGTH\n ) {\n return undefined;\n }\n const info: McpToolErrorInfo = { code, message };\n if (details !== undefined) {\n try {\n if (\n !details ||\n typeof details !== 'object' ||\n Array.isArray(details) ||\n typeof JSON.stringify(details) !== 'string' ||\n JSON.stringify(details).length > MAX_SAFE_DETAILS_BYTES\n ) {\n return undefined;\n }\n info.details = JSON.parse(JSON.stringify(details));\n } catch {\n return undefined;\n }\n }\n return info;\n}\n\n/**\n * Resolve a thrown value to the information that may reach an agent. Never\n * throws: a thrown {@link McpToolError} or a valid `mapError` result yields its\n * safe code and message; anything else (including a throwing or malformed\n * mapper) yields the generic failure.\n */\nexport function safeMcpToolError(\n error: unknown,\n mapError?: McpToolErrorMapper,\n): McpToolErrorInfo {\n return authoredMcpToolError(error, mapError) ?? { ...GENERIC_TOOL_ERROR };\n}\n\n/**\n * The authored (opt-in) safe error for a thrown value: a valid\n * {@link McpToolError} or `mapError` result, else `undefined`. Only this form\n * is typed on the MCP wire; an unmapped failure keeps the generic result.\n */\nexport function authoredMcpToolError(\n error: unknown,\n mapError?: McpToolErrorMapper,\n): McpToolErrorInfo | undefined {\n try {\n if (error instanceof McpToolError) {\n const info = validInfo({\n code: error.code,\n message: error.message,\n details: error.details,\n });\n if (info) return info;\n } else if (mapError) {\n const info = validInfo(mapError(error));\n if (info) return info;\n }\n } catch {\n // A mapper failure falls back to the generic message.\n }\n return undefined;\n}\n"],"mappings":";AACO,IAAM,8BAA8B;AAGpC,IAAM,yBAAyB;AAiB/B,IAAM,iBAAN,cAA6B,MAAM;CACxC,YACW,QACT,SACS,WAAmC,CAAC,GAC7C;EACA,MAAM,OAAO;EAJJ,KAAA,SAAA;EAEA,KAAA,WAAA;EAGT,KAAK,OAAO;CACd;CANW;CAEA;AAKb;AAGO,IAAM,0BAA0B;AAGhC,IAAM,4BAA4B;AAGlC,IAAM,mCAAmC;AAGzC,IAAM,iCAAiC;AAGvC,IAAM,oCAAoC;AAiB1C,IAAM,eAAN,cAA2B,MAAM;CAC7B;CACA;CACT,YACE,MACA,SACA,SACA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,IAAI,YAAY,KAAA,GAAW,KAAK,UAAU;CAC5C;AACF;AAOA,IAAM,YAAY;AAClB,IAAM,0BAA0B;AAChC,IAAM,yBAAyB;AAE/B,IAAM,qBAAiD,OAAO,OAAO;CACnE,MAAM;CACN,SAAS;AACX,CAAC;AAED,SAAS,UAAU,OAA8C;CAC/D,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO,KAAA;CAChD,MAAM,EAAE,MAAM,SAAS,YAAY;CACnC,IAAI,OAAO,S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