Skip to content

Add request timeouts to Supermemory MCP client calls#1142

Draft
Dhravya wants to merge 2 commits into
mainfrom
cursor/polylane-autofix-add-request-timeouts-to-supermemory-mcp-client-calls-dbc1
Draft

Add request timeouts to Supermemory MCP client calls#1142
Dhravya wants to merge 2 commits into
mainfrom
cursor/polylane-autofix-add-request-timeouts-to-supermemory-mcp-client-calls-dbc1

Conversation

@Dhravya

@Dhravya Dhravya commented Jun 20, 2026

Copy link
Copy Markdown
Member

Problem

Outbound requests from the supermemory-mcp Durable Object to api.supermemory.ai had no client-side timeout, causing stalls of up to ~318 seconds when downstream services (Turbopuffer, Gemini) were slow. Two separate code paths were affected:

  1. SDK calls (search, add, forget, profile) — the Supermemory SDK client was constructed without a timeout option, so it defaulted to 60 seconds or whatever the underlying runtime allows.
  2. Manual fetch calls (getProjects, getDocuments) — these had no signal or AbortSignal at all, meaning they could stall indefinitely.

Changes (apps/mcp/src/client.ts)

  • FETCH_TIMEOUT_MS = 30_000 — new constant following the existing pattern in apps/api/src/services/extraction/extractors/image.ts.
  • SDK constructor — pass timeout: FETCH_TIMEOUT_MS so all SDK-backed calls are bounded to 30 seconds.
  • getProjects(options?: { signal?: AbortSignal }) — thread an AbortSignal into the fetch; defaults to AbortSignal.timeout(30_000) when no caller-supplied signal is present.
  • getDocuments(containerTags?, page?, limit?, options?: { signal?: AbortSignal }) — same pattern.
  • handleError — new guard catches AbortError / TimeoutError and surfaces a friendly "Request to Supermemory API timed out" message instead of an opaque crash, consistent with existing friendly error messages.

Assumptions

  • 30 seconds is an appropriate upper bound for MCP tool calls (matches the SDK default the plan recommended and the constant already used elsewhere in the repo).
  • Callers in server.ts do not currently have an easy per-request AbortSignal from the McpAgent/ExecutionContext, so the options parameter is left as an extension point for future use; all existing call sites pick up the default 30-second timeout automatically.
  • Pre-existing type errors in unrelated packages (@supermemory/tools, @supermemory/ai-sdk) are not caused by this change — the MCP package itself has no new type errors.
Open in Web Open in Cursor 

- Pass explicit timeout: 30_000 to the Supermemory SDK constructor so all
  SDK-backed calls (search, add, forget, profile) are bounded to 30 seconds
- Add AbortSignal.timeout(FETCH_TIMEOUT_MS) to the manual fetch calls in
  getProjects() and getDocuments() which had no timeout before
- Accept an optional { signal?: AbortSignal } argument on both methods so
  callers can thread a request-scoped signal when one is available
- Catch AbortError / TimeoutError in handleError() and surface a friendly
  'Request to Supermemory API timed out' message instead of an opaque crash
- Follow existing codebase convention (FETCH_TIMEOUT_MS constant, same value
  used in apps/api/src/services/extraction/extractors/image.ts)

Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 3693fdb Jun 20 2026, 01:16 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 3693fdb Commit Preview URL

Branch Preview URL
Jun 20 2026, 01:17 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants