Skip to content

feat: add --oauth login for the --http local entry - #404

Open
barryroodt wants to merge 1 commit into
mainfrom
feat/local-http-oauth
Open

barryroodt wants to merge 1 commit into
mainfrom
feat/local-http-oauth

Conversation

@barryroodt

@barryroodt barryroodt commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Adds browser sign-in to this repo's local --http dev server.

What is the current behavior?

Each developer creates and stores a PAT so their client can send it in every request's Authorization header.

What is the new behavior?

--http --oauth opens Supabase sign-in through the MCP SDK, using the hosted MCP server matching --api-url and a callback at 127.0.0.1:3112. The entry attaches the token, so clients can omit headers. Concurrent requests share one refresh because refresh tokens are single use.

Registration and tokens persist in ~/.supabase/mcp-oauth.json (mode 0600). SUPABASE_HOME overrides the directory. Delete the file to sign out.

Both modes now return 403 for requests with a browser Origin, alongside the existing Host check. OAuth has no per-request gate. The trade-off is that any local process that can reach the port can use your scopes.

How to Review

In the diff, start with oauth-client.ts for sign-in and refresh. In local-http-entry.ts, the principal stays stable across refreshes so pending confirmations still work. cli.ts handles failed sign-in with exit code 1. See local-http-entry.test.ts for request coverage and CONTRIBUTING.md for usage.

  • Are we comfortable with the loopback trade-off?
  • Confirm the platform consumer can take @modelcontextprotocol/client as a runtime dependency.

Verification

On the rebuild, tsc --noEmit and pnpm format:check passed. All 1,054 tests passed across 36 files, including 66 local HTTP tests. Each new test failed when its corresponding behavior was removed.

Nobody has run a real sign-in on the rebuilt commit. Pedro verified September's version on staging and production. oauth-client.ts has no dedicated tests.

Additional context

I replaced the 20 commits with one on current main since #401 merged the HTTP entry. oauth-client.ts is byte-identical to the previous head. Matt approved before the rebuild, so I'd welcome a fresh review. Pedro closed #421 in favour of this PR.

Part of AI-1166

@barryroodt
barryroodt requested a review from a team as a code owner September 3, 2026 08:19
@barryroodt
barryroodt force-pushed the feat/local-http-oauth branch 2 times, most recently from 3ba6f78 to 41dbecd Compare September 3, 2026 09:01
@barryroodt barryroodt self-assigned this Sep 3, 2026
@barryroodt barryroodt added the publish-preview Runs `publish-preview` workflow to publish preview packages via https://pkg.pr.new/ label Sep 3, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@supabase/mcp-server-supabase@db7a018
pnpm add https://pkg.pr.new/@supabase/mcp-utils@db7a018

commit: db7a018

@coveralls

coveralls commented Sep 3, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 45984885641

Coverage decreased (-1.0%) to 97.237%

Details

  • Coverage decreased (-1.0%) from the base build.
  • Patch coverage: 87 uncovered changes across 1 file (13 of 100 lines covered, 13.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
packages/mcp-server-supabase/src/transports/oauth-client.ts 87 0 0.0%
Total (2 files) 100 13 13.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 6810
Covered Lines: 6642
Line Coverage: 97.53%
Relevant Branches: 1479
Covered Branches: 1418
Branch Coverage: 95.88%
Branches in Coverage %: Yes
Coverage Strength: 2305.04 hits per line

💛 - Coveralls

@barryroodt
barryroodt force-pushed the feat/local-http-oauth branch 2 times, most recently from d2ff583 to 1661479 Compare September 4, 2026 11:52
},
"dependencies": {
"@mjackson/multipart-parser": "^0.10.1",
"@modelcontextprotocol/client": "catalog:",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note @modelcontextprotocol/client becomes a runtime dep with my changes so --oauth can use the SDK's auth() flow. Platform already has it at the same catalog version as a devDependency of mgmt-api, so the next bump will pull it (plus some small transitives) into the image as install weight. Platform doesn't reach the code that uses it though.

@mattrossman

Copy link
Copy Markdown
Collaborator

Pushed changes to trim this PR, though might be good to check the @modelcontextprotocol/client dep decision w/ platform team in case they object. We already get a nice DX boost from #401 alone so not the end of the world if we don't get OAuth in near term.

Tested w/ --oauth flag in latest Claude Code, staging.

npx https://pkg.pr.new/@supabase/mcp-server-supabase@9f140f0 --http --oauth --api-url https://api.supabase.green

Base automatically changed from feat/local-http-entry to main September 7, 2026 12:48
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]>
Rebuilt on current main from the OAuth-only part of the original branch.
The --http entry itself reached main in #401, so the earlier commits that
built it are dropped.

--oauth signs in with Supabase OAuth in the browser, stores the session in
~/.supabase/mcp-oauth.json and attaches the token to every request, so the
client config needs no Authorization header. The entry now also rejects
requests that carry a browser Origin.
@barryroodt
barryroodt force-pushed the feat/local-http-oauth branch from 9f140f0 to db7a018 Compare November 27, 2026 10:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish-preview Runs `publish-preview` workflow to publish preview packages via https://pkg.pr.new/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants