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