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

Function withClient

packages/hosts/mcp/src/artifacts-tools.test.ts:135–165  ·  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

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

Callers 2

runBoundActionFunction · 0.70

Calls 4

createExecutorMcpServerFunction · 0.90
resolveMethod · 0.80
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected