---
schema_version: 1
slug: stateless-mcp-streamable-http
status: source-reviewed
walkthrough_verified: false
content_hash: 249b1af2e2db026884d82ca0b2b36257fe9b020582e4e9e631fff194e0bdbac9
---

# Stateless MCP servers over Streamable HTTP: Edge Functions, Node, compression, and transport armor

Engineering patterns for stateless remote MCP servers: rejecting hanging GET streams, compact JSON vs. SSE, clean 404 OAuth discovery, compiled surfaces, Server-Timing, and Brotli/Gzip compression.

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/internal/resident-surface.ts)

## 01. Why stateless remote MCP servers behave differently from stdio.

### Before you start

- A remote MCP server running on stateless compute (Supabase Edge Functions, Cloudflare Workers, Vercel/Next.js, or Cloud Run/Node).
- Clients connecting over Streamable HTTP (not local stdio).
- A way to inspect HTTP status codes and response headers (curl or chumbo doctor).

Most early MCP tutorials assume a long-lived local stdio process. Remote MCP servers on Edge Functions, Next.js, or autoscaled Node containers are stateless HTTP handlers with strict execution timeouts and cold-start budgets.

Running a naive stateful MCP transport on stateless compute causes four classic production failures: hanging GET listen streams that exhaust isolate limits, unnecessary SSE framing on ordinary JSON-RPC calls, repeated schema recompilation on every request, and confusing 405 errors on OAuth discovery probes.

**A hardened stateless Streamable HTTP request:** CORS preflight + transport armor (reject unsupported GET streams) → Non-OAuth /.well-known/oauth-* returns clean 404 → Compiled surface serves cached schema slice with AsyncLocalStorage ctx → Compact application/json + Server-Timing + Brotli/Gzip

## 02. Five wire-level rules for fast, reliable stateless MCP servers.

### Default transport pitfalls vs. production stateless behavior

Each optimization reduces latency, bandwidth, or client retry loops.

#### Listen streams: Fail fast on unsupported stateless GET streams

Starting point:

```text
Clients probing GET /mcp for server-initiated SSE events.
```

- Without transport armor, stateless functions hold connections open until timeout.
- On Node, dropped TCP connections must propagate AbortSignal to cancel in-flight work.

What to do:

```text
Reject unsupported listen streams immediately (applyMcpTransportArmor / withMcpTransportArmor) and propagate disconnect aborts.
```

Stateless servers remain fully Streamable HTTP compliant without holding idle sockets.

#### Wire format: Default to compact application/json and negotiate compression

Starting point:

```text
Clients sending Accept: application/json, text/event-stream.
```

- When subscriptions are disabled, return compact application/json instead of verbose SSE framing.
- Honor text/event-stream when a client explicitly requests SSE without JSON.

What to do:

```text
Enable Brotli/Gzip compression (>= 1024 bytes) on Node hosts and emit Server-Timing: chumbo;dur=<ms> for observability.
```

Progressive SSE streaming stays uncompressed when streaming is explicitly requested.

#### CPU and memory: Compile stateless capability surfaces once per slice

Starting point:

```text
Repeated tools/list and tools/call traffic on warm isolates.
```

- Rebuilding Zod schemas, JSON Schema conversions, and static ui:// HTML on every request wastes CPU.
- Cache compiled surfaces per (profile, scopes) slice while isolating per-request caller ctx via AsyncLocalStorage.

What to do:

```text
Fall back automatically to per-request registration when register() reads request-varying context (or opt out with protocol.surfaceCache: "per-request").
```

Caller identity and RLS stay strictly isolated on every invocation.

## 03. Return clean 404s on unconfigured OAuth discovery and expose CORS headers.

Modern MCP clients proactively probe /.well-known/oauth-protected-resource and /.well-known/oauth-authorization-server even on API-key, bearer, or public endpoints. Return 404 Not Found (and 204 on CORS OPTIONS preflights) instead of 405 Method Not Allowed so clients immediately fall back without noisy retries.

When browser-based MCP hosts or MCP Apps connect, admit only explicit allowed origins and expose required MCP response headers (including Mcp-Session-Id and Server-Timing) in Access-Control-Expose-Headers.

> **Measure real handler latency with Server-Timing.**
>
> Chumbo 0.16+ emits Server-Timing: chumbo;dur=<ms> on both createSupabaseMcp and withChumbo (included in DEFAULT_MCP_EXPOSE_HEADERS), making cold-start vs. warm-isolate latency immediately visible in browser DevTools and curl.

## 04. Inspect the wire contract directly.

### Probe Streamable HTTP behavior and response headers

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

Read [host targets](https://github.com/elsheppo/chumbo/blob/main/docs/reference/host-targets/README.md) and [resident surface compilation](https://github.com/elsheppo/chumbo/blob/main/src/internal/resident-surface.ts) for implementation details across Edge Functions, Next.js, and chumbo/node.

### The stateless Streamable HTTP boundary is fast and resilient.

- Unsupported stateless GET listen streams fail fast instead of hanging until timeout.
- Standard MCP clients sending Accept: application/json, text/event-stream receive compact application/json on stateless endpoints.
- Non-OAuth servers return 404 (and 204 OPTIONS) on /.well-known/oauth-* probes.
- Node deployments negotiate Brotli/Gzip compression on large responses (>= 1024 bytes) while keeping SSE progressive.
- Responses include Server-Timing metrics and preserve per-request caller isolation under concurrent load.

Run these in your application before you call it done.

### If the result differs

#### A registration callback depends on per-request headers or query params

Chumbo automatically detects request-varying context reads and falls back to per-request registration; you can also set protocol.surfaceCache: "per-request" explicitly.

[Read the reference](https://github.com/elsheppo/chumbo/blob/main/SPEC.md)

### Keep building

- [Run a Supabase MCP server in Next.js or Node](/recipes/host-targets-next-node/): Scaffold and deploy with --target next or --target node.
- [How to build a good MCP server](/recipes/how-to-build-a-good-mcp-server/): Review the full tool design, pagination, auth, and testing guide.

## 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: Engineering patterns for stateless remote MCP servers: rejecting hanging GET streams, compact JSON vs. SSE, clean 404 OAuth discovery, compiled surfaces, Server-Timing, and Brotli/Gzip compression.

Read the complete guide at https://chumbo.dev/recipes/stateless-mcp-streamable-http/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.

Harden the stateless Streamable HTTP transport: reject hanging GET listen streams, return compact application/json by default, return 404 on unconfigured OAuth discovery probes, expose Server-Timing and MCP CORS headers, and verify compression and concurrency isolation on the target host.

Prerequisites:
- A remote MCP server running on stateless compute (Supabase Edge Functions, Cloudflare Workers, Vercel/Next.js, or Cloud Run/Node).
- Clients connecting over Streamable HTTP (not local stdio).
- A way to inspect HTTP status codes and response headers (curl or chumbo doctor).

Acceptance:
- Unsupported stateless GET listen streams fail fast instead of hanging until timeout.
- Standard MCP clients sending Accept: application/json, text/event-stream receive compact application/json on stateless endpoints.
- Non-OAuth servers return 404 (and 204 OPTIONS) on /.well-known/oauth-* probes.
- Node deployments negotiate Brotli/Gzip compression on large responses (>= 1024 bytes) while keeping SSE progressive.
- Responses include Server-Timing metrics and preserve per-request caller isolation under concurrent load.

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_URL` | No | The Streamable HTTP MCP endpoint URL to inspect. |

### Handoff report

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