feat!: accept only OAuth on /mcp and remove MCP keys #50

Merged
marti merged 5 commits from feature/oauth-only-mcp into develop 2026-11-10 09:13:50 +01:00
Owner

Summary

OAuth is now the only way into /mcp. MCP keys (mhm_) are removed end to end. Admin mhk_ REST tokens are unchanged and still refused on /mcp.

 POST /mcp
-  authenticateMcp
-    mhm_ key -> verifyMcpKey -> session bound to the key
-    otherwise -> authenticateBearer
+  authenticateBearer -> session bound to the OAuth grant
 apps/api
-  routes/me/mcp-keys.ts
-  /api/me/mcp-keys/:ownerId/*              # per-key access and profiles
-  api_tokens.kind, api_token_kind
-  api_token_id on client_hidden_servers, client_hidden_tools, client_profiles, tool_calls
+  drizzle/0010_remove_mcp_keys.sql         # client_id becomes NOT NULL on the three access tables
 apps/web
-  Clients page: MCP keys section
-  /clients/keys/$keyId

trail check reports 3 conflicts claiming this brings back MCP keys or admin tokens on /mcp. They are keyword matches: keys are deleted here, and a test pins that both mhm_ and mhk_ bearers get 401 on /mcp. The learning that describes MCP keys as active still needs replacing.

Evidence

  • Before: /mcp accepted a valid mhm_ key and opened a session as its owner.
    After: accepts nothing but an OAuth access token in apps/api/test/gateway.test.ts passes:

    POST /mcp with Bearer mhm_...  -> 401 invalid_token, WWW-Authenticate points at OAuth metadata
    POST /mcp with Bearer mhk_...  -> 401 invalid_token, WWW-Authenticate points at OAuth metadata
    GET /api/me/mcp-keys           -> 404
    
  • nix develop -c ./scripts/ci.sh passed: lint, typecheck, 538 tests (2 skipped), build, audit. A later commit only removes two unused test imports; lint and the API typecheck were re-run after it.

  • Migration on a throwaway Postgres 18 seeded through 0009 with one MCP key, one admin token, and key-owned and client-owned rows:

    api_tokens        admin token kept, MCP key deleted
    client_profiles   OAuth client's row kept, key's row deleted
    tool_calls        row kept
    client_id         NOT NULL on all three access tables
    api_token_kind    type dropped
    
  • The portal change is covered by component tests only. No screenshots were taken.

Merge Danger

Door: one-way

Migration 0010 deletes every MCP key and its access rules. Reverting the code does not restore them; users would have to create new keys and set their rules again.

Blast Radius: integrations

Anything authenticating to /mcp with an mhm_ key (scripts, automation tools, clients that only take a URL and headers) gets 401 and must move to OAuth or stop. Clients that cannot do OAuth have no replacement. Past tool calls made through a key stay in activity but lose their client name.

🤖 Generated with Claude Code

## Summary OAuth is now the only way into `/mcp`. MCP keys (`mhm_`) are removed end to end. Admin `mhk_` REST tokens are unchanged and still refused on `/mcp`. ```diff POST /mcp - authenticateMcp - mhm_ key -> verifyMcpKey -> session bound to the key - otherwise -> authenticateBearer + authenticateBearer -> session bound to the OAuth grant ``` ```diff apps/api - routes/me/mcp-keys.ts - /api/me/mcp-keys/:ownerId/* # per-key access and profiles - api_tokens.kind, api_token_kind - api_token_id on client_hidden_servers, client_hidden_tools, client_profiles, tool_calls + drizzle/0010_remove_mcp_keys.sql # client_id becomes NOT NULL on the three access tables apps/web - Clients page: MCP keys section - /clients/keys/$keyId ``` `trail check` reports 3 conflicts claiming this brings back MCP keys or admin tokens on `/mcp`. They are keyword matches: keys are deleted here, and a test pins that both `mhm_` and `mhk_` bearers get 401 on `/mcp`. The learning that describes MCP keys as active still needs replacing. ## Evidence - **Before:** `/mcp` accepted a valid `mhm_` key and opened a session as its owner. **After:** `accepts nothing but an OAuth access token` in `apps/api/test/gateway.test.ts` passes: ```text POST /mcp with Bearer mhm_... -> 401 invalid_token, WWW-Authenticate points at OAuth metadata POST /mcp with Bearer mhk_... -> 401 invalid_token, WWW-Authenticate points at OAuth metadata GET /api/me/mcp-keys -> 404 ``` - `nix develop -c ./scripts/ci.sh` passed: lint, typecheck, 538 tests (2 skipped), build, audit. A later commit only removes two unused test imports; lint and the API typecheck were re-run after it. - Migration on a throwaway Postgres 18 seeded through 0009 with one MCP key, one admin token, and key-owned and client-owned rows: ```text api_tokens admin token kept, MCP key deleted client_profiles OAuth client's row kept, key's row deleted tool_calls row kept client_id NOT NULL on all three access tables api_token_kind type dropped ``` - The portal change is covered by component tests only. No screenshots were taken. ## Merge Danger **Door:** one-way Migration 0010 deletes every MCP key and its access rules. Reverting the code does not restore them; users would have to create new keys and set their rules again. **Blast Radius:** integrations Anything authenticating to `/mcp` with an `mhm_` key (scripts, automation tools, clients that only take a URL and headers) gets 401 and must move to OAuth or stop. Clients that cannot do OAuth have no replacement. Past tool calls made through a key stay in activity but lose their client name. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Merge pull request 'develop' (#49) from develop into main
All checks were successful
CI / check (push) Successful in 6m0s
43fe4e2422
Reviewed-on: #49
MCP keys were a second way into the user gateway alongside OAuth. Drop
them: the key routes, the gateway check, per-key access rules, and the
columns that existed only for keys. Admin mhk_ tokens stay; they serve
the admin REST API and are still refused on /mcp.

trail check flags this as bringing back MCP keys or admin tokens on
/mcp. It does the opposite: keys are deleted, and a test pins that both
mhm_ and mhk_ bearers get 401 on /mcp.

BREAKING CHANGE: mhm_ keys stop working and migration 0010 deletes them
and their access rules. Clients using one must connect through OAuth.
Past tool calls made with a key stay but lose their client name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Clients page, the key access page and the setup hint went with the
API. TokenManager now only serves admin API tokens, so its extension
points for keys are gone too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test(api): drop imports left unused by the MCP key removal
All checks were successful
CI / check (pull_request) Successful in 5m55s
f89f8ad3b7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marti merged commit 4fda4831fc into develop 2026-11-10 09:13:50 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marti/mcphub!50
No description provided.