Merge timeout additions for supermemory-mcp (#1144)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Polylane Automation <automation@nominal.ai>
This commit is contained in:
Dhravya Shah 2026-06-29 12:28:14 -07:00 committed by GitHub
parent 1af9dbc448
commit e706a13877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 8 deletions

View file

@ -103,6 +103,7 @@ export async function validateOAuthToken(
headers: {
Authorization: `Bearer ${token}`,
},
signal: AbortSignal.timeout(30_000),
})
if (!sessionResponse.ok) {

View file

@ -2,6 +2,7 @@ import Supermemory from "supermemory"
const MAX_CHARS = 200000 // ~50k tokens (character-based limit)
const DEFAULT_PROJECT_ID = "sm_project_default"
const FETCH_TIMEOUT_MS = 30_000
interface MemoryRichFields {
metadata?: Record<string, unknown> | null
@ -142,7 +143,7 @@ export class SupermemoryClient {
this.client = new Supermemory({
apiKey: bearerToken,
baseURL: apiUrl,
timeout: 30_000,
timeout: FETCH_TIMEOUT_MS,
})
this.containerTag = containerTag || DEFAULT_PROJECT_ID
}
@ -329,15 +330,16 @@ export class SupermemoryClient {
}
// Get projects list
async getProjects(): Promise<string[]> {
async getProjects(options?: { signal?: AbortSignal }): Promise<string[]> {
try {
const signal = options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS)
const response = await fetch(`${this.apiUrl}/v3/projects`, {
method: "GET",
headers: {
Authorization: `Bearer ${this.bearerToken}`,
"Content-Type": "application/json",
},
signal: AbortSignal.timeout(30_000),
signal,
})
if (!response.ok) {
@ -361,8 +363,10 @@ export class SupermemoryClient {
containerTags?: string[],
page = 1,
limit = 10,
options?: { signal?: AbortSignal },
): Promise<DocumentsApiResponse> {
try {
const signal = options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS)
const response = await fetch(`${this.apiUrl}/v3/documents/documents`, {
method: "POST",
headers: {
@ -376,7 +380,7 @@ export class SupermemoryClient {
order: "desc",
containerTags,
}),
signal: AbortSignal.timeout(30_000),
signal,
})
if (!response.ok) {
throw Object.assign(new Error("Failed to fetch documents"), {
@ -390,14 +394,12 @@ export class SupermemoryClient {
}
private handleError(error: unknown): never {
// Handle request timeout / abort
// Handle request timeout (AbortSignal.timeout or explicit 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.",
)
throw new Error("Request to Supermemory API timed out")
}
// Handle network/fetch errors

View file

@ -89,6 +89,7 @@ app.get("/.well-known/oauth-authorization-server", async (c) => {
// Fetch the authorization server metadata from the main API
const response = await fetch(
`${apiUrl}/.well-known/oauth-authorization-server`,
{ signal: AbortSignal.timeout(30_000) },
)
if (!response.ok) {