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

Function buildMcpRoutes

packages/core/api/src/server/executor-app.ts:613–633  ·  view source on GitHub ↗
(
  mcp: McpProviders<RMcpAuth>,
  identity: Layer.Layer<IdentityProvider>,
)

Source from the content-addressed store, hash-verified

611 * (`RMcpAuth = never`, cloud), the provide is a harmless no-op.
612 */
613const buildMcpRoutes = <RMcpAuth>(
614 mcp: McpProviders<RMcpAuth>,
615 identity: Layer.Layer<IdentityProvider>,
616): Layer.Layer<never, never, HttpRouter.HttpRouter> => {
617 // The auth seam may declare `IdentityProvider` as a requirement (self-host's
618 // genuinely reads it; cloud's ignores it — its MCP JWT/api-key path is separate).
619 // Either way the identity seam is provided ONCE (memoized) and shared across the
620 // build-time provide + the per-request `provideRequest`. The provided
621 // `IdentityProvider` covers `RMcpAuth` whether it is `IdentityProvider` or `never`.
622 const mcpAuthLive = (mcp.auth as Layer.Layer<McpAuthProvider, never, IdentityProvider>).pipe(
623 Layer.provide(identity),
624 );
625 // No session store: the host serves `/mcp` transport elsewhere (the Cloudflare
626 // Agent bridge), so mount only the auth-declared discovery routes. The discovery
627 // handlers are captured from the auth seam at build, so no per-request seams.
628 if (!mcp.sessions) {
629 return McpDiscoveryRoutes.pipe(Layer.provide(mcpAuthLive));
630 }
631 const mcpSeams = Layer.mergeAll(mcpAuthLive, mcp.sessions, mcp.reporter ?? McpErrorReporterNoop);
632 return McpServingRoutes.pipe(HttpRouter.provideRequest(mcpSeams), Layer.provide(mcpAuthLive));
633};
634
635// Re-exported so a strategy author building the `config.failure` value can name
636// the `Principal` the strategy renders failures around.

Callers 1

makeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected