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

Function openSession

apps/cloud/src/mcp-session.e2e.node.test.ts:133–172  ·  view source on GitHub ↗
(
  organizationId: string,
  options: BuildOptions & { readonly caps?: ClientCapabilities } = {},
)

Source from the content-addressed store, hash-verified

131// them connected to an in-memory MCP client. Shaped as an acquireRelease so
132// the transport teardown is guaranteed when the test scope closes.
133const openSession = (
134 organizationId: string,
135 options: BuildOptions & { readonly caps?: ClientCapabilities } = {},
136) =>
137 Effect.acquireRelease(
138 Effect.gen(function* () {
139 const executor = yield* buildScopedExecutor(organizationId, `Org ${organizationId}`, options);
140 const engine = createExecutionEngine({ executor, codeExecutor: makeQuickJsExecutor() });
141 const mcpServer = yield* buildMcpServer({
142 engine,
143 appsEnabled: false,
144 requestStateSigningKey: new Uint8Array(32).fill(23),
145 requestStatePrincipal: `cloud-mcp-test:${organizationId}`,
146 sessionful: true,
147 elicitationMode: options.elicitationMode ? { mode: options.elicitationMode } : undefined,
148 });
149 const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
150 const client = new Client(
151 { name: "cloud-e2e-test", version: "1.0.0" },
152 { capabilities: options.caps ?? ELICITATION_CAPS },
153 );
154 yield* Effect.promise(() => mcpServer.connect(serverTransport));
155 yield* Effect.promise(() => client.connect(clientTransport));
156 return { client, clientTransport, serverTransport };
157 }),
158 ({ clientTransport, serverTransport }) =>
159 Effect.all(
160 [
161 Effect.tryPromise({
162 try: () => clientTransport.close(),
163 catch: (cause) => cause,
164 }).pipe(Effect.ignore),
165 Effect.tryPromise({
166 try: () => serverTransport.close(),
167 catch: (cause) => cause,
168 }).pipe(Effect.ignore),
169 ],
170 { discard: true },
171 ),
172 ).pipe(Effect.map(({ client }) => ({ client })));
173
174const nextOrgId = (() => {
175 let seq = 0;

Callers 1

Calls 6

createExecutionEngineFunction · 0.90
makeQuickJsExecutorFunction · 0.90
buildMcpServerFunction · 0.90
buildScopedExecutorFunction · 0.85
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected