GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(mcp): add OAuth redirect URI configuration for MCP servers by christso · Pull Request #9034 · anomalyco/opencode

Conversation

@christso

@christso christso commented Jan 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Re-implements the redirectUri option for MCP OAuth configuration, allowing users to specify a custom callback URL for OAuth flows.

  • Adds redirectUri config option to McpOAuth schema
  • Updates McpOAuthProvider to use custom redirect URI when provided
  • Updates McpOAuthCallback.ensureRunning() to support custom port/path
  • Adds parseRedirectUri() utility function

Key difference from original PR #7379: The OAuth callback server is now started lazily in startAuth() only when authentication is actually needed, rather than preemptively in create() for all remote servers. This fixes the regression where non-OAuth MCP servers would fail to connect.

Closes #7377

Test plan

  • Existing MCP tests pass (6 tests)
  • New parseRedirectUri tests pass (3 tests)
  • New ensureRunning with custom redirectUri test passes (1 test)
  • Manual test: Context7 remote MCP server connects without OAuth callback server
  • Manual test: Local filesystem MCP server connects normally

Manual test results

┌  MCP Servers
│
●  ✓ context7 connected
│      https://mcp.context7.com/mcp
│
●  ✓ filesystem connected
│      npx -y @modelcontextprotocol/server-filesystem /tmp
│
└  2 server(s)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zeval, egze, marcomicera, rbino, Tien-Lam, domsleee, nazeel-esper, cristinecula, aashish2057, la55u, and 5 more reacted with heart emoji
All reactions
  • ❤️ 15 reactions
@christso @claude
feat(mcp): add OAuth redirect URI configuration for MCP servers
79503a6
Re-implements the redirectUri option for MCP OAuth configuration, allowing
users to specify a custom callback URL for OAuth flows.

Key difference from original PR anomalyco#7379: the OAuth callback server is now
started lazily in startAuth() only when authentication is actually needed,
rather than preemptively in create() for all remote servers. This fixes the
regression where non-OAuth MCP servers would fail to connect.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions Bot added the needs:issue label Jan 17, 2026
@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

christso reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

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

No duplicate PRs found

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:issue label Jan 17, 2026
@christso christso mentioned this pull request Jan 17, 2026
[FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers #7377
Closed
christso and others added 2 commits January 17, 2026 18:43
@christso
Merge branch 'dev' into fix/mcp-oauth-redirect-v2
c24b737
@christso @claude
feat(mcp): pass redirectUri to OAuth provider in debug command
5ca5221
Ensures the debug command uses the configured redirectUri when testing
OAuth flows, making it consistent with the main auth flow.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This was referenced Jan 17, 2026
feat(mcp): support explicit OAuth callback host binding #9078
Closed
docs: document MCP OAuth redirect URI for pre-registered clients #9908
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:49
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@github-actions github-actions Bot mentioned this pull request Jan 31, 2026
feat(app): add MCP OAuth authentication UI to settings #11477
Closed
@christso
Merge branch 'dev' into fix/mcp-oauth-redirect-v2
2e984bc
@github-actions github-actions Bot mentioned this pull request Feb 3, 2026
feat(tui): add MCP OAuth authentication in dialog-mcp #11925
Closed
@egze

egze commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. I am directly affected that I can't set a custom redirectUri.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@christso

christso commented Feb 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Here's the configuration that Claude Code supports when I run claude mcp add -h. OpenCode should also support defining the callback port or URI.

Options:
  --callback-port <port>       Fixed port for OAuth callback (for servers requiring pre-registered redirect URIs)
  --client-id <clientId>       OAuth client ID for HTTP/SSE servers
  --client-secret              Prompt for OAuth client secret (or set MCP_CLIENT_SECRET env var)
  -e, --env <env...>           Set environment variables (e.g. -e KEY=value)
  -H, --header <header...>     Set WebSocket headers (e.g. -H "X-Api-Key: abc123" -H "X-Custom: value")
  -h, --help                   Display help for command
  -s, --scope <scope>          Configuration scope (local, user, or project) (default: "local")
  -t, --transport <transport>  Transport type (stdio, sse, http). Defaults to stdio if not specified.

It's been a while since I submitted the PR because I was happy with the workaround of running a script to copy the MCP token from CC to OpenCode. But it seems a lot of my colleagues are not happy with the workaround, so I'm revisiting this.

Risk analysis

This is a v2 of #7379, which was reverted due to a regression where the OAuth callback server was started eagerly in create() for all remote servers, causing non-OAuth MCP servers (e.g. Context7) to fail.

The regression is fixed in this version. The key change is lazy initialization -- ensureRunning() is now only called inside startAuth(), which is only triggered when OAuth authentication is actually needed. Non-OAuth servers never call startAuth(), so they are unaffected.

Theoretical race condition in the stop/restart logic is not a practical concern. The code stops and restarts the callback server when ensureRunning() is called with a different port/path, which clears all pending OAuth callbacks. However, authenticate() is user-initiated and sequential -- a user would have to be mid-OAuth-flow for one server and simultaneously trigger OAuth for a second server with a different redirectUri. The single-threaded event loop and the interactive nature of OAuth (browser redirect, user action) make this effectively impossible in normal usage.

Ready to merge. @rekram1-node

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@christso
Merge branch 'dev' into fix/mcp-oauth-redirect-v2
03388a0
christso
christso commented Feb 17, 2026
View reviewed changes
Comment thread packages/opencode/src/mcp/oauth-callback.ts Outdated
Comment on lines +67 to +71
// If server is running on a different port/path, stop it first
if (server && (currentPort !== port || currentPath !== path)) {
log.info("stopping oauth callback server to reconfigure", { oldPort: currentPort, newPort: port })
await stop()
}

@christso christso Feb 17, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy initialization fix for the regression in #7379 -- this stop/restart path is only reachable during an active OAuth flow (via startAuth()), so non-OAuth servers are never affected. The theoretical race with concurrent different-redirectUri auths is not a practical concern since authenticate() is user-initiated and sequential.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dbpolito

dbpolito commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

would love to see this one merged to use github mcp with oauth

benceferdinandy-signifyd reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Mar 6, 2026
fix(mcp): generate OAuth state on-the-fly during initial connection #16248
Closed
3 of 6 tasks
@chandlerok

chandlerok commented Mar 18, 2026

Copy link
Copy Markdown

would love to see this merged

benceferdinandy-signifyd reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benceferdinandy-signifyd

benceferdinandy-signifyd commented Mar 19, 2026

Copy link
Copy Markdown

@christso seems this ran ontu a merge conflict. would be nice to see this merged ..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fbxai fbxai mentioned this pull request Apr 3, 2026
feat(opencode): Enable oauth redirect #20812
Closed
3 of 6 tasks
@egze egze mentioned this pull request Apr 7, 2026
feat(mcp): add OAuth redirect URI configuration for MCP servers #21385
Merged
3 of 6 tasks
@egze

egze commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@christso I made a new PR based on yours #21385

If you still want to make the changes in your branch - just tell me and I'll close mine. I just need this feature so badly 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

egze added a commit to egze/opencode that referenced this pull request Apr 7, 2026
@egze
feat(mcp): add OAuth redirect URI configuration for MCP servers
73cb540
Adds `redirectUri` config option to MCP OAuth, allowing users to specify
a custom callback URL for OAuth flows. The callback server dynamically
reconfigures its port and path based on the provided URI.

Based on anomalyco#9034, adapted for the current codebase
which uses Node http.createServer instead of Bun.serve.
@mzyil

mzyil commented Apr 8, 2026

Copy link
Copy Markdown

any updates on this?

primeroz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@christso
Merge remote-tracking branch 'origin/dev' into fix/mcp-oauth-redirect-v2
c64b540
# Conflicts:
#	packages/opencode/src/cli/cmd/mcp.ts
#	packages/opencode/src/config/config.ts
#	packages/opencode/src/mcp/index.ts
#	packages/opencode/src/mcp/oauth-callback.ts
#	packages/opencode/src/mcp/oauth-provider.ts
@christso

christso commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #21385 — closing this PR.

Thanks @egze for picking this up and re-implementing it for the current codebase! The Node http.createServer adaptation was the right call given the upstream changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@christso christso closed this May 7, 2026
@christso
christso deleted the fix/mcp-oauth-redirect-v2 branch May 7, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@christso @egze @dbpolito @chandlerok @benceferdinandy-signifyd @mzyil
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.