feat: resolve upstream tokens without the sign-in on the enforced path
AIM-594
Stacked on #7818 (← #7813 ← #7810 ← #7768 ← #7761 ← #7653)
Summary
- Sign-in-free token lookup on the enforced path. When the auth client resolver is enforced, a
remote_sessionorservice_accountclient looks up the stored token by user and registration (GetActiveRemoteSessionInTenant,GetTenantUserRemoteSessionForClient). The registration no longer needs a link to the server's sign-in, so one consent serves every server the registration reaches. - Reach follows the registration's scope:
- a project registration serves only that project
- an org-shared registration serves any project in the consent's org
- a global registration serves only the consent's org, never another one
- Deleted sign-ins still count. A consent made through a sign-in that was later deleted still serves its org. The decoupled lookup drops the
NOT deletedfilter on the consent's sign-in and uses it only to find the org. - Cross-org re-consent creates a new grant. If a user re-consents a registration through another org's sign-in, the old grant is tombstoned (
SoftDeleteRemoteSessionConsentedInOtherOrganization) and a new one is written, instead of the old row moving orgs in place. Any agent attachment on the old grant has to be re-attached. - Callers are routed explicitly. Workloads, principal credentials and attachments are checked in that order (
attachedCaller), so each one reaches the lookup meant for it. - The lookup mode is explicit. A
tokenLookupvalue (lookupSignInorlookupAuthClient) replaces the implicit branching, and the sign-in path is unchanged.
Motivation
The RFC "Multiple Upstream Credentials for MCP Servers" separates the inbound sign-in from upstream auth. Until now a token was found through the sign-in link, so two servers on different sign-ins couldn't share a consent even when they share the registration. Users had to reconnect, and moving a server to a new sign-in orphaned its tokens.
Keying on the registration's own scope makes one consent work across servers without crossing org boundaries. Because the consent's org is now what scopes the lookup, a cross-org re-consent writes a new grant rather than silently moving the old one into a new tenant.
Notes
- With the resolver flags off, token lookups are unchanged. The cross-org grant replacement applies to consent writes in every mode.
- Agent attachments are still keyed by sign-in; moving them to the registration is deferred to AIM-593.
- Gateway members come in a later PR.
🤖 Generated with Claude Code
Summary by cubic
Resolves upstream tokens through the OAuth registration when the auth client resolver is enforced, so a personal connection or service account no longer needs a link to the server's sign-in. One consent serves every server the registration reaches, and lookups are unchanged when the resolver flags are off.
Behavior
- A project registration serves that project; an org-shared registration serves any project in the consent's org; a global registration serves only that org.
- A consent through a deleted sign-in still serves its org; a login state without an organization is rejected so a re-consent can't overwrite another org's grant.
- Re-consenting through another org's sign-in writes a new grant in that org and tombstones the old one, clearing its identity without revoking the upstream credential (which would revoke the new consent too); workloads and agents in the first org must reconnect, and agent attachments must be re-attached.
- A grant resolved for the authorizer is rechecked after a blocking refresh, so a stale grant doesn't keep serving the session.
- Callers are routed explicitly (workloads, principal credentials, attachments) and the lookup mode is explicit (
lookupSignInorlookupAuthClient). - Member MCP connection status reads the same way: when enforced,
get_my_mcp_connection_statuslists the proxied server's reachable associated registrations without the sign-in link and reports a grant only where the resolver would serve it.
Notes
- Agent attachments are still keyed by sign-in; moving them to the registration is deferred to AIM-593, and gateway members land in a later PR.