Skip to content

fix(mcp): handle oauth flows that connect without tokens#27785

Open
ImDevinC wants to merge 3 commits into
anomalyco:devfrom
ImDevinC:fix/mcp-oauth-5953
Open

fix(mcp): handle oauth flows that connect without tokens#27785
ImDevinC wants to merge 3 commits into
anomalyco:devfrom
ImDevinC:fix/mcp-oauth-5953

Conversation

@ImDevinC
Copy link
Copy Markdown

@ImDevinC ImDevinC commented May 15, 2026

Issue for this PR

Closes #5953

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This fixes the MCP OAuth path where a remote server can complete transport setup without ever persisting OAuth credentials. Instead of treating that as a successful auth, the MCP service now keeps the server in needs_auth, surfaces a clearer CLI error, and preserves the explicit startAuth() redirect flow for servers that can connect anonymously before OAuth is completed.

How did you verify your code works?

I validated it with targeted MCP coverage:

  • bun test test/mcp/oauth-auto-connect.test.ts test/mcp/oauth-browser.test.ts test/mcp/lifecycle.test.ts
  • bun typecheck
  • manual verification with a clean data dir in a separate workdir:
    XDG_DATA_HOME="$(mktemp -d)" "$HOME/Projects/opencode/packages/opencode/dist/opencode-darwin-arm64/bin/opencode" mcp auth slack --log-level DEBUG

Screenshots / recordings

N/A, no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Treat MCP servers that can connect their transport without actually persisting OAuth credentials as still needing authentication. This keeps MCP auth state, CLI messaging, and the explicit startAuth flow aligned for issue anomalyco#5953.

Fixes anomalyco#5953

Tested:

- bun test test/mcp/oauth-auto-connect.test.ts test/mcp/oauth-browser.test.ts test/mcp/lifecycle.test.ts

- bun typecheck

- reviewed the MCP-only diff against CONTRIBUTING.md and .github/pull_request_template.md to confirm the change stays scoped to the auth fix and includes targeted regression coverage

Co-authored-by: opencode <noreply@opencode.com>
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found a potentially related PR:

Related PR:

The other OAuth-related PRs (#27068, #26854, #23572) are about different aspects of OAuth handling (discovery, scope metadata, callback server cleanup) and don't appear to be duplicates of the current fix.

@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

Comment thread packages/opencode/src/mcp/auth.ts
ImDevinC and others added 2 commits May 16, 2026 02:02
Stop persisting MCP auth records when only the server URL remains after credentials are invalidated. This keeps logout state aligned with actual OAuth material during the issue anomalyco#5953 fix.

Tested:

- bun test test/mcp/oauth-auto-connect.test.ts

- bun typecheck

Co-authored-by: opencode <noreply@opencode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reauthentication with Jira MCP via Oauth doesn't work

2 participants