Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(memory-plugins): report client-side MCP proxy timeouts as -32004 instead of unreachable (#4741)

now-ingf7c6e843860e
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index e43589824..3462f58c6 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -71,6 +71,7 @@ jobs:
examples/memory-plugin-shared/setup-wizard.test.mjs \
examples/memory-plugin-shared/sync.test.mjs \
examples/memory-plugin-shared/mcp-proxy-config.test.mjs \
+ examples/memory-plugin-shared/mcp-proxy-core.test.mjs \
examples/memory-plugin-shared/recall-compress-core.test.mjs \
examples/memory-plugin-shared/recall-core.test.mjs \
examples/memory-plugin-shared/recall-session-wiring.test.mjs \
diff --git a/agent-plugins/servers/shared/mcp-proxy-core.mjs b/agent-plugins/servers/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/agent-plugins/servers/shared/mcp-proxy-core.mjs
+++ b/agent-plugins/servers/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs b/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
+++ b/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
index 8c978779c..25e1f7198 100644
--- a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
+++ b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
@@ -291,6 +291,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/memory-plugin-shared/mcp-proxy-core.test.mjs b/examples/memory-plugin-shared/mcp-proxy-core.test.mjs
new file mode 100644
index 000000000..2b59de6ab
--- /dev/null
+++ b/examples/memory-plugin-shared/mcp-proxy-core.test.mjs
@@ -0,0 +1,76 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { createOpenVikingMcpProxy } from "./lib/mcp-proxy-core.mjs";
+
+function buildHarness({ fetchImpl, timeoutMs = 40 }) {
+ const lines = [];
+ const stdout = {
+ write(line, cb) {
+ lines.push(line);
+ if (cb) cb();
+ return true;
+ },
+ };
+ const proxy = createOpenVikingMcpProxy({
+ stdin: process.stdin,
+ stdout,
+ fetchImpl,
+ readConfig: () => ({
+ mcpUrl: "http://127.0.0.1:1933/mcp",
+ timeoutMs,
+ watchedPaths: [],
+ }),
+ loggerFactory: () => ({ log() {}, logError() {} }),
+ });
+ const responses = () => lines.map((l) => JSON.parse(l));
+ const send = (obj) => proxy.handleMessage(obj);
+ const waitFor = async (predicate, label) => {
+ for (let i = 0; i < 100; i++) {
+ const found = responses().find(predicate);
+ if (found) return found;
+ await new Promise((r) => setTimeout(r, 20));
+ }
+ throw new Error(`timed out waiting for ${label}; got: ${lines.join("|")}`);
+ };
+ return { proxy, send, waitFor, responses };
+}
+
+test("an aborted request maps to -32004 naming the timeout budget", async () => {
+ const harness = buildHarness({
+ // Stalls until aborted, like a real signal-aware fetch against a slow server.
+ fetchImpl: (_url, { signal } = {}) =>
+ new Promise((_resolve, reject) => {
+ signal.addEventListener("abort", () => {
+ const err = new Error("This operation was aborted");
+ err.name = "AbortError";
+ reject(err);
+ });
+ }),
+ timeoutMs: 40,
+ });
+ harness.send({ jsonrpc: "2.0", id: 7, method: "initialize", params: {} });
+ const res = await harness.waitFor(
+ (m) => m.id === 7 && m.error,
+ "timeout error response",
+ );
+ assert.equal(res.error.code, -32004);
+ assert.match(res.error.message, /timed out after 40ms/);
+ assert.match(res.error.message, /OPENVIKING_TIMEOUT_MS/);
+ assert.equal(res.error.data.timeoutMs, 40);
+ assert.equal(res.error.data.mcpUrl, "http://127.0.0.1:1933/mcp");
+});
+
+test("a genuine connection failure still maps to -32001", async () => {
+ const harness = buildHarness({
+ fetchImpl: () => {
+ throw new TypeError("fetch failed");
+ },
+ });
+ harness.send({ jsonrpc: "2.0", id: 8, method: "initialize", params: {} });
+ const res = await harness.waitFor(
+ (m) => m.id === 8 && m.error,
+ "connection error response",
+ );
+ assert.equal(res.error.code, -32001);
+ assert.match(res.error.message, /reachable/);
+});
diff --git a/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs b/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
+++ b/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,
diff --git a/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 93d071da7..9a8f5ba26 100644
--- a/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -292,6 +292,18 @@ export function createOpenVikingMcpProxy({
);
}
const msg = err instanceof Error ? err.message : String(err);
+ if (err && err.name === "AbortError") {
+ // Client-side timeout, not an outage: the server may be healthy and
+ // still computing (rerank-inclusive find/search can legitimately take
+ // longer than the default budget). Keep -32001 for genuine
+ // connection failures so the two are not misdiagnosed as each other.
+ return errorResponse(
+ id,
+ -32004,
+ `OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). The server may still be processing (rerank can be slow) — check /health or raise OPENVIKING_TIMEOUT_MS.`,
+ { timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
+ );
+ }
return errorResponse(
id,
-32001,