Skip to content

Commit 0198b49

Browse files
glassBead-tcclaude
andcommitted
fix(server): add 3s timeout to listRoots to prevent 300s hang
server.listRoots() hangs indefinitely over streamable HTTP due to MCP SDK bug (modelcontextprotocol/typescript-sdk#1167, open since Nov 2025). Every first tool call on Cloud Run blocked for 300s. Wrap in Promise.race with 3s timeout — project resolution from roots fails fast and falls through gracefully. Workspace isolation via API key is unaffected. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 618768d commit 0198b49

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/server-factory.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ Use \`console.log()\` for debugging — output captured in response logs.`;
324324
return;
325325
}
326326
try {
327-
const { roots } = await server.server.listRoots();
327+
const timeout = new Promise((_, reject) =>
328+
setTimeout(() => reject(new Error('listRoots timed out')), 3000),
329+
);
330+
const { roots } = await Promise.race([
331+
server.server.listRoots(),
332+
timeout,
333+
]) as { roots: Array<{ uri: string; name?: string }> };
328334
if (roots.length > 0) {
329335
const root = roots[0];
330336
const name = root.name

0 commit comments

Comments
 (0)