feat: persist explicit MCP server OAuth client associations
Summary
Populates the MCP server ↔ upstream OAuth client associations from the schema PR below this one, without changing how serving resolves sign-in.
-
Explicit configuration.
commitServerIdentityConfiguration(dashboard and the Platform MCPattach_platform_mcp_identity_providertool) associates the configured server, and only that server, with the chosen client. The Platform MCP path now locks the server row before the issuer, the same order MCP server updates use. -
Transitional capture. The post-commit issuer resync that every binding write already runs now also reconciles associations:
- it prunes associations whose client is no longer bound to the server's issuer, or that point at a deleted client or server;
- it associates every bound client with a server that is its issuer's only consumer (no sibling server, no gateway).
Bindings on shared issuers are never copied onto every server. Organization-client deletion, global-client deletion and
removeClientFromMcpServerdidn't run that resync, so they now prune the client's associations directly. MCP server delete and issuer removal prune too. -
Management API. Adds
remoteSessions.listServerClientAssociations(mcp:read), which returns each client withserver_count, andremoteSessions.detachServerClientAssociation(mcp:write, audited asremote-session-client:detach-mcp-server). Detach removes only that server's row and never the client. It returns a conflict for a sole consumer's own binding, which would be re-derived; User Identity is turned off instead. -
Dashboard. The User Identity settings say when the connected client also signs in other MCP servers.
-
Backfill. Adds the
associationbackfillpackage (server/internal/mcpservers/upstreamclients/associationbackfill). It runs per organization, and its dry run decides without writing. A server alone on its issuer gets every bound client. On a shared issuer, a server gets the one client its own RFC 9728 metadata names, else the one client holding grants for its upstream, else the one client whose authorization server is the server's derived one: the same evidence gateway members use. A server with no evidence for any client uses none (no_client), and a detached client stays detached. Only conflicting evidence is leftambiguousfor an administrator. Writes are conditional on the evidence still holding and are idempotent. Staff run it from the admin dashboard in #7659. -
Gateway-fronted servers. A gateway issuer binds one client per member authorization server, and requests route members to those clients by the RFC 8707 resource recorded on each grant. The backfill also decides every server a gateway issuer fronts: members of a stored gateway, and every server of the organization for the organization gateway's issuer.
- A client the issuer binds whose live grants name the server's remote upstream URL is associated first, whichever issuer minted the grant. This is the comparison request routing makes today. A tunnel's resource identifier is only what the tunnel claims, so tunnels are decided by derived issuer alone.
- Failing that, the one client matching the server's derived authorization server is associated. This is how consent claimed members.
- Several matches, or grants and the derived issuer disagreeing, are left unresolved for an administrator. A server none of the issuer's clients serve is left alone, as the gateway serves it no credential today either.
- Binding and gateway membership changes capture the derived match as they happen; adding or removing a gateway member, or deleting a gateway, now reconciles. The prune keeps an association while any issuer reaching the server (its own, a gateway it belongs to, or the organization issuer) still binds the client. Pruned rows are deleted outright, so a soft-deleted row only ever records an explicit detach, and a server that rejoins a gateway is captured again.
- Evidence for these rules was checked against production data (read-only); the findings are on AIM-587.
-
Hosted and unproxied servers keep serving from the issuer's bindings, so one on a shared issuer that no configuration decides is reported as
unproxiedand is not a gap. -
Demo seed. Writes each seeded server's associations, and fails the seed if any is missing.
Supported combinations. Associations stay within what issuer bindings would serve until cutover. Hosted servers with several upstreams on their own issuer get every client. Nothing adds a singular-client rule or a multiple-alternative-client UX.
Platform MCP / Admin MCP. The attach tool records associations through the shared committer. The status and readiness tools keep reading the current serving path, so they're unchanged until cutover (AIM-586). The staff Admin MCP has no server-auth inspection tool that reads clients, so nothing needs parity yet.
Motivation
The serving path will select a server's upstream client from explicit associations (AIM-585, AIM-586) instead of deriving it per user session issuer, which breaks once several servers share an organization issuer (AIM-577). This PR is the additive preparation: it captures configuration as it changes and backfills existing state, while the current runtime stays authoritative.
Gutternote review steps
- Sidebar → MCP → open a remote MCP server that uses User Identity → Settings → Authentication (
/<org>/projects/<project>/mcp/x/<server>/settings). - When the server's OAuth client is also associated with other servers, a muted line under the provider row reads "This client also signs in N other MCP servers. Changing or rotating it changes their sign-in too."
- A server whose client serves only it shows no extra line. The seeded Linear server is in this state.
Summary by cubic
Persists which upstream OAuth client each MCP server signs in with, so a server sharing an issuer with siblings can be served its own client later, and the dashboard can warn when one client serves several servers. Sign-in still resolves through issuer bindings today; this change records the configuration explicitly.
- Setting User Identity on one server associates only that server with the chosen client; the Platform MCP attach tool locks, rechecks, and verifies the server's source and issuer before registering. A commit or attach that can't record the association fails.
- Reconciliation on binding writes and client/server deletion keeps associations aligned with current issuer bindings, pruning stale entries and deriving sole-consumer associations, ignoring servers and gateways in soft-deleted projects. Gateway associations require a live tenant issuer or the organization's only live gateway issuer; grants count only through issuers of the server's organization.
- New management endpoints
listServerClientAssociationsanddetachServerClientAssociation(both audited) let callers inspect and remove a single server's association without touching the client. - Dashboard shows a muted line when the server's client also signs in other servers, and skips the association read without
mcp:read. - A rerunnable backfill lives in the server as a package the admin service runs per organization, reporting
unbound,configured, andambiguousservers from issuer bindings and server metadata. It decides every proxied server, including those on a shared issuer, by grant resource first then derived issuer; conflicts and no-gateway-client cases remain unresolved. Hosted and unproxied servers keep serving through the issuer's bindings. - Demo seed writes the Linear server's association and each EMA service's own client, with postflight verifying all four seeded associations.
Migration
- Run the backfill package per organization in dry-run mode first; activate only when the report shows no gaps or skips. It is idempotent and respects explicit detaches on shared issuers.
🚀 Preview Environment (PR #7644)
Preview URL: https://pr-7644.dev.getgram.ai
| Component | Status | Details | Updated (UTC) |
|---|---|---|---|
| ✅ Database | Ready | Existing database reused | 2026-10-20 11:46:54. |
| ⏭️ Images | Superseded | Newer commit pushed, re-syncing | 2026-10-20 11:59:03. |
Gram Preview Bot