()
| 547 | }; |
| 548 | |
| 549 | const factory = () => { |
| 550 | const server = new McpServer({ name: serverName, version: "1.0.0" }, { capabilities: {} }); |
| 551 | const registered = server.registerTool( |
| 552 | currentToolName, |
| 553 | { |
| 554 | description: "Greets the caller", |
| 555 | inputSchema: { name: z.string() }, |
| 556 | }, |
| 557 | async ({ name }: { name: string }) => ({ |
| 558 | content: [{ type: "text" as const, text: `greeting:${name}` }], |
| 559 | }), |
| 560 | ); |
| 561 | registrations.add(registered); |
| 562 | server.registerTool( |
| 563 | "rename_greet", |
| 564 | { description: "Renames the greet tool", inputSchema: {} }, |
| 565 | async (_args, extra) => { |
| 566 | renameTool(); |
| 567 | // `RegisteredTool.update` already emitted list_changed, but with no |
| 568 | // relatedRequestId the transport routes it to the standalone GET SSE |
| 569 | // stream, which a request-scoped client may never have open. Send it |
| 570 | // through the handler's `extra` too: that stamps the request id, so |
| 571 | // the notification rides THIS call's response stream and is |
| 572 | // guaranteed to reach the caller before the tool result. |
| 573 | await extra.sendNotification({ method: "notifications/tools/list_changed" }); |
| 574 | return { content: [{ type: "text" as const, text: "renamed" }] }; |
| 575 | }, |
| 576 | ); |
| 577 | return server; |
| 578 | }; |
| 579 | |
| 580 | return { factory, renameTool, initialToolName, renamedToolName }; |
| 581 | }; |
no test coverage detected