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

Function connectionFailure

packages/plugins/mcp/src/sdk/connection.ts:433–476  ·  view source on GitHub ↗
(
  transport: string,
  message: string,
  cause: unknown,
)

Source from the content-addressed store, hash-verified

431});
432
433const connectionFailure = (
434 transport: string,
435 message: string,
436 cause: unknown,
437): McpConnectionError | McpOAuthReauthorizationRequired => {
438 if (hasNestedOAuthReauthorization(cause)) {
439 return new McpOAuthReauthorizationRequired({ message: "MCP OAuth re-authorization required" });
440 }
441 if (Predicate.isTagged(cause, "McpInsufficientScopeError")) {
442 // Surfaced as a connection error with the 403 status; the invoke/connect
443 // catch sites detect the tag and classify as oauth_scope_insufficient.
444 return new McpConnectionError({
445 transport,
446 message: `${message} (HTTP 403: insufficient scope)`,
447 httpStatus: 403,
448 insufficientScope: true,
449 });
450 }
451 const httpTransportError = nestedMcpHttpTransportError(cause);
452 if (Option.isSome(httpTransportError)) {
453 return new McpConnectionError({
454 transport,
455 message: CONNECTION_FAILURE_MESSAGES[httpTransportError.value.failureKind],
456 failureKind: httpTransportError.value.failureKind,
457 });
458 }
459 // Carry the handshake HTTP status structurally (and in the message for
460 // humans) so the liveness health check can classify a rejected credential
461 // as expired rather than a generic connection failure.
462 const status = connectionHttpStatusFromCause(cause);
463 const failureKind: McpConnectionFailureKind =
464 isStreamableHttpProtocolError(cause) ||
465 (status !== undefined && PROTOCOL_HTTP_STATUSES.has(status))
466 ? "protocol"
467 : status === undefined
468 ? "network"
469 : "http";
470 return new McpConnectionError({
471 transport,
472 message: status === undefined ? message : `${message} (HTTP ${status})`,
473 failureKind,
474 ...(status === undefined ? {} : { httpStatus: status }),
475 });
476};
477
478const connectionAttemptSummary = (failure: McpConnectionError): string => {
479 if (failure.httpStatus !== undefined) return `HTTP ${failure.httpStatus}`;

Callers 1

connectClientFunction · 0.85

Tested by

no test coverage detected