()
| 512 | }; |
| 513 | |
| 514 | const factory = () => { |
| 515 | const server = new McpServer({ name: serverName, version: "1.0.0" }, { capabilities: {} }); |
| 516 | const registered = server.registerTool( |
| 517 | currentToolName, |
| 518 | { |
| 519 | description: "Greets the caller", |
| 520 | inputSchema: { name: z.string() }, |
| 521 | }, |
| 522 | async ({ name }: { name: string }) => ({ |
| 523 | content: [{ type: "text" as const, text: `greeting:${name}` }], |
| 524 | }), |
| 525 | ); |
| 526 | registrations.add(registered); |
| 527 | server.registerTool( |
| 528 | "rename_greet", |
| 529 | { description: "Renames the greet tool", inputSchema: {} }, |
| 530 | async (_args, extra) => { |
| 531 | renameTool(); |
| 532 | // `RegisteredTool.update` already emitted list_changed, but with no |
| 533 | // relatedRequestId the transport routes it to the standalone GET SSE |
| 534 | // stream, which a request-scoped client may never have open. Send it |
| 535 | // through the handler's `extra` too: that stamps the request id, so |
| 536 | // the notification rides THIS call's response stream and is |
| 537 | // guaranteed to reach the caller before the tool result. |
| 538 | await extra.sendNotification({ method: "notifications/tools/list_changed" }); |
| 539 | return { content: [{ type: "text" as const, text: "renamed" }] }; |
| 540 | }, |
| 541 | ); |
| 542 | return server; |
| 543 | }; |
| 544 | |
| 545 | return { factory, renameTool, initialToolName, renamedToolName }; |
| 546 | }; |
no test coverage detected