ADR 0004: OAuth per Principal for Remote MCP Servers
Status: accepted, 2026-11-14; amended by ADR 0012, decision 8, on 2026-11-19: the sign-in is a signin card in the requester's direct chat, refused in groups, and a person's token i
Status: accepted, 2026-11-14; amended by ADR 0012, decision 8, on 2026-11-19: the sign-in is a sign_in card in the requester's direct chat, refused in groups, and a person's token is their credential mcp:<server>.
Context
Remote MCP servers (issue trackers, docs, mail) act on a person's own account and require OAuth 2.1 sign-in (MCP authorization, 2025-06-18 and later). Today a URL server gets only static headers from the instance configuration, so one token would act for every person who talks to the Host. A sign-in needs things no plugin can provide: a redirect URI the browser returns to, flow state that survives the wait, and token storage bound to the person, not to the instance. The Host has no HTTP listener of its own; the httpapi channel is a plugin.
Decision
- Host listener. The Host configuration gains
oauth: {listen, public_url}. Withlistenset the Host servesGET /oauth/callbackandGET /oauth/client.json(a Client ID Metadata Document) on that address;public_url(defaulthttp://{listen}) is how browsers reach it. Withoutoauth, servers that need sign-in reportmcp.oauth_unavailableand offer no tools. - Which servers. A manifest server declares
auth: oauth(optionalscopes), or the Host learns it the first time the server answers401withWWW-Authenticate: Bearer. Staticheadersstay for servers with a shared key. - Flow (
internal/oauth). Discover the protected resource metadata (RFC 9728, fromresource_metadatainWWW-Authenticateor the well-known path) and the authorization server metadata (RFC 8414, then OpenID discovery). The client is the operator'sclient_idoption if set, else the metadata document whenpublic_urlishttpsand the server supports it, else Dynamic Client Registration (RFC 7591), cached per (instance, issuer). Authorize with PKCES256,stateand theresourceparameter (RFC 8707); checkisson the redirect when the server announces it (RFC 9207). Flow state is a row inoauth_flowsbound to (instance, principal, server) with the verifier, and expires after 10 minutes. - Tokens. Stored in the existing encrypted secret store under (instance, principal) as
oauth:{server}, the principal being the person when principals are linked. Refreshed when less than 60 s remain; a failed refresh deletes them, so the person signs in again. - Sessions per principal. A server with OAuth gets one MCP session per (server, principal), carrying that principal's token, closed after 10 idle minutes; a
401during a session refreshes once, then asks for sign-in. - What the model sees. For a principal without a token the server's tools are not listed; instead
{prefix}__sign_in(no arguments, description: sign in to the service so its tools become available; ask the user first). It asks the person a link question withDoneandCancel; the browser lands on the callback, which stores the tokens. The tools appear from the person's next message, because a run's tool list is pinned.
Consequences
- ◆New Host configuration (
oauth), a manifest field (auth,scopes), a store table (oauth_flows) and an HTTP listener. No plugin API changes: the manifest adapter (internal/bundle) reaches the flow through a Host-internal port. - ◆A Host reachable only on loopback can sign in only people whose browser runs on that machine; a team Host needs a
public_urlits users can reach, preferablyhttps. - ◆In a group conversation the link question is shown in that conversation; sending it to the requester's direct chat is not part of this decision.
- ◆Tokens never reach the model, the logs or the checkpoint.
Design: MCP section 9.