MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / factory

Function factory

packages/plugins/mcp/src/testing/server.ts:561–590  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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};

Callers 5

evaluateComponentFunction · 0.85
applyFactoryFunction · 0.85
handleMcpRequestFunction · 0.85
resolveTargetFunction · 0.85

Calls 1

renameToolFunction · 0.85

Tested by

no test coverage detected