Skip to content

mcpAuthRouter construction-time env is incompatible with request-scoped runtimes (Cloudflare Workers, Supabase Edge, etc.) #1860

@earonesty

Description

@earonesty

Is your feature request related to a problem? Please describe.
createMcpAuthRouter requires env-dependent initialization at app construction time. This does not work in request-scoped runtimes where bindings only exist per request.

In Cloudflare Workers (using Hono), Supabase Edge Functions, Deno Deploy, and similar environments, env is only available inside the request handler (for example c.env). There is no stable app-level env at construction time.

The only working pattern today is to reconstruct the router on every request:

app.post("/token", (c) =>
  createMcpAuthRouter(c.env).fetch(c.req.raw, c.env)
);

This is awkward and suggests the API assumes a long-lived Node-style server.


Describe the solution you'd like
Support a request-time execution model that does not require env at construction time.

Examples:

const handler = createMcpAuthHandler();
app.all("/oauth/*", (c) => handler(c.req.raw, c.env));

or:

app.use("/oauth/*", (c) => mcpAuthHandler(c));

or:

mcpAuthRouter({ getEnv: (c) => c.env });

Any approach where env is provided at request time instead of construction time would resolve this.


Describe alternatives you've considered
Per-request router construction:

(c) => createMcpAuthRouter(c.env).fetch(c.req.raw, c.env)

This works but:

  • recreates the router on every request
  • prevents reuse of internal state or memoization
  • requires repetitive route wiring

Additional context
Request-scoped runtimes are now common deployment targets:

  • Cloudflare Workers
  • Supabase Edge Functions
  • Vercel Edge Runtime
  • Deno Deploy

All share the same constraint: env is only available per request.

The current API design makes the SDK difficult to use in these environments and effectively limits it to Node-style servers. Supporting a fetch-style or context-driven handler would make the SDK compatible with edge runtimes without workarounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequest for a new feature that's not currently supported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions