Add 30-second request timeouts to SupermemoryMCP client calls

- Set timeout: 30_000 on the Supermemory SDK constructor so all SDK
  method calls (add, memories.forget, search.memories, profile) time
  out after 30 s instead of hanging indefinitely.
- Add signal: AbortSignal.timeout(30_000) to the two manual fetch
  helpers getProjects and getDocuments.
- Handle AbortError / TimeoutError in handleError so a timed-out
  request surfaces a clear message instead of propagating an unhandled
  exception into the Durable Object.

Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
This commit is contained in:
Cursor Agent 2026-06-20 21:37:42 +00:00
parent cf47d73126
commit 09047e30f0
No known key found for this signature in database

View file

@ -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 (