{"record":{"id":"6bcd4d42337c9ff4","repo":"vercel/ai","slug":"mcp-client-initialization-was-aborted","errorCode":null,"errorMessage":"MCP client initialization was aborted","messagePattern":"MCP client initialization was aborted","errorType":"exception","errorClass":"MCPClientError","httpStatus":null,"severity":"warning","filePath":"packages/mcp/src/tool/mcp-client.ts","lineNumber":595,"sourceCode":"        {\n          method: 'notifications/initialized',\n        },\n        { signal },\n      );\n\n      return this;\n    } catch (error) {\n      try {\n        await waitForAbort(this.transport.close({ signal }), signal);\n      } catch {}\n      this.onClose();\n\n      if (timeoutError != null) {\n        throw timeoutError;\n      }\n\n      if (externalSignal?.aborted) {\n        throw new MCPClientError({\n          message: 'MCP client initialization was aborted',\n          cause: externalSignal.reason,\n        });\n      }\n\n      throw error;\n    } finally {\n      if (timeoutId != null) {\n        clearTimeout(timeoutId);\n      }\n    }\n  }\n\n  private async tryProtocolDiscovery(\n    signal: AbortSignal | undefined,\n  ): Promise<boolean> {\n    this.protocolEra = 'modern';\n    this.protocolVersion = LATEST_PROTOCOL_VERSION;","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mcp/src/tool/mcp-client.ts#L577-L613","documentation":"Thrown in the init catch path when the external AbortSignal passed to createMCPClient was aborted during initialization. The client re-wraps the abort as MCPClientError with the signal's reason as cause, after the transport is closed.","triggerScenarios":"Caller-supplied AbortSignal fires while the initialize handshake/discovery request is in flight; e.g. a request timeout, user navigation, or explicit abortController.abort() during client creation.","commonSituations":"React effect cleanups aborting in-flight client creation; server taking longer than a caller-imposed timeout; user navigating away; request cancellations in serverless functions.","solutions":["Catch MCPClientError and treat message 'MCP client initialization was aborted' as an expected cancellation, not a server failure.","Increase the timeout if the abort is from your own deadline and the server is slow to initialize.","Check error.cause (the signal reason) to identify who aborted.","Avoid aborting the signal during setup, or retry creation after the abort reason is resolved."],"exampleFix":"// before\nconst client = await createMCPClient({ transport, signal: controller.signal });\n// after\ntry {\n  const client = await createMCPClient({ transport, signal: controller.signal });\n} catch (e) {\n  if (MCPClientError.isInstance(e) && e.message.includes('aborted')) return; // expected cancellation\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (controller.signal.aborted) {\n  return; // do not start client creation with an already-aborted signal\n}","typeGuard":"function isAbortError(e: unknown): boolean {\n  return e instanceof Error && (e.name === 'AbortError' || e.message.includes('aborted'));\n}","tryCatchPattern":"try {\n  const client = await createMCPClient({ transport, signal: controller.signal });\n} catch (e) {\n  if (MCPClientError.isInstance(e) && e.message === 'MCP client initialization was aborted') {\n    return; // expected cancellation, use e.cause to see why\n  }\n  throw e;\n}","preventionTips":["Don't abort the signal during client setup unless cancellation is intended","Give initialization a generous timeout if servers start slowly","Check e.cause to distinguish user cancellation from timeouts"],"tags":["mcp","abort","cancellation","timeout"],"backgroundTag":"operation-aborted","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}