Description
What happens
opencode mcp auth <server> against any OAuth-protected MCP server fails immediately with Failed to get tools. The browser never opens; the callback server starts and sits there doing nothing.
What I expected
The browser opens, I log in, opencode picks up the code from the callback, exchanges it for tokens and stores them.
Why it happens
A race in MCP.startAuth(). The SDK's connect() resolves before kicking off the OAuth flow (which only starts on the first real request). startAuth() returns authorizationUrl="", authenticate() takes the "already authenticated" branch and calls defs() → listTools() on an unauthenticated client. That listTools() finally triggers OAuth, but by then defs() has already swallowed the UnauthorizedError and authenticate() returns status="failed". The browser never gets a chance.
Plugins
No response
OpenCode version
v1.15.6
Steps to reproduce
- Add an OAuth-protected MCP server to
~/.config/opencode/opencode.jsonc:
rm -f ~/.local/share/opencode/mcp-auth.json
opencode --log-level DEBUG --print-logs mcp auth myserver
Screenshot and/or share link
No response
Operating System
Ubuntu 25.10
Terminal
Tilix
Description
What happens
opencode mcp auth <server>against any OAuth-protected MCP server fails immediately withFailed to get tools. The browser never opens; the callback server starts and sits there doing nothing.What I expected
The browser opens, I log in, opencode picks up the code from the callback, exchanges it for tokens and stores them.
Why it happens
A race in
MCP.startAuth(). The SDK'sconnect()resolves before kicking off the OAuth flow (which only starts on the first real request).startAuth()returnsauthorizationUrl="",authenticate()takes the "already authenticated" branch and callsdefs()→listTools()on an unauthenticated client. ThatlistTools()finally triggers OAuth, but by thendefs()has already swallowed theUnauthorizedErrorandauthenticate()returnsstatus="failed". The browser never gets a chance.Plugins
No response
OpenCode version
v1.15.6
Steps to reproduce
~/.config/opencode/opencode.jsonc:{ "mcp": { "myserver": { "type": "remote", "url": "https://mcp.example.com", "enabled": true } } }rm -f ~/.local/share/opencode/mcp-auth.jsonopencode --log-level DEBUG --print-logs mcp auth myserverScreenshot and/or share link
No response
Operating System
Ubuntu 25.10
Terminal
Tilix