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

Function withClient

packages/hosts/mcp/src/artifacts-tools.test.ts:140–171  ·  view source on GitHub ↗
(
  engine: ExecutionEngine<E>,
  capabilities: ClientCapabilities,
  fn: (client: Client) => Promise<void>,
  config?: Partial<ExecutorMcpServerConfig<E>>,
)

Source from the content-addressed store, hash-verified

138} as const;
139
140const withClient = async <E extends Cause.YieldableError>(
141 engine: ExecutionEngine<E>,
142 capabilities: ClientCapabilities,
143 fn: (client: Client) => Promise<void>,
144 config?: Partial<ExecutorMcpServerConfig<E>>,
145) => {
146 const mcpServer = await Effect.runPromise(
147 buildMcpServer({
148 engine,
149 ...SESSION_SERVER_OPTIONS,
150 loadAppShellHtml: () => Promise.resolve(SHELL_HTML),
151 // Artifacts are on by default and nearly every test in this file
152 // exercises the artifact surface; spelled out here anyway so the cases
153 // that assert the OFF surface (`artifactsEnabled: false`) read as the
154 // deliberate contrast. The default (no flag at all) is proved directly
155 // in the opt-out describe block.
156 artifactsEnabled: true,
157 ...config,
158 } as ExecutorMcpServerConfig<E>),
159 );
160 const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
161 const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities });
162 await mcpServer.connect(serverTransport);
163 await client.connect(clientTransport);
164 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: test helper must close MCP transports after async client assertions
165 try {
166 await fn(client);
167 } finally {
168 await clientTransport.close();
169 await serverTransport.close();
170 }
171};
172
173const SHELL_HTML = "<!doctype html><html><body><div id='root'></div></body></html>";
174

Callers 2

runBoundActionFunction · 0.70

Calls 4

buildMcpServerFunction · 0.90
resolveMethod · 0.80
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected