---
schema_version: 1
slug: host-targets-next-node
status: source-reviewed
walkthrough_verified: false
content_hash: 218f773566f47e949fa7215f0706ca8d3801f2573bf10e691f53000cd134b1e6
---

# Run a Chumbo MCP server in Next.js App Router or standalone Node with chumbo/node

Serve your Chumbo MCP directly from a Next.js App Router route or a standalone Node HTTP server with Brotli/Gzip compression and compiled stateless surfaces.

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.

[Structured recipe](./recipe.json) · [Human-readable page](./)

## Sources

- [Canonical pattern](https://github.com/elsheppo/chumbo/blob/main/docs/reference/host-targets/README.md)
- [Reference implementation](https://github.com/elsheppo/chumbo/blob/main/src/node.ts)

## 01. Pick the host that matches your deployment unit.

A Chumbo app is a web-standard fetch handler. Supabase Edge Functions remain the default target, while Next.js App Router and standalone Node servers let you deploy the exact same capabilities.ts seam inside an existing app or container without losing Supabase Auth or RLS.

### Three targets, one capability contract

All three targets share access modes, result helpers, compiled stateless surfaces, and chumbo doctor.

#### Next.js: Colocated App Router route

Starting point:

```text
npx chumbo setup --target next
```

- Generates app/mcp/[[...path]]/route.ts and app/mcp/capabilities.ts.
- Serves /mcp and /.well-known/... discovery suffixes with dynamic = force-dynamic.

What to do:

```text
Run your normal Next.js dev server and verify with chumbo doctor.
```

Accepts SUPABASE_URL / SUPABASE_PUBLISHABLE_KEY or NEXT_PUBLIC_ equivalents.

#### Node: Standalone HTTP server via chumbo/node

Starting point:

```text
npx chumbo setup --target node
```

- Generates mcp/index.ts served with serve(app, { port }) over node:http.
- Includes Brotli/Gzip compression (>= 1024 bytes), single-buffer writes, SSE streaming, and reverse-proxy URL reconstruction.

What to do:

```text
Run with Node 22+ and deploy to Cloud Run, Fly, Railway, or any container host.
```

Listens on PORT (default 8080) and propagates client disconnect aborts.

## 02. Scaffold the host target and inspect the plan.

### Before you start

- An existing Supabase project whose Auth, Postgres grants, and RLS policies remain authoritative.
- Node 22+ and either a Next.js App Router repository or a Node container/host (Cloud Run, Fly, Railway, or similar).
- Environment variables SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, and in production MCP_PUBLIC_URL.

Run setup with --plan first to preview every file before writing.

### Preview a Next.js App Router scaffold

```sh
npx chumbo setup --target next --plan --json
```

### Preview a standalone Node scaffold

```sh
npx chumbo setup --target node --plan --json
```

Read the [host targets reference](https://github.com/elsheppo/chumbo/blob/main/docs/reference/host-targets/README.md) for environment variables, migration placement when no supabase/ directory is present, and embedding toNodeHandler(app) into an existing HTTP server.

## 03. Stateless wire efficiency comes built in.

**One stateless request on Node or Next.js:** Request enters fetch handler → Compiled surface serves cached schema slice → AsyncLocalStorage isolates caller ctx → Compact JSON + Server-Timing + Brotli/Gzip

On stateless endpoints, Chumbo compiles and caches capability surfaces per (profile, scopes) slice while isolating per-request caller context through AsyncLocalStorage. Registration callbacks that read request-varying properties automatically fall back to per-request registration, and protocol.surfaceCache: "per-request" provides an explicit opt-out.

> **Compact JSON, clean 404s, and Server-Timing**
>
> Stateless endpoints default to compact application/json when clients accept JSON, return 404 (and 204 on CORS preflight) on /.well-known/oauth-* probes when OAuth is unconfigured, and emit Server-Timing: chumbo;dur=<ms>.

## 04. Use chumbo doctor as the executable contract.

### Run the generated Node server locally

```sh
node --experimental-strip-types mcp/index.ts
```

### Probe the deployed public URL

```sh
npx chumbo doctor --url "$MCP_PUBLIC_URL" --json
```

### The hosted target matches the Edge Function contract.

- Local doctor probes initialize, discover tools, and invoke one safe capability on 127.0.0.1.
- MCP_PUBLIC_URL matches the exact public URL clients connect to in production.
- Reverse-proxy headers preserve the public scheme and host for OAuth discovery.
- Response headers expose Server-Timing: chumbo;dur=<ms> and negotiate compression on Node.
- Non-OAuth deployments return 404 on /.well-known/oauth-* discovery probes.

Run these in your application before you call it done.

### If the result differs

#### OAuth metadata advertises an internal container URL

Set MCP_PUBLIC_URL to the exact public HTTPS URL clients connect to, and confirm your reverse proxy forwards x-forwarded-proto and x-forwarded-host.

[Read the reference](https://github.com/elsheppo/chumbo/blob/main/docs/reference/host-targets/README.md)

### Keep building

- [Test, deploy and debug your MCP](/recipes/deploy-debug-mcp/): Diagnose gateway, identity, grant, and tool-surface boundaries.
- [Give users a product URL](/recipes/clean-mcp-url/): Compare hosting in-app versus proxying an Edge Function.

## Instructions for your coding agent

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

Goal: Serve your Chumbo MCP directly from a Next.js App Router route or a standalone Node HTTP server with Brotli/Gzip compression and compiled stateless surfaces.

Read the complete guide at https://chumbo.dev/recipes/host-targets-next-node/recipe.md and the canonical reference at https://github.com/elsheppo/chumbo/blob/main/docs/reference/host-targets/README.md. Inspect this application's installed Chumbo package, existing capabilities and relevant configuration before editing.

Choose --target next or --target node based on the existing application repository. Inspect the setup plan before writing files, preserve existing capabilities.ts, set MCP_PUBLIC_URL for production, and verify both local and deployed URLs with chumbo doctor.

Prerequisites:
- An existing Supabase project whose Auth, Postgres grants, and RLS policies remain authoritative.
- Node 22+ and either a Next.js App Router repository or a Node container/host (Cloud Run, Fly, Railway, or similar).
- Environment variables SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, and in production MCP_PUBLIC_URL.

Acceptance:
- Local doctor probes initialize, discover tools, and invoke one safe capability on 127.0.0.1.
- MCP_PUBLIC_URL matches the exact public URL clients connect to in production.
- Reverse-proxy headers preserve the public scheme and host for OAuth discovery.
- Response headers expose Server-Timing: chumbo;dur=<ms> and negotiate compression on Node.
- Non-OAuth deployments return 404 on /.well-known/oauth-* discovery probes.

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.

### Required environment inputs

| Variable | Sensitive | Meaning |
| --- | --- | --- |
| `MCP_PUBLIC_URL` | No | The exact public URL MCP clients connect to in production. |

### Handoff report

- Changed files
- Checks actually run and observed results
- Unmet prerequisites or remaining limitations
