diff --git a/apps/mcp/src/client.ts b/apps/mcp/src/client.ts index ee35fcf1..1a405979 100644 --- a/apps/mcp/src/client.ts +++ b/apps/mcp/src/client.ts @@ -142,6 +142,7 @@ export class SupermemoryClient { this.client = new Supermemory({ apiKey: bearerToken, baseURL: apiUrl, + timeout: 30_000, }) this.containerTag = containerTag || DEFAULT_PROJECT_ID } @@ -336,6 +337,7 @@ export class SupermemoryClient { Authorization: `Bearer ${this.bearerToken}`, "Content-Type": "application/json", }, + signal: AbortSignal.timeout(30_000), }) if (!response.ok) { @@ -374,6 +376,7 @@ export class SupermemoryClient { order: "desc", containerTags, }), + signal: AbortSignal.timeout(30_000), }) if (!response.ok) { throw Object.assign(new Error("Failed to fetch documents"), { @@ -387,6 +390,16 @@ export class SupermemoryClient { } private handleError(error: unknown): never { + // Handle request timeout / abort + if ( + error instanceof Error && + (error.name === "AbortError" || error.name === "TimeoutError") + ) { + throw new Error( + "Request timed out after 30 seconds. The service may be slow or unavailable. Please try again.", + ) + } + // Handle network/fetch errors if (error instanceof TypeError) { if (