We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

OAuth

OpenCode supports two forms of authentication:

  • API-key-style auth through custom headers
  • OAuth flows that OpenCode can kick off and manage

For simple OAuth-enabled servers, OpenCode can detect the auth requirement, kick off the flow, and store the resulting tokens for future use. The config is usually simple:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "notion": {
        "type": "remote",
        "url": "https://mcp.notion.com/mcp",
      },
    },
  },
}

When the server reports that it needs authentication, start the sign-in flow from OpenCode's MCP interface or with opencode mcp auth <name>. Open the authorization URL it gives you in a browser.

OpenCode stores the resulting credentials outside your project configuration. You shouldn't need to manage that storage directly. Use opencode mcp logout <name> when you want to remove credentials.

More Complex Flows

Where this gets a bit hairier is if the MCP server doesn't support Dynamic Client Registration. In that case (like with the GitHub MCP), you need to register and provide a client ID and secret in the config (guh):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "github": {
        "type": "remote",
        "url": "https://api.githubcopilot.com/mcp/",
        "oauth": {
          "client_id": "{env:GITHUB_MCP_CLIENT_ID}",
          "client_secret": "{env:GITHUB_MCP_CLIENT_SECRET}",
        },
      },
    },
  },
}

CLI Commands

If you're having trouble with authentication, here are a few of the commands that can help you debug:

  • opencode mcp list: List all servers and their authorization status.
  • opencode mcp auth <name>: Authenticate with an MCP server.
  • opencode mcp logout <name>: Remove stored credentials.

Assignment

Give OpenCode access to a Notion page through OAuth, then have it read the page.

Tell OpenCode to run and submit the CLI tests from the project root. Connection failures carry no penalty.