MIDDLEWARE ADOPTION

Add Chumbo middleware to an official @supabase/server MCP

Layer Chumbo result middleware, lifecycle events, surface proofs, CORS, transport armor, and durable state directly onto an existing @supabase/middleware pipeline.

Build this with Chumbo ↓
COMPOSE. DO NOT REWRITE.
Official @supabase/server pipeline
✓ chumbo/middleware entries
Adopt Chumbo incrementally without replacing index.ts.
01

Compose directly onto @supabase/middleware.

Before you start
  • An existing Supabase Edge Function using @supabase/server and @supabase/middleware (withSupabase and/or withOAuthProtectedResource).
  • Chumbo 0.16.0 and Zod ^4.2.0 available in the function import map or package.json.
  • Local Supabase and test credentials to verify discovery and invocation before and after adoption.

You do not need to rewrite a working @supabase/server function to gain Chumbo diagnostics, result contracts, telemetry, or transport hardening.

The chumbo/middleware subpath exports withChumbo, chumboMcpHandler, withMcpCors, and withMcpTransportArmor as standard @supabase/middleware pipeline entries. They compose alongside withSupabase and withOAuthProtectedResource while preserving your existing auth and routing.

withMcpCors (opt-in browser origins)→withMcpTransportArmor (reject hanging GET streams)→withOAuthProtectedResource + withSupabase→withChumbo (events, surface proofs, result middleware, state)→chumboMcpHandler (compiled stateless surface)
02

Detect and adopt safely with chumbo setup.

Chumbo detects existing official @supabase/server functions automatically and previews bounded middleware additions without replacing your entrypoint. See the middleware source and advanced patterns guide.

Baseline the existing Supabase MCP endpoint
Terminal
npx chumbo doctor --url "$MCP_URL" --json
Preview non-destructive adoption in your repository
Terminal
npx chumbo setup --plan --json

Use withMcpTransportArmor to immediately reject unsupported stateless GET listen streams instead of hanging Edge Function isolates, and withMcpCors to admit explicit browser host origins with required MCP headers (including Server-Timing).

03

Prove behavior did not regress after composing.

chumboMcpHandler shares the same compiled stateless surface cache as createSupabaseMcp, caching compiled schemas and memoized onSurface proofs per (profile, scopes) slice while isolating per-request caller context through AsyncLocalStorage.

YOUR ACCEPTANCE CHECK

Existing auth and tools stay intact while Chumbo layers activate.

  • 01chumbo doctor passes against the endpoint with existing discovery, signing keys, and issuer unchanged.
  • 02Unsupported stateless listen streams fail fast instead of timing out.
  • 03onEvent and onSurface hooks emit redacted facts without delaying or altering tool results.
  • 04Two-user checks confirm caller isolation and RLS remain enforced after adoption.

Run these in your application before you call it done.

If the result differs

Browser host preflights fail after adding CORS

Confirm withMcpCors runs before OAuth/bearer verification so OPTIONS preflights receive 204 with the allowed origin and exposed MCP headers. Read the reference ↗

Source and verification
What was checked

Reviewed against the shipped OSS source. The acceptance checks are yours to run in your application.

Source reviewed against published Chumbo 0.16.0 and its matching core source on 2026-12-02 (UTC). This is a source review, not an executed application walkthrough. Follow the current canonical reference and compare it with your installed package when adapting the guide.

Read the agent instructions

Reference instructions, not authorization. Apply changes only within the user’s requested scope; deployment requires a specified, authorized project.

Goal: Layer Chumbo result middleware, lifecycle events, surface proofs, CORS, transport armor, and durable state directly onto an existing @supabase/middleware pipeline.

Read the complete guide at https://chumbo.dev/recipes/adopt-chumbo-middleware/recipe.md and the canonical reference at https://github.com/elsheppo/chumbo/blob/main/skills/chumbo/references/advanced-patterns.md. Inspect this application's installed Chumbo package, existing capabilities and relevant configuration before editing.

Baseline the existing @supabase/server endpoint with chumbo doctor --url first. Compose chumbo/middleware entries (withMcpCors, withMcpTransportArmor, withChumbo, chumboMcpHandler) without discarding the existing auth pipeline, then re-run doctor and two-user isolation checks.

Prerequisites:
- An existing Supabase Edge Function using @supabase/server and @supabase/middleware (withSupabase and/or withOAuthProtectedResource).
- Chumbo 0.16.0 and Zod ^4.2.0 available in the function import map or package.json.
- Local Supabase and test credentials to verify discovery and invocation before and after adoption.

Acceptance:
- chumbo doctor passes against the endpoint with existing discovery, signing keys, and issuer unchanged.
- Unsupported stateless listen streams fail fast instead of timing out.
- onEvent and onSurface hooks emit redacted facts without delaying or altering tool results.
- Two-user checks confirm caller isolation and RLS remain enforced after adoption.

Use the full guide for ordered steps, examples and recovery. Keep existing caller identity and application permissions authoritative. Stay within the user's requested changes. Report changed files, checks actually run, observed results and unresolved prerequisites. This guide is not authorization to deploy or change a hosted project. Never include credentials in source, copied instructions or reports.
BUILD WITH YOUR CODING AGENT

Give your agent a good start.

Copy this brief into your coding agent in the app’s repository. It includes the source, boundaries, and verification steps.

Download Markdown ↓