Skip to content

Commit 818a48c

Browse files
glassBead-tcclaude
andcommitted
fix(server): use relatedRequestId for listRoots
Replace sendRequest + Promise.race timeout with explicit relatedRequestId passed to server.server.listRoots(). Routes through the active POST response stream instead of the standalone GET SSE stream. Eliminates the unhandled rejection from the timeout promise (Greptile P1) and the unnecessary dynamic import. See: modelcontextprotocol/typescript-sdk#1167 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 09b1925 commit 818a48c

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

‎src/server-factory.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Use \`console.log()\` for debugging — output captured in response logs.`;
308308
// Auto-resolve project scope from MCP roots (or THOUGHTBOX_PROJECT env var)
309309
// Deferred: transport isn't connected during createMcpServer()
310310
let projectResolved = false;
311-
const resolveProject = async (extra?: { sendRequest: (...a: any[]) => Promise<any> }) => {
311+
const resolveProject = async (requestId?: string | number) => {
312312
if (projectResolved) return;
313313
projectResolved = true;
314314
const envProject = process.env.THOUGHTBOX_PROJECT;
@@ -324,18 +324,13 @@ Use \`console.log()\` for debugging — output captured in response logs.`;
324324
return;
325325
}
326326
try {
327-
// Use extra.sendRequest (routes through the active POST response stream
328-
// via relatedRequestId) rather than server.server.listRoots() which tries
329-
// a standalone SSE channel that hangs over streamable HTTP.
330-
// See: modelcontextprotocol/typescript-sdk#1167
331-
const { ListRootsResultSchema } = await import('@modelcontextprotocol/sdk/types.js');
332-
const timeout = new Promise<never>((_, reject) =>
333-
setTimeout(() => reject(new Error('listRoots timed out')), 3000),
334-
);
335-
const listRoots = extra?.sendRequest
336-
? extra.sendRequest({ method: 'roots/list' }, ListRootsResultSchema)
337-
: server.server.listRoots();
338-
const { roots } = await Promise.race([listRoots, timeout]);
327+
// Pass relatedRequestId so the transport routes through the active
328+
// POST response stream instead of the standalone GET SSE stream,
329+
// which hangs over streamable HTTP (typescript-sdk#1167).
330+
const options = requestId !== undefined
331+
? { relatedRequestId: requestId }
332+
: undefined;
333+
const { roots } = await server.server.listRoots(undefined, options);
339334
if (roots.length > 0) {
340335
const root = roots[0];
341336
const name = root.name
@@ -365,7 +360,7 @@ Use \`console.log()\` for debugging — output captured in response logs.`;
365360
annotations: toolDef.annotations,
366361
},
367362
async (args: any, extra: any) => {
368-
await resolveProject(extra);
363+
await resolveProject(extra.requestId);
369364
try {
370365
const result = await toolInstance.handle(args as any);
371366
if (result && Array.isArray(result.content)) {

0 commit comments

Comments
 (0)