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

Function makeCloudflareApp

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

Source from the content-addressed store, hash-verified

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

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