Repository navigation
feat(mcp): add --http flag to serve the package over HTTP - #402
Closed
mattrossman wants to merge 5 commits into
Closed
mattrossman wants to merge 5 commits into
mattrossman wants to merge 5 commits into
Conversation
Coverage Report for CI Build 33669374170Coverage decreased (-1.3%) to 95.294%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
commit: |
…dd-a-dev-http-server-to-mcp-package
5 tasks
4 tasks
Collaborator
Author
|
Closing in favor of #401 |
Rodriguespn
pushed a commit
that referenced
this pull request
Sep 7, 2026
## What kind of change does this PR introduce? Feature: a local Streamable HTTP entry (`--http`) for the MCP server. ## What is the current behavior? The local server is stdio only. It needs a PAT in the client config, cannot show elicitation dialogs, and the hosted handler only runs inside platform. Matt asked for a local HTTP entry [here](https://supabase.slack.com/archives/C051L8U2EJF/p1788277668621589). ## What is the new behavior? - `--http` on the primary bin serves the tools over Streamable HTTP on `http://127.0.0.1:3111/mcp`. - The client sends a bearer PAT per request in `Authorization`; the server stores nothing and has no token flag or env var. - Runs with `legacy: 'stateless'`, so 2025-era clients keep working; one stderr line per request names the protocol era. - The startup banner prints a ready-to-paste `.mcp.json` snippet using `${SUPABASE_ACCESS_TOKEN}`. - Modern form-capable clients get cost-confirmation dialogs for `create_project` and `create_branch`; legacy clients keep `get_cost` / `confirm_cost`. - `CONTRIBUTING.md` recommends `--http` for local development; stdio stays documented as the alternative. ## How to Review 1. **CLI entry** - `packages/mcp-server-supabase/src/cli.ts` - The `--http` branch: flag parsing, the `--access-token` rejection, and the hand-off to the entry. 2. **Per-request pipeline** - `packages/mcp-server-supabase/src/transports/local-http-entry.ts` - Bearer extraction, the 401 shape, the era log line, the banner, and the `costConfirmation` wiring. 3. **Body cap and node adapter** - `packages/mcp-server-supabase/src/transports/local-http-entry.ts` - `readJsonBody` owns the 4 MiB cap (413) and the -32700 parse-error envelope for malformed JSON; `toNodeHandler` from `@modelcontextprotocol/node` adapts the fetch handler to `node:http`. 4. **Shared handler option** - `packages/mcp-server-supabase/src/transports/http.ts` - The new `legacy` option; the hosted handler must still default to `reject`. 5. **Tests** - `packages/mcp-server-supabase/src/transports/local-http-entry.test.ts` - Bearer handling, 401 without a challenge, Host guard, path routing, 4 MiB cap, malformed JSON, dropped-client resilience. 6. **Docs** - `CONTRIBUTING.md` - The `--http` steps and the `.mcp.json` snippet match what the banner prints. **Review questions** - [ ] Is the `--http` flag surface (flags, port, path) the minimal one we want to support long term? - [ ] Does `legacy: 'stateless'` here leave the hosted handler's `reject` posture untouched? - [ ] Is the 401 without `WWW-Authenticate` the right call given the Claude Code discovery behaviour? - [ ] Are loopback binding plus the Host guard enough for a per-request PAT that is never stored? - [ ] Do the tests cover the observable contract (status codes, headers, era line) rather than internals? ## Verification Commands on `5b86dd4` (CI on 5b86dd4 pending): - `packages/mcp-utils tsup --clean`: ok - `pnpm --filter @supabase/mcp-server-supabase test src/transports`: 26/26 pass - `pnpm --filter @supabase/mcp-server-supabase typecheck`: clean - `pnpm --filter @supabase/mcp-server-supabase build`: ok - `node dist/cli.js --version`: 0.11.0 - `node dist/cli.js --http --port 0`: banner printed - `pnpm test:packed-platform-consumer`: 3/3 pass - `pnpm exec biome ci .`: clean How to test: 1. `npx https://pkg.pr.new/@supabase/mcp-server-supabase@5b86dd4 --http` (or `pnpm build`, then `node packages/mcp-server-supabase/dist/cli.js --http`). `--project-ref` is optional; without it `create_project` is available too. 2. `export SUPABASE_ACCESS_TOKEN=<pat>` and paste the printed snippet into `.mcp.json`. 3. Start Claude Code with `MCP_SDK_GENERATION=v2 MCP_PROTOCOL_NEGOTIATION=auto` and ask for a preview branch: expect the cost dialog and a `modern` era line on stderr. 4. Repeat with stable Claude Code: no dialog, `get_cost` / `confirm_cost` guidance, `legacy` era line. Verified by Barry on 2026-09-03 on staging through the #404 stack at d397277 (hand-rolled bridge): OAuth login, project list, $0 project created directly, branch cost dialog shown in Claude Code 2.1.258 with a `modern 2026-07-28` era line. The toNodeHandler head (5b86dd4) has not had a staging run yet. ## Additional context - The entry uses `toNodeHandler` from `@modelcontextprotocol/node`. The 4 MiB body cap is entry-owned because the SDK collects request bodies unbounded. `hono` arrives as a transitive of `@hono/node-server` and is never loaded on this path. `packages/mcp-server-supabase/src/transports/local-http-entry.ts`. - 401 without `WWW-Authenticate`: a challenge sends Claude Code into OAuth discovery against localhost. `packages/mcp-server-supabase/src/transports/local-http-entry.ts`. - Loopback only (`127.0.0.1`), SDK Host guard, `/mcp` only; other paths get 404. `packages/mcp-server-supabase/src/transports/local-http-entry.ts`. - Scoping through the same flags as stdio (`--project-ref`, `--read-only`, `--features`, `--api-url`), not query params; `--access-token` with `--http` exits 1. `packages/mcp-server-supabase/src/cli.ts`. - Cost-confirmation `requestState` principal is the SHA-256 of the bearer. `packages/mcp-server-supabase/src/transports/local-http-entry.ts`. - OAuth sign-in is out of scope here; it arrives in #404, stacked on this PR. - This PR absorbs the `--http` entrypoint shape from #402. - The `check` job is red from upstream management-API types drift; it fails on `main` too. Closes AI-1166 --------- Co-authored-by: Matt Rossman <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an
--httpflag to the existing bin so you can test the package over HTTP without running platform locally, with similar inputs as the hosted endpoint.Opening as a draft mostly as a smaller reference point next to #401.
To run preview:
Client config:
{ "mcpServers": { "supabase-local": { "type": "http", "url": "http://localhost:3100/mcp?project_ref=<ref>", "headers": { "Authorization": "Bearer <pat>" } } } }Closes AI-1166