Skip to content

Commit ae1e7a5

Browse files
committed
Fix #3234 -
"Everything Server crashes when multiple clients reconnect" * In index.ts - added a variable to hold the initialize timeout - store the timeout in the oninitialized handler - clear the timeout in the cleanup callback * In roots.ts - In the catch block of syncRoots, log the error to the console via .error rather than attempting to send to the client because the most probable case here is that we don't have a connection.
1 parent 9ade571 commit ae1e7a5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/everything/server/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const createServer: () => ServerFactoryResponse = () => {
4040
const taskStore = new InMemoryTaskStore();
4141
const taskMessageQueue = new InMemoryTaskMessageQueue();
4242

43+
let initializeTimeout: NodeJS.Timeout | null = null;
44+
4345
// Create the server
4446
const server = new McpServer(
4547
{
@@ -98,7 +100,7 @@ export const createServer: () => ServerFactoryResponse = () => {
98100
// This is delayed until after the `notifications/initialized` handler finishes,
99101
// otherwise, the request gets lost.
100102
const sessionId = server.server.transport?.sessionId;
101-
setTimeout(() => syncRoots(server, sessionId), 350);
103+
initializeTimeout = setTimeout(() => syncRoots(server, sessionId), 350);
102104
};
103105

104106
// Return the ServerFactoryResponse
@@ -110,6 +112,7 @@ export const createServer: () => ServerFactoryResponse = () => {
110112
stopSimulatedResourceUpdates(sessionId);
111113
// Clean up task store timers
112114
taskStore.cleanup();
115+
if (initializeTimeout) clearTimeout(initializeTimeout);
113116
},
114117
} satisfies ServerFactoryResponse;
115118
};

src/everything/server/roots.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,10 @@ export const syncRoots = async (server: McpServer, sessionId?: string) => {
6363
);
6464
}
6565
} catch (error) {
66-
await server.sendLoggingMessage(
67-
{
68-
level: "error",
69-
logger: "everything-server",
70-
data: `Failed to request roots from client: ${
71-
error instanceof Error ? error.message : String(error)
72-
}`,
73-
},
74-
sessionId
66+
console.error(
67+
`Failed to request roots from client ${sessionId}: ${
68+
error instanceof Error ? error.message : String(error)
69+
}`
7570
);
7671
}
7772
};

0 commit comments

Comments
 (0)