Add request timeouts to Supermemory MCP client calls (#1146)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
Dhravya Shah 2026-06-25 13:35:23 -07:00 committed by GitHub
parent 4ce13cd4cf
commit 886ee692f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3493 additions and 0 deletions

3480
apps/mcp/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -142,6 +142,7 @@ export class SupermemoryClient {
this.client = new Supermemory({ this.client = new Supermemory({
apiKey: bearerToken, apiKey: bearerToken,
baseURL: apiUrl, baseURL: apiUrl,
timeout: 30_000,
}) })
this.containerTag = containerTag || DEFAULT_PROJECT_ID this.containerTag = containerTag || DEFAULT_PROJECT_ID
} }
@ -336,6 +337,7 @@ export class SupermemoryClient {
Authorization: `Bearer ${this.bearerToken}`, Authorization: `Bearer ${this.bearerToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
signal: AbortSignal.timeout(30_000),
}) })
if (!response.ok) { if (!response.ok) {
@ -374,6 +376,7 @@ export class SupermemoryClient {
order: "desc", order: "desc",
containerTags, containerTags,
}), }),
signal: AbortSignal.timeout(30_000),
}) })
if (!response.ok) { if (!response.ok) {
throw Object.assign(new Error("Failed to fetch documents"), { throw Object.assign(new Error("Failed to fetch documents"), {
@ -387,6 +390,16 @@ export class SupermemoryClient {
} }
private handleError(error: unknown): never { 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 // Handle network/fetch errors
if (error instanceof TypeError) { if (error instanceof TypeError) {
if ( if (