mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-26 07:44:05 +00:00
fix(ruvocal): MCP SSE auto-reconnect on stale session (404/connection errors)
- Widen isConnectionClosedError to catch 404, fetch failed, ECONNRESET - Add transport readyState check in clientPool for dead connections - Retry logic now triggers reconnection on stale SSE sessions Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
53b567acd2
commit
426f3bbda7
2 changed files with 24 additions and 2 deletions
|
|
@ -16,7 +16,19 @@ function keyOf(server: McpServerConfig) {
|
|||
export async function getClient(server: McpServerConfig, signal?: AbortSignal): Promise<Client> {
|
||||
const key = keyOf(server);
|
||||
const existing = pool.get(key);
|
||||
if (existing) return existing;
|
||||
if (existing) {
|
||||
// Verify the cached client is still alive by checking transport state
|
||||
try {
|
||||
// If the transport is closed/errored, evict and reconnect
|
||||
if ((existing as unknown as { _transport?: { readyState?: number } })._transport?.readyState === 2) {
|
||||
pool.delete(key);
|
||||
} else {
|
||||
return existing;
|
||||
}
|
||||
} catch {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
let firstError: unknown;
|
||||
const client = new Client({ name: "chat-ui-mcp", version: "0.1.0" });
|
||||
|
|
|
|||
|
|
@ -4,7 +4,17 @@ import { config } from "$lib/server/config";
|
|||
|
||||
function isConnectionClosedError(err: unknown): boolean {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
return message.includes("-32000") || message.toLowerCase().includes("connection closed");
|
||||
const lower = message.toLowerCase();
|
||||
return (
|
||||
message.includes("-32000") ||
|
||||
lower.includes("connection closed") ||
|
||||
lower.includes("404") ||
|
||||
lower.includes("not found") ||
|
||||
lower.includes("session") ||
|
||||
lower.includes("fetch failed") ||
|
||||
lower.includes("econnreset") ||
|
||||
lower.includes("econnrefused")
|
||||
);
|
||||
}
|
||||
|
||||
export interface McpServerConfig {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue