feat(mcp): sign in to upstream MCP servers with OAuth from the dashboard

SA
4d ago
+3705-25

Operators can now sign in to MCP servers that need OAuth (Notion, Linear, Atlassian, ...) from the dashboard's MCP Servers page. Servers that answer 401 show Sign-in required. The sign-in follows the MCP authorization spec: discovery through protected resource metadata, then authorization server metadata (RFC 8414 or OIDC), S256 PKCE required, the RFC 8707 resource parameter on every token request, state and RFC 9207 iss checks, and dynamic client registration, with a field for a pre-registered client ID when the server has none. Tokens are stored sealed with GOMODEL_ENCRYPTION_KEY, refreshed with refresh-token rotation, and never logged or returned by the admin API.

Part of #1222

Decisions

  • One sign-in per server for the whole gateway (a shared session, matching how upstreams work today). It works for both dashboard-managed and config.yaml HTTP/SSE servers.
  • Tokens live in a new mcp_server_oauth table/collection as one sealed record. gomodel secrets reencrypt covers it.
  • The callback at /admin/mcp-oauth/callback skips bearer auth. A single-use state with a 10 minute TTL, plus an HttpOnly binding cookie set by the start call, authenticate it instead. Failure details are shown on the server row, never in the redirect URL.
  • A signed-in token replaces a static Authorization header and is only sent to the server's own origin. Changing the server URL stops using its tokens.

Left for later

  • Client ID Metadata Documents (needs a public HTTPS client metadata URL).
  • Step-up authorization on 403 insufficient_scope, and per-user upstream tokens.
  • Token revocation (RFC 7009) on sign-out.
  • Pending sign-ins are kept in memory, so with several replicas the callback needs sticky sessions. Refreshed tokens already reach the other replicas through the database.

Summary by CodeRabbit

  • New Features
    • Added interactive OAuth sign-in and sign-out for supported MCP servers through the dashboard, with visible authorization status and error details.
    • Added support for OAuth token refresh and encrypted storage.
  • Documentation
    • Expanded MCP Gateway guides with sign-in steps, supported options, status handling, and security details.
    • Updated encryption documentation to include OAuth credentials and tokens.