Skip to content

MCP OAuth controller: durable refresh and reconnect reuse #521

Description

@JAORMX

Parent: #518

Outcome

Attach one official AuthorizationCodeHandler to each OAuth-enabled MCP server, restore credentials before connection, persist token/client changes safely, and retain authorization state across existing MCP reconnects.

Design requirements

  • Add adapter-local OAuth policy/options under internal/adapter/mcp; no engine/, protobuf, or ACP type.
  • Construct one server-owned handler during Connect, attach it in internal/adapter/mcp/mcp.go (Server.dial), and retain it across reconnects.
  • Define a versioned OAuth credential envelope in the MCP OAuth package, not the generic store. Persist the whole lifecycle as one opaque record.
  • Credential identity includes stable principal/profile, canonical MCP resource, exact authorization-server issuer, and client identity; never only the configured server name.
  • Restore through InitialTokenSource; wrap NewTokenSource so access/refresh rotation CAS-writes the envelope. On CAS conflict or invalid_grant, reload once rather than overwriting/retrying stale refresh state.
  • Coalesce authorization/refresh transitions per credential identity; no background refresh goroutine.
  • Use a distinct hardened OAuth HTTP client with response/time bounds, redirect limits, DNS pinning/rebinding defense, and explicit policy for configured internal deployments. Never attach static MCP headers to OAuth endpoints.
  • Return typed, redacted login-required/unavailable errors. A noninteractive/nil presenter never starts UI.

Acceptance criteria

  • Fresh authorization reaches tool listing exclusively through the official SDK handler.
  • Warm restart restores credentials without invoking the fetcher.
  • Expiry refreshes and persists rotated refresh state with CAS; stale writers cannot replace the winner.
  • Existing internal/adapter/mcp/reconnect.go reuses the same handler/token source.
  • Concurrent 401s produce one authorization attempt.
  • OAuth-disabled and static-header servers remain unchanged; static Authorization plus OAuth fails before connect.
  • Cross-origin redirects receive neither static nor OAuth bearer credentials.
  • Diagnostics, errors, inventory, model events, and ACP contain no OAuth artifacts.

Verification

Adapter unit tests plus offline OAuth/MCP fixtures for fresh auth, warm restore, rotation, CAS conflict, invalid grant, concurrency, reconnect, hostile redirects/DNS, cancellation, and redaction canaries.

Dependencies and sizing

Blocked by the credential-store and SDK-qualification issues.

Size: L–XL. Complexity: high/security-critical. Execution: chunk controller/envelope first, network policy and integration second.

Activity

  1. self-assigned this
    on Aug 14, 2026
  2. added
    enhancement
    on Aug 14, 2026
  3. JAORMX commented on Aug 14, 2026

    @JAORMX
    ContributorAuthor

    Implementation is complete on feat/issue-521-mcp-oauth-controller, stacked on the #519 credential-store and #520 SDK-qualification branches. It includes the durable CAS envelope/controller, official SDK handler reuse across reconnect, hardened no-proxy/DNS-pinned OAuth and MCP transports, exact issuer/credential egress gates, authorization singleflight, lifecycle cancellation, safe errors, and ADR 0110. Security and QA repair waves are complete; task lint, task test, docs checks, race tests, and the offline demo pass. The branch is pushed but the PR is intentionally waiting for #536/#537 to land so its base/diff is clean.

  4. added 2 commits that reference this issue on Aug 15, 2026
    ec657aa
    ee11f61
  5. added a commit that references this issue on Aug 15, 2026
    99cb04f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions