()
| 639 | }; |
| 640 | |
| 641 | const factory = () => { |
| 642 | const server = new McpServer({ name: serverName, version: "1.0.0" }, { capabilities: {} }); |
| 643 | const registered = server.registerTool( |
| 644 | currentToolName, |
| 645 | { |
| 646 | description: "Greets the caller", |
| 647 | inputSchema: { name: z.string() }, |
| 648 | }, |
| 649 | async ({ name }: { name: string }) => ({ |
| 650 | content: [{ type: "text" as const, text: `greeting:${name}` }], |
| 651 | }), |
| 652 | ); |
| 653 | registrations.add(registered); |
| 654 | server.registerTool( |
| 655 | "rename_greet", |
| 656 | { description: "Renames the greet tool", inputSchema: {} }, |
| 657 | async (_args, extra) => { |
| 658 | renameTool(); |
| 659 | // `RegisteredTool.update` already emitted list_changed, but with no |
| 660 | // relatedRequestId the transport routes it to the standalone GET SSE |
| 661 | // stream, which a request-scoped client may never have open. Send it |
| 662 | // through the handler's `extra` too: that stamps the request id, so |
| 663 | // the notification rides THIS call's response stream and is |
| 664 | // guaranteed to reach the caller before the tool result. |
| 665 | await extra.sendNotification({ method: "notifications/tools/list_changed" }); |
| 666 | return { content: [{ type: "text" as const, text: "renamed" }] }; |
| 667 | }, |
| 668 | ); |
| 669 | return server; |
| 670 | }; |
| 671 | |
| 672 | return { factory, renameTool, initialToolName, renamedToolName }; |
| 673 | }; |
no test coverage detected