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

Function makeCloudflareApp

apps/host-cloudflare/src/app.ts:36–80  ·  view source on GitHub ↗
(env: CloudflareEnv)

Source from the content-addressed store, hash-verified

34// ===========================================================================
35
36export const makeCloudflareApp = async (env: CloudflareEnv) => {
37 const config = loadConfig(env);
38 const plugins = makeCloudflarePlugins(config.secretKey);
39
40 // Load the Workers-compatible (WASM-inlined) QuickJS variant before any
41 // executor is built, the default variant cannot fetch its .wasm on Workers.
42 await preloadQuickJs();
43
44 // Open and idempotently bring up the D1 schema once. This is the long-lived
45 // handle the per-request scoped executor reads through the DbProvider seam.
46 const dbHandle = await createD1ExecutorDb(env.DB, env.BLOBS);
47 const identityLayer = cloudflareAccessIdentityLayer(config);
48 const mcpAgentHandler = makeCloudflareMcpAgentHandler(config);
49 const approvalHandler = makeCloudflareApprovalHandler(config, env);
50
51 const { appLayer, toWebHandler } = ExecutorApp.make({
52 plugins,
53 providers: {
54 identity: identityLayer,
55 db: dbProviderLayer(Effect.succeed(dbHandle)),
56 engine: { codeExecutor: CloudflareCodeExecutorProvider },
57 plugins: {
58 provider: makeCloudflarePluginsProvider(config),
59 config: makeCloudflareHostConfig(config),
60 },
61 errorCapture: ErrorCaptureLive,
62 // The account API (`/api/account/*`) backs the shared multiplayer shell's
63 // auth context; `me` reflects the Access principal. Members/keys are
64 // Access-managed, so the rest of the surface is stubbed.
65 account: cloudflareAccountMiddleware(config),
66 },
67 extensions: {
68 routes: [
69 // Browser approval of paused MCP executions: the console resume page
70 // reads paused detail (GET) and records the decision (POST .../resume),
71 // Access-gated, routed to the owning session's Durable Object.
72 HttpRouter.add("*", "/api/mcp-sessions/*", HttpEffect.fromWebHandler(approvalHandler)),
73 ],
74 },
75 config: { mountPrefix: "/api", failure: textFailureStrategy },
76 boot: identityLayer,
77 });
78
79 return { appLayer, toWebHandler, mcpAgentHandler };
80};

Callers 1

resolveHandlerFunction · 0.90

Calls 11

loadConfigFunction · 0.90
makeCloudflarePluginsFunction · 0.90
preloadQuickJsFunction · 0.90
createD1ExecutorDbFunction · 0.90
dbProviderLayerFunction · 0.90
makeCloudflareHostConfigFunction · 0.90

Tested by

no test coverage detected