opencode icon indicating copy to clipboard operation
opencode copied to clipboard

opencode mcp auth fails silently in remote/headless sessions (SSH, devcontainer)

Open danlapid opened this issue 1 month ago • 3 comments

Description

When running opencode mcp auth in a remote or headless environment (SSH, devcontainer, WSL without display), the command fails with a cryptic "Something went wrong" error because it cannot open a browser.

The open package tries to launch xdg-open (on Linux) which either:

  • Doesn't exist (ENOENT error)
  • Exists but fails because there's no display server

In both cases, the user has no way to complete the OAuth flow because the authorization URL is not shown.

Expected Behavior

When browser opening fails, the authorization URL should be displayed so users can manually copy it and open it in a browser on their local machine.

Actual Behavior

$ opencode mcp auth jira --log-level DEBUG --print-logs true
...
INFO  opening browser for oauth
▲  Something went wrong
ERROR e=Executable not found in $PATH: "xdg-open" exception

OpenCode version

1.1.8

Steps to reproduce

  1. SSH into a remote server or use a devcontainer
  2. Run opencode mcp auth <server-name>
  3. Observe the error with no actionable information

Operating System

Linux (tested in devcontainer)

Terminal

Any

danlapid avatar Jan 11 '26 23:01 danlapid

This issue might be a duplicate of existing issues. Please check:

  • #7114: Claude Pro/Max authentication not usable over SSH (same issue with browser opening and inability to copy authorization URLs in remote/headless environments)

Feel free to ignore if this doesn't address your specific case.

github-actions[bot] avatar Jan 11 '26 23:01 github-actions[bot]

I did read #7114 and I don't think it's an exact duplicate, this issue is very specific the other is a bit general and vague.

danlapid avatar Jan 11 '26 23:01 danlapid

I ran into this, too. Getting around xdg-open requirement is one step, I did this to try and move forward:

#!/bin/bash
# Install at: /usr/local/bin/xdg-open
# Opens URL in host browser via VS Code's browser helper
if [[ -n "$BROWSER" ]]; then
    "$BROWSER" "$1"
else
    echo "xdg-open: $1"
fi

That opens the browser for auth just fine, but the callback URL is http://127.0.0.1:19876/mcp/oauth/callback and when I look in my devcontainer (which is patiently waiting now, rather than giving the Something went wrong error) I don't see opencode (or anything) listening on 19876. So even with the port forwarded to the devcontainer, clicking anything in my browser just hangs.

bretthoerner avatar Jan 12 '26 22:01 bretthoerner