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

Function withClient

packages/hosts/mcp/src/tool-server.test.ts:47–68  ·  view source on GitHub ↗
(
  engine: ExecutionEngine<E>,
  capabilities: ClientCapabilities,
  fn: (client: Client) => Promise<void>,
  config?: Pick<
    ExecutorMcpServerConfig<E>,
    "debug" | "elicitationMode" | "browserApprovalStore" | "pausedExecutionHooks"
  >,
)

Source from the content-addressed store, hash-verified

45
46/** Connect a real MCP Client to our executor MCP server over in-memory transports. */
47const withClient = async <E extends Cause.YieldableError>(
48 engine: ExecutionEngine<E>,
49 capabilities: ClientCapabilities,
50 fn: (client: Client) => Promise<void>,
51 config?: Pick<
52 ExecutorMcpServerConfig<E>,
53 "debug" | "elicitationMode" | "browserApprovalStore" | "pausedExecutionHooks"
54 >,
55) => {
56 const mcpServer = await Effect.runPromise(createExecutorMcpServer({ engine, ...config }));
57 const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
58 const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities });
59 await mcpServer.connect(serverTransport);
60 await client.connect(clientTransport);
61 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: test helper must close MCP transports after async client assertions
62 try {
63 await fn(client);
64 } finally {
65 await clientTransport.close();
66 await serverTransport.close();
67 }
68};
69
70const withNativeClient = async <E extends Cause.YieldableError>(
71 engine: ExecutionEngine<E>,

Callers 2

withNativeClientFunction · 0.85

Calls 3

createExecutorMcpServerFunction · 0.90
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected