Skip to content

mcp: OAuth loopback callback fails with a remote OpenCode server #59869

Closed as duplicate

Description

@Sc0th

Description

MCP OAuth authorization fails when OpenCode is running as a remote server and the authorization browser is on a different device. The OAuth URL uses a loopback redirect (http://127.0.0.1:<port>/callback), which points to the browser’s device, not the remote OpenCode server that initiated authorization.

Plugins

notify-pushover, @openclient-ios/[email protected], [email protected]

OpenCode version

OpenCode version: 2.2.0

Steps to reproduce

  1. Connect a client to an OpenCode server running on a different host.
  2. Open /mcps and authorize the remote MCP server at https://opencode.ai/console/mcp.
  3. Complete authorization in a browser on the client device.
  4. The authorization URL redirects to http://127.0.0.1:<ephemeral-port>/callback, and authorization fails because that loopback address is on the browser’s device, not the OpenCode server.

Expected Behavior

 OAuth authorization should complete when using a remote OpenCode server, without requiring the browser device to reach the server through a manually configured tunnel.

Actual Behavior

 The callback targets the browser device’s loopback address, while the OpenCode server is on another host. Authorization cannot complete. In this environment, network policy prevents using an SSH tunnel as a workaround.

Additional Context

 The redirect URI observed was `http://127.0.0.1:36857/callback` (port varies). OAuth query parameters have been omitted. A remote-safe callback mechanism or device-code/manual-code flow would avoid this limitation.

Screenshot

No response

Operating System

Alma 10

Terminal

Bash

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the clear report, @Sc0th!

    I think this is a duplicate of #54495. It asks for MCP OAuth to work when the browser is on a different machine than the OpenCode server, using the paste-the-redirect-URL/code fallback you suggested. There's also an open PR for it, #58370, which names a TUI attached to a remote server as one of the cases it fixes.

    Possible duplicates and related issues, ordered from most to least likely:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Closing this as a duplicate of #54495. That issue covers MCP OAuth failing when the browser is on a different machine from the OpenCode server, because the callback listens only on the server's 127.0.0.1. There's also an open PR for it, #58370, which would let you finish sign-in by pasting the redirect URL from your browser. Please follow #54495 for updates.

    If your case turns out to be different, reply here with the details and we can reopen. Thanks again for the clear report, @Sc0th!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions