You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// New initialization request - create a new server instance for this session
422
+
constsessionServer=newMcpServer({
423
+
name: serverName,
424
+
version: serverVersion,
425
+
},{
426
+
capabilities: {
427
+
tools: {},
428
+
},
429
+
});
430
+
431
+
// Add the query_documentation tool to this server instance using the shared handler
432
+
sessionServer.tool(
433
+
"query_documentation",
434
+
"Query documentation stored in a sqlite-vec database using vector search.",
435
+
{
436
+
queryText: z.string().min(1).describe("The natural language query to search for."),
437
+
productName: z.string().min(1).describe("The name of the product documentation database to search within (e.g., 'my-product'). Corresponds to the DB filename without .db."),
438
+
version: z.string().optional().describe("The specific version of the product documentation (e.g., '1.2.0'). Optional."),
439
+
limit: z.number().int().positive().optional().default(4).describe("Maximum number of results to return. Defaults to 4."),
440
+
},
441
+
queryDocumentationToolHandler
442
+
);
443
+
417
444
transport=newStreamableHTTPServerTransport({
418
445
sessionIdGenerator: ()=>randomUUID(),
419
446
onsessioninitialized: (sessionId: string)=>{
420
-
// Store the transport by session ID when session is initialized
447
+
// Store the transport and server by session ID when session is initialized
421
448
console.error(`Session initialized with ID: ${sessionId}`);
422
449
transports.set(sessionId,transport);
450
+
servers.set(sessionId,sessionServer);
423
451
}
424
452
});
425
453
426
-
// Set up onclose handler to clean up transport when closed
454
+
// Set up onclose handler to clean up transport and server when closed
427
455
transport.onclose=async()=>{
428
456
constsid=transport.sessionId;
429
457
if(sid&&transports.has(sid)){
430
-
console.error(`Transport closed for session ${sid}, removing from transports map`);
458
+
console.error(`Transport closed for session ${sid}, removing from transports and servers map`);
431
459
transports.delete(sid);
460
+
servers.delete(sid);
432
461
}
433
462
};
434
463
435
-
// Connect the transport to the MCP server BEFORE handling the request
436
-
awaitserver.connect(transport);
464
+
// Connect the transport to the session-specific MCP s
465
+
// erver BEFORE handling the request
466
+
awaitsessionServer.connect(transport);
437
467
438
468
awaittransport.handleRequest(req,res);
439
469
return;// Already handled
@@ -549,12 +579,12 @@ async function main() {
549
579
550
580
// Handle server shutdown with proper SIGTERM/SIGINT support and timeout
0 commit comments