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

Function withClient

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

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

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