()
| 487 | }; |
| 488 | |
| 489 | const factory = () => { |
| 490 | const server = new McpServer({ name: serverName, version: "1.0.0" }, { capabilities: {} }); |
| 491 | const registered = server.registerTool( |
| 492 | currentToolName, |
| 493 | { |
| 494 | description: "Greets the caller", |
| 495 | inputSchema: { name: z.string() }, |
| 496 | }, |
| 497 | async ({ name }: { name: string }) => ({ |
| 498 | content: [{ type: "text" as const, text: `greeting:${name}` }], |
| 499 | }), |
| 500 | ); |
| 501 | registrations.add(registered); |
| 502 | server.registerTool( |
| 503 | "rename_greet", |
| 504 | { description: "Renames the greet tool", inputSchema: {} }, |
| 505 | async (_args, extra) => { |
| 506 | renameTool(); |
| 507 | // `RegisteredTool.update` already emitted list_changed, but with no |
| 508 | // relatedRequestId the transport routes it to the standalone GET SSE |
| 509 | // stream, which a request-scoped client may never have open. Send it |
| 510 | // through the handler's `extra` too: that stamps the request id, so |
| 511 | // the notification rides THIS call's response stream and is |
| 512 | // guaranteed to reach the caller before the tool result. |
| 513 | await extra.sendNotification({ method: "notifications/tools/list_changed" }); |
| 514 | return { content: [{ type: "text" as const, text: "renamed" }] }; |
| 515 | }, |
| 516 | ); |
| 517 | return server; |
| 518 | }; |
| 519 | |
| 520 | return { factory, renameTool, initialToolName, renamedToolName }; |
| 521 | }; |
no test coverage detected