MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / toMcpFailureResult

Function toMcpFailureResult

packages/hosts/mcp/src/tool-server.ts:674–701  ·  view source on GitHub ↗
(cause: Cause.Cause<unknown>)

Source from the content-addressed store, hash-verified

672});
673
674const toMcpFailureResult = (cause: Cause.Cause<unknown>): McpToolResult => {
675 const correlationId = newCorrelationId();
676 const defect = Cause.findDefect(cause);
677 const nativeElicitationFailed =
678 Result.isSuccess(defect) &&
679 Predicate.isTagged("McpNativeElicitationTransportError")(defect.success);
680 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: best-effort defect logging must tolerate non-serializable causes
681 try {
682 console.error(
683 `[executor:mcp] execute defect correlation_id=${correlationId}`,
684 Cause.pretty(cause),
685 );
686 } catch {
687 /* ignore logger failures */
688 }
689 const text = nativeElicitationFailed
690 ? `Native elicitation transport failed [${correlationId}]. Reconnect the MCP client and try again.`
691 : `Internal tool error [${correlationId}]`;
692 return {
693 content: [{ type: "text", text: `Error: ${text}` }],
694 structuredContent: {
695 status: "error",
696 error: text,
697 ...(nativeElicitationFailed ? { errorCode: "native_elicitation_transport_failed" } : {}),
698 },
699 isError: true,
700 };
701};
702
703const recoveryText =
704 "To recover, run the execute tool again with the original code; if it pauses, a fresh executionId will be issued.";

Callers 1

runToolEffectFunction · 0.85

Calls 2

errorMethod · 0.80
newCorrelationIdFunction · 0.70

Tested by

no test coverage detected