Repository navigation
Labels
enhancementNew feature or request
Description
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; noengine/, protobuf, or ACP type. - Construct one server-owned handler during
Connect, attach it ininternal/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; wrapNewTokenSourceso access/refresh rotation CAS-writes the envelope. On CAS conflict orinvalid_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.goreuses the same handler/token source. - Concurrent 401s produce one authorization attempt.
- OAuth-disabled and static-header servers remain unchanged; static
Authorizationplus 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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
JAORMX commentedon Aug 14, 2026
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.feat(mcp): add durable OAuth controller
test(mcp): cover canceled OAuth handshake
feat(mcp): add durable OAuth controller (#559)