Manage the OAuth connection lifecycle of a remote MCP server in OpenCode
Handle an OAuth-enabled remote MCP server through configuration, authorization, verification, disconnect, logout and reconnect.
Prerequisites and input · Engineering checks · 1. Confirm the server entry has OAuth enabled
At a glance
Remote MCP servers use OAuth by default and the authorization state lives outside the project configuration, so a server being in the configuration does not mean it is connected. For an OAuth-enabled remote server, this guide organizes authorization, verification, revocation and reconnecting, based on the OpenCode MCP page. Protocol field values it mentions are only restated as written, with no judgement about which revision is newer. The product was not run.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- OpenCode Manage the OAuth connection lifecycle of a remote MCP server in OpenCode
Execution locations and responsibilities
- OpenCode configuration loader and runtime Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.
When to use
- OAuth applies when
typeis remote andoauthis not false. The client identity is a pre-registeredclient_id, then CIMD, then DCR; secrets are referenced with{env:NAME}and kept out of the file.
When not to use
- The documentation describes
opencode mcp logoutas removing stored OAuth credentials; whether the authorization server invalidates tokens is not stated, so confirm server-side revocation with the provider. - Disconnecting in
/mcpsdoes not change configuration; to stay disconnected setdisabled, and to remove a server edit the configuration file. Do not treat the three as the same. - The
protocolfield defaults tolegacy, andautoprobes for the 2026-07-28 revision and falls back; the page gives these values and this guide draws no compatibility conclusion from them and calls no revision the newest.
Prerequisites and input
- You have a remote MCP server address that supports OAuth, an absolute Streamable HTTP endpoint, and you know which account you will sign in with.
- You understand that the configuration loader reads the configuration, the runtime stores authorization credentials outside project configuration, and the browser sign-in happens on an external authorization server.
- If OpenCode runs over SSH, in a container or on a remote server, you are ready to sign in from a browser on another machine and paste the callback address from its address bar back into the prompt.
Engineering checks
Before authorizing: configuration and client identity — OAuth applies when type is remote and oauth is not false. The client identity is a pre-registered client_id, then CIMD, then DCR; secrets are referenced with {env:NAME} and kept out of the file.
Verifying the connection: state, names and permissions — opencode mcp list shows connection state; tool names are the normalized <server>_<tool>; permission actions can hide or deny tools without disconnecting the server.
Revoking and reconnecting: configuration, credentials and connection are separate — Disconnecting in /mcps does not change configuration, disabled keeps it disconnected, deleting the entry removes the server, and opencode mcp logout clears stored OAuth credentials. The four do different things and cannot stand in for each other.
1. Confirm the server entry has OAuth enabled
Where: project or global opencode.jsonc, or written by opencode mcp add. Input: the server name and absolute URL. Action: confirm the entry has type remote, an absolute url, and no oauth set to false; turn OAuth off only when the server uses an API key or another header credential exclusively. Done when: opencode mcp list shows the server with needs authentication or connected. Stop if: the name is replaced wholesale by a same-named entry in a higher-precedence config and you did not repeat every required field; fix the entry first, and do not use one server name to stand for two accounts.
2. Choose the client registration path
Where: the server's oauth object. Input: the authorization server's capabilities and any credentials you were given. Action: OpenCode uses a pre-registered client (when client_id is configured), then CIMD (the authorization server supports both CIMD and public clients, and redirect_uri is not set), then DCR; if neither CIMD nor DCR is supported you must configure a pre-registered client. Setting redirect_uri disables CIMD. Set auth_server_metadata_url when the server does not publish protected resource metadata. Use client_secret only for a confidential client and reference it with {env:NAME}. Done when: you can state which path this server will actually take. Stop if: the server supports neither CIMD nor DCR and you have no pre-registered credentials; stop and ask the provider.
3. Complete authorization
Where: /mcps in OpenCode, or the command opencode mcp auth sentry (replace the name with yours). Input: the browser sign-in and consent. Action: select the server in /mcps and finish authorization in the browser; run opencode mcp auth without a name to pick from OAuth-capable servers. If the browser is on another machine, a page that does not load appears after sign-in; copy its address-bar callback address and paste it into the waiting sign-in prompt. Done when: the prompt finishes and control returns. Stop if: the page does not load and no prompt is available to paste into; the callback address carries authorization parameters, so treat it as sensitive and do not share it, which is a cautious inference from the documentation example, not a documented rule.
4. Verify the connection and available capabilities
Where: opencode mcp list and /mcps. Input: the server name. Action: confirm the state is connected; tool names follow <server>_<tool> with characters other than letters, numbers, _ and - replaced by _, so the normalized server name must stay unique; where needed, deny a server's tools with a <server>_* style permission action without disconnecting it. Startup and catalog listing each default to a 30 second timeout, and a slow server can be tuned under timeout. For form elicitation OpenCode shows a form and closing it cancels the request; URL elicitation presents a link that can be opened. Do not treat both modes as a form. Done when: state, tool names and permission expectations agree. Stop if: it stays connecting past those timeouts; stop and check timeout and protocol settings instead of repeating authorization.
5. Separate disconnect, disable, delete and logout
Where: /mcps, the configuration file and the command opencode mcp logout sentry. Input: what you want to achieve. Action: to stop temporarily, disconnect in /mcps, which does not change configuration; to keep it disconnected, set disabled in configuration; to remove it, delete the configuration entry; to switch accounts or sign in again, run opencode mcp logout, which removes stored OAuth credentials. Done when: opencode mcp list confirms the new state. Stop if: the documentation says logout removes stored credentials but does not say whether tokens are revoked at the authorization server, so if server-side invalidation is required, handle it with the provider; this guide makes no promise about it.
6. Reconnect and check identity
Where: the same server entry and /mcps. Input: the logged-out server. Action: authorize again; to use two accounts at once, use different server names, because sign-ins are stored per name. With pool on, directories share a connection only when URL, headers, OAuth settings, signed-in account and more all match under the same name, and only connections on the 2026-07-28 revision are shared. Done when: opencode mcp list shows connected and one low-risk tool call shows the expected account. Stop if: the account is wrong; go back to step 5 and log out; the ai.opencode/sessionID sent with tool calls is only a correlation value, so do not use it for authentication or authorization, and remote servers may log it.
Task example
Unexecuted walkthrough: remote server sentry permits OAuth. Inspect its actual connection state, authorize it and check effective tool names. To switch accounts use opencode mcp logout sentry to remove stored credentials; the source does not establish immediate disconnection or a required needs-authentication status. Record observed connection state separately, explicitly disconnect in /mcps when needed, then authorize and verify the account. Use separate server names when separate accounts need them. Actual authentication and server-side revocation still require verification; no such receipt exists here.
Completion checks
- Input ownership: server name, URL, account, registration path and credential location are recorded, and secrets appear only as
{env:NAME}. - Execution location: you can say that the loader reads configuration, the runtime handles authorization and token refresh, sign-in happens on the external authorization server, and what disconnect, disable, delete and logout each change.
- Result contract and stop: the
opencode mcp liststate before and after authorization is recorded, the state after logout and the reconnected account are checked, and you stopped on timeouts, an unloadable callback page or an unclear registration path.
Verification scope
The OpenCode MCP servers page was read. Installation, login, API execution and output were not tested. The server name and state changes are invented expectations and do not describe any real service.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.