memory-plugin-shared MCP proxy: client-side timeout (AbortError) mislabeled as "server unreachable" in -32001 error
Summary
In examples/memory-plugin-shared/lib/mcp-proxy-core.mjs, when a request exceeds timeoutMs (default 15000 ms), the AbortError from postToMcp's AbortController falls into mapError()'s final catch-all and returns -32001 with the message:
OpenViking MCP request failed. Check the configured URL (http://127.0.0.1:1933/mcp) and that the OpenViking server (
openviking-server) is reachable.
…even when the server is healthy and actively computing. Rerank-inclusive find/search can legitimately take tens of seconds server-side (we measured 17–57 s), so on the default 15 s budget every such call reports "unreachable". This actively misdirects diagnosis — on our multi-agent deployment, timeout aborts were repeatedly misdiagnosed as outages or wiring/auth problems before the root cause was found.
Reproduce
- Use any integration built from the shared proxy (zcode / antigravity / opencode / claude variants all share
mcp-proxy-core.mjs) and setOPENVIKING_TIMEOUT_MS=2000. - Drive the proxy over stdio:
initialize, thentools/call findwith a rerank-heavy query against a populated store. - At ~2 s you get:
{"jsonrpc":"2.0","id":2,"error":{"code":-32001,"message":"OpenViking MCP request failed. Check the configured URL (http://127.0.0.1:1933/mcp) and that the OpenViking server (`openviking-server`) is reachable.","data":{"cause":"This operation was aborted"}}}
- Meanwhile
GET /healthreturns ok, and the identical call with a 60 s budget succeeds in ~30 s.
Suggested fix
Branch on AbortError before the catch-all, keeping -32001 for genuine connection failures (-32002 already covers upstream HTTP errors):
const msg = err instanceof Error ? err.message : String(err);
if (err?.name === "AbortError") {
return errorResponse(
id,
-32003,
`OpenViking MCP request timed out after ${proxyConfig.timeoutMs}ms (${proxyConfig.mcpUrl}). Server may be slow (rerank) or unreachable — check /health.`,
{ timeoutMs: proxyConfig.timeoutMs, mcpUrl: proxyConfig.mcpUrl, cause: msg },
);
}
We carry this patch locally and it separates the cases cleanly: timeout → -32003 naming the actual budget; dead endpoint (fetch failed / ECONNREFUSED) → -32001; auth failures keep the existing precise 401/403 message.
Companion (optional, happy to split out)
For thin integrations using the hook runtime, an opt-in knob would also help: OPENVIKING_RECALL_MIN_PROMPT_CHARS (default 1, preserving current behavior) in agent-hook-runtime.mjs's config block, so integrations can skip auto-recall for trivially short prompts without code changes:
recallMinPromptChars: envNumber("OPENVIKING_RECALL_MIN_PROMPT_CHARS", 1, 0),
// guard:
if (!cfg.autoRecall || String(prompt || "").trim().length < (cfg.recallMinPromptChars ?? 1)) return null;
Happy to turn either into a PR if welcome.
Thanks for the precise write-up — the suggested branch shape is exactly right, with one correction: -32003 is already taken by the proxy's "upstream returned an empty response" error, so the timeout case needs the next free code. Implemented in #4741 as -32004 with the budget and endpoint in both the message and data (timeoutMs, mcpUrl), propagated to every generated copy via sync.mjs, plus tests covering the abort case and the connection-failure contrast through the real handleMessage path.
The optional companion (OPENVIKING_RECALL_MIN_PROMPT_CHARS) was left out of #4741 to keep it focused — if the maintainers want it, it splits out cleanly.