()
| 601 | }; |
| 602 | |
| 603 | const factory = () => { |
| 604 | const server = new McpServer({ name: serverName, version: "1.0.0" }, { capabilities: {} }); |
| 605 | const registered = server.registerTool( |
| 606 | currentToolName, |
| 607 | { |
| 608 | description: "Greets the caller", |
| 609 | inputSchema: { name: z.string() }, |
| 610 | }, |
| 611 | async ({ name }: { name: string }) => ({ |
| 612 | content: [{ type: "text" as const, text: `greeting:${name}` }], |
| 613 | }), |
| 614 | ); |
| 615 | registrations.add(registered); |
| 616 | server.registerTool( |
| 617 | "rename_greet", |
| 618 | { description: "Renames the greet tool", inputSchema: {} }, |
| 619 | async (_args, extra) => { |
| 620 | renameTool(); |
| 621 | // `RegisteredTool.update` already emitted list_changed, but with no |
| 622 | // relatedRequestId the transport routes it to the standalone GET SSE |
| 623 | // stream, which a request-scoped client may never have open. Send it |
| 624 | // through the handler's `extra` too: that stamps the request id, so |
| 625 | // the notification rides THIS call's response stream and is |
| 626 | // guaranteed to reach the caller before the tool result. |
| 627 | await extra.sendNotification({ method: "notifications/tools/list_changed" }); |
| 628 | return { content: [{ type: "text" as const, text: "renamed" }] }; |
| 629 | }, |
| 630 | ); |
| 631 | return server; |
| 632 | }; |
| 633 | |
| 634 | return { factory, renameTool, initialToolName, renamedToolName }; |
| 635 | }; |
no test coverage detected