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

Function makeMcpBuildServer

packages/core/api/src/server/mcp-build.ts:44–98  ·  view source on GitHub ↗
(executionStack: McpExecutionStackLayer, hostOptions?: McpBuildHostOptions)

Source from the content-addressed store, hash-verified

42 */
43export const makeMcpBuildServer =
44 (executionStack: McpExecutionStackLayer, hostOptions?: McpBuildHostOptions): McpBuildServer =>
45 (principal: Principal, options?: McpBuildServerOptions) =>
46 Effect.gen(function* () {
47 const { engine, executor } = yield* makeExecutionStack(
48 principal.accountId,
49 principal.organizationId,
50 principal.organizationName,
51 {
52 mcpResource: options?.resource,
53 orgWrites: "request",
54 },
55 ).pipe(Effect.withSpan("mcp.execution_stack.build"));
56 // Read inside the provided boundary: `webBaseUrl` is a host seam, and
57 // hosts that can't know their public URL at boot leave it unset — in
58 // which case artifacts still persist but carry no deep link.
59 const hostConfig = yield* HostConfig;
60 return { engine, executor, webBaseUrl: hostConfig.webBaseUrl };
61 }).pipe(
62 // Pin browser-handoff URLs to the principal's org slug when present;
63 // absent slug leaves the service unprovided and the URL stays bare.
64 principal.organizationSlug !== undefined
65 ? Effect.provideService(RequestOrgSlug, { slug: principal.organizationSlug })
66 : (effect) => effect,
67 Effect.provide(executionStack),
68 Effect.mapError((cause) => new McpEngineBuildError({ cause })),
69 Effect.flatMap(({ engine, executor, webBaseUrl }) =>
70 createExecutorMcpServer({
71 engine,
72 artifacts: executor.artifacts,
73 connections: executor.connections,
74 tools: executor.tools,
75 integrations: executor.integrations,
76 ...(hostOptions?.loadAppShellHtml
77 ? { loadAppShellHtml: hostOptions.loadAppShellHtml }
78 : {}),
79 ...(hostOptions?.smokeRenderArtifact
80 ? { smokeRenderArtifact: hostOptions.smokeRenderArtifact }
81 : {}),
82 ...(hostOptions?.onArtifactUsage ? { onArtifactUsage: hostOptions.onArtifactUsage } : {}),
83 // Same org pinning as `RequestOrgSlug` above: self-host serves its
84 // console under `/<org-slug>` (`default` when unconfigured), so the
85 // deep link carries the principal's slug rather than relying on the
86 // browser's active org to canonicalize a bare path after landing.
87 ...(webBaseUrl
88 ? { artifactUrl: artifactUrlFor(webBaseUrl, principal.organizationSlug) }
89 : {}),
90 ...(options ?? {}),
91 }).pipe(
92 Effect.withSpan("mcp.server.create"),
93 // Catalog failures use the same retryable build envelope.
94 Effect.mapError((cause) => new McpEngineBuildError({ cause })),
95 Effect.map((mcpServer) => ({ mcpServer, engine, executor })),
96 ),
97 ),
98 );
99
100/** Per-host (not per-session) MCP wiring. Kept separate from
101 * `McpBuildServerOptions`, which the session store fills in per request. */

Callers 1

Calls 3

makeExecutionStackFunction · 0.90
createExecutorMcpServerFunction · 0.90
artifactUrlForFunction · 0.90

Tested by

no test coverage detected