mig: add typed MCP auth clients and server associations
Stacked on #7653.
Summary
Schema only, in four tables. They hold typed auth clients: the ways an MCP server can authenticate to its upstream. Columns shared by several types live on mcp_auth_clients; fields only one type needs get that type's own table (today only EMA).
mcp_auth_clients: one row per auth client.- Columns: a stable id, the org, an optional project (NULL means shared across the organization), a generated
attachment_scope(the project or organization owner, used by scope-checked foreign keys),client_type,source(backfilloradmin), a name, an enabled flag and the author. It's soft deleted. - Type and source: validated in application code (
remote_session,service_account,static_credential,pass_through,ema); the DB only checks they're non-empty, so a new type needs no migration. - OAuth registration: OAuth-backed types (
remote_session,service_account,ema) point at theirremote_session_clientsrow here, rather than copying it. The pointer isremote_session_client_idplusclient_attachment_scope, with a composite FK. - Registration check: the registration id and its scope are set together, and the registration must sit in the client's project or organization, or be platform-global. Which types need one is validated in application code.
- Uniqueness: partial unique indexes on
(organization_id, remote_session_client_id)for livesource = 'backfill'rows, per type, give each registration at most one backfilledremote_sessionand oneservice_accountclient per organization, so the backfill finds rather than duplicates. Admin-created clients may share a registration (RFC §7.3/7.4). A platform-global registration gets one backfilled client per organization.
- Columns: a stable id, the org, an optional project (NULL means shared across the organization), a generated
mcp_auth_client_emas: extra detail foremaclients only.- Columns: the upstream authorization server (
remote_session_issuer_id), the resource and the requested scopes. - Issuer must match the registration: the table copies the base row's
organization_idandremote_session_client_id. One FK pins those copies, andclient_type = 'ema', to the base row via(id, client_type, remote_session_client_id, organization_id). A second FK pins(remote_session_client_id, remote_session_issuer_id)toremote_session_clients. - Why it's built this way: this is the smallest shape that keeps "the issuer is the registration's issuer" enforced by the database without copying scope columns.
- Placement: the table sits after
remote_session_clients_id_issuer_keyinschema.sql, because Atlas needs that key to exist first. - Uniqueness: one live row per (organization, issuer, registration, resource); the row is soft deleted with its base row, so a retired client frees the key. Two orgs can share a platform-global registration.
- Not stored here: the vouching order stays in
remote_session_ema_providers, and the user session issuer is no longer part of the key.
- Columns: the upstream authorization server (
mcp_auth_client_headers: headers owned by a client. Same shape, CHECKs and access classes asremote_mcp_server_headers. Static credentials and pass-through keep their material here.mcp_server_auth_clients: which clients each server offers, many-to-many, with asource(backfilloradmin) so the backfill only ever retires links it created. It uses the same tenant and scope pattern asmcp_server_remote_session_clients, which this PR leaves untouched.- No upstream auth: not modeled as a client. It stays the existing
no_authselection (RFC §7.5); a server with no clients is setup incomplete. Pass-through only forwards explicitly named headers (value_from_request_header); it never forwards the caller's own credentials by default. mcp_servers.requires_upstream_auth: nullable boolean.truemeans the upstream needs authentication,falsemeans it explicitly needs none,NULLmeans undecided. The backfill only ever setstrue(for a server it links a client to); the admin UI (AIM-592) setsfalse. Adding a nullable column with no default is metadata-only.
An earlier revision had a table per type. It's collapsed to these four because only EMA has fields of its own. The OAuth-backed types differ only in which registration they point at, and that now lives on the base row.
remote_session_issuers.passthrough isn't modeled. It's stored issuer config ("the MCP client registers and transacts directly with this issuer"), shown in admin views, not an outbound identity.
Nothing reads or writes these tables yet. The existing outbound configuration stays authoritative. The backfill and the admin runner phase follow in separate PRs.
Motivation
This is milestone 2 of RFC: Multiple Upstream Credentials for MCP Servers, With RBAC Control. Every existing upstream identity needs a stable, typed id before permissions (AIM-589/591) and the single resolver (AIM-594) can refer to it. EMA becomes an auth client a server offers, rather than something derived from its sign-in.
The regenerated sqlc files only add the new table models.
š¤ Generated with Claude Code
Summary by cubic
Adds the schema for typed MCP auth clients ā the ways an MCP server can authenticate to its upstream ā so each existing upstream identity gets a stable, typed ID before permissions and the unified resolver can reference it (AIM-588). Also adds a nullable requires_upstream_auth flag on mcp_servers (true needs auth, false explicitly needs none, NULL undecided). Nothing reads or writes these yet; the existing outbound configuration stays authoritative. The diff also carries unrelated changes merged in from main: the typed MCP route base (AIM-601), the hosted MCP orphan cleanup (AIM-580), hosted MCP server-key writes and flag removal (AIM-579), the agent provisioning wizard and identity page, the OAuth metadata discovery recovery (AIM-515), the refusal of Authorization as a configured header source (AIM-630), the OAuth token exchange error naming (AIM-388), the CLI rebrand to speakeasy, the Assistants rollout flag retirement, and a Mise header fix.
Schema
mcp_auth_clientsholds one row per client: stable id, org/project tenant, generatedattachment_scope,client_type,source(backfill|admin), name, enabled flag, and soft delete.- OAuth-backed types (
remote_session,service_account,ema) reference existingremote_session_clientsrows rather than copying them; composite FKs prevent a type row from attaching to the wrong client type or tenant. Static credentials and pass-throughs keep their material in headers. mcp_auth_client_emaspins the upstream issuer, registration, resource, and requested scopes, one row per issuer, registration, and resource.mcp_auth_client_headersstores client-owned headers;mcp_server_auth_clientsmaps which clients each server offers, many-to-many, withsourceso the backfill only retires links it created.client_typeandsourceare validated in application code, so a new type needs no migration.