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

Function makeSelfHostApp

apps/host-selfhost/src/app.ts:58–170  ·  view source on GitHub ↗
(options: MakeSelfHostAppOptions = {})

Source from the content-addressed store, hash-verified

56}
57
58export const makeSelfHostApp = async (options: MakeSelfHostAppOptions = {}) => {
59 const config = loadConfig();
60
61 // ---- eager async boot: the shared libSQL handle -----------------------
62 const dbHandle = await createSelfHostDb({
63 path: options.dbPath ?? config.dbPath,
64 namespace: SELF_HOST_NAMESPACE,
65 version: SELF_HOST_SCHEMA_VERSION,
66 });
67
68 // Boot-time data migrations: each registry entry runs once and is stamped
69 // in the `data_migration` ledger; stamped entries are skipped without
70 // touching the data.
71 await Effect.runPromise(runSqliteDataMigrations(dbHandle.client, selfHostDataMigrations));
72
73 // ---- auth providers ---------------------------------------------------
74 // Better Auth: cookie/bearer/api-key identity + /api/auth handler + account
75 // API + MCP OAuth seam, all over the shared libSQL handle.
76 const { identityLayer, authHandler, betterAuth } = await resolveAuthProviders(dbHandle);
77
78 // ---- the in-process MCP serving seams (+ shutdown hook) ----------------
79 // Pass the pinned public origin so browser-approval URLs are reachable behind
80 // a reverse proxy (not the internal 127.0.0.1 bind from the request URL).
81 const mcp = makeSelfHostMcpSeams(dbHandle, betterAuth, config.webBaseUrl);
82
83 // CLI device-login discovery (`executor login`). Points the CLI at Better
84 // Auth's device endpoints; `requestFormat: "json"` because those endpoints
85 // only accept JSON (unlike WorkOS's form-encoded ones). The issued token is a
86 // Better Auth session that `bearer()` accepts on the /api/* plane.
87 const cliLoginHandler = HttpEffect.fromWebHandler(
88 async () =>
89 new Response(
90 JSON.stringify({
91 provider: "better-auth",
92 deviceAuthorizationEndpoint: `${config.webBaseUrl}/api/auth/device/code`,
93 tokenEndpoint: `${config.webBaseUrl}/api/auth/device/token`,
94 clientId: "executor-cli",
95 requestFormat: "json",
96 }),
97 { headers: { "content-type": "application/json" } },
98 ),
99 );
100
101 const { appLayer, toWebHandler } = ExecutorApp.make({
102 plugins: selfHostPlugins,
103 providers: {
104 identity: identityLayer,
105 account: selfHostAccountMiddleware(betterAuth),
106 db: SelfHostDbProvider,
107 engine: {
108 codeExecutor: SelfHostCodeExecutorProvider,
109 // Anonymous execution analytics (this seam is the HTTP plane; the MCP
110 // plane's decorator is wired in mcp/session-store.ts's stack layer).
111 decorator: SelfHostAnalyticsEngineDecorator,
112 },
113 mcp: { auth: mcp.auth, sessions: mcp.sessions, reporter: mcp.reporter },
114 plugins: { provider: SelfHostPluginsProvider, config: SelfHostHostConfig },
115 errorCapture: ErrorCaptureLive,

Callers 2

startServerFunction · 0.90
makeSelfHostApiHandlerFunction · 0.85

Calls 11

loadConfigFunction · 0.90
createSelfHostDbFunction · 0.90
runSqliteDataMigrationsFunction · 0.90
resolveAuthProvidersFunction · 0.90
makeSelfHostMcpSeamsFunction · 0.90
composePluginApiFunction · 0.85
closeMethod · 0.65

Tested by

no test coverage detected