(
principal: Principal,
options: McpSessionBuildOptions | McpModernServerBuildOptions,
)
| 57 | function build(principal: Principal, options: McpSessionBuildOptions): McpSessionBuildEffect; |
| 58 | function build(principal: Principal, options: McpModernServerBuildOptions): McpModernBuildEffect; |
| 59 | function build( |
| 60 | principal: Principal, |
| 61 | options: McpSessionBuildOptions | McpModernServerBuildOptions, |
| 62 | ): Effect.Effect< |
| 63 | Effect.Success<McpSessionBuildEffect> | Effect.Success<McpModernBuildEffect>, |
| 64 | Effect.Error<McpSessionBuildEffect> | Effect.Error<McpModernBuildEffect> |
| 65 | > { |
| 66 | const { resource, ...serverOptions } = options; |
| 67 | return Effect.gen(function* () { |
| 68 | const { engine, executor } = yield* makeExecutionStack( |
| 69 | principal.accountId, |
| 70 | principal.organizationId, |
| 71 | principal.organizationName, |
| 72 | { mcpResource: resource }, |
| 73 | ).pipe(Effect.withSpan("mcp.execution_stack.build")); |
| 74 | // Read inside the provided boundary: `webBaseUrl` is a host seam, and |
| 75 | // hosts that cannot know their public URL at boot leave it unset. |
| 76 | const hostConfig = yield* HostConfig; |
| 77 | return { engine, executor, webBaseUrl: hostConfig.webBaseUrl }; |
| 78 | }).pipe( |
| 79 | principal.organizationSlug !== undefined |
| 80 | ? Effect.provideService(RequestOrgSlug, { slug: principal.organizationSlug }) |
| 81 | : (effect) => effect, |
| 82 | Effect.provide(executionStack), |
| 83 | Effect.mapError((cause) => new McpEngineBuildError({ cause })), |
| 84 | Effect.flatMap(({ engine, executor, webBaseUrl }) => |
| 85 | buildMcpServer({ |
| 86 | engine, |
| 87 | artifacts: executor.artifacts, |
| 88 | connections: executor.connections, |
| 89 | ...(hostOptions?.loadAppShellHtml |
| 90 | ? { loadAppShellHtml: hostOptions.loadAppShellHtml } |
| 91 | : {}), |
| 92 | ...(hostOptions?.smokeRenderArtifact |
| 93 | ? { smokeRenderArtifact: hostOptions.smokeRenderArtifact } |
| 94 | : {}), |
| 95 | ...(hostOptions?.onArtifactUsage ? { onArtifactUsage: hostOptions.onArtifactUsage } : {}), |
| 96 | ...(webBaseUrl |
| 97 | ? { artifactUrl: artifactUrlFor(webBaseUrl, principal.organizationSlug) } |
| 98 | : {}), |
| 99 | ...serverOptions, |
| 100 | }).pipe( |
| 101 | Effect.withSpan("mcp.server.create"), |
| 102 | Effect.map((mcpServer) => ("sessionful" in options ? { mcpServer, engine } : mcpServer)), |
| 103 | ), |
| 104 | ), |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | return build; |
| 109 | }; |
no test coverage detected