Guide

How to Add MCP Servers to OpenCode

OpenCode has a dedicated mcp sub-command surface — add, list, auth, logout, and debug — that makes connecting Model Context Protocol servers straightforward once you know the exact commands. This guide walks through every step: installing an MCP server, authenticating OAuth-enabled servers, verifying the connection, and fixing the most common failure mode (tools not appearing). Commands are verified against OpenCode v1.17.8, installed and run on 2026-06-20.

By DK, Editor  ·  Last verified: 2026-06-20  · OpenCode v1.17.8 (installed and run 2026-06-20)  ·  How we test

Before you start

  • OpenCode installed — curl -fsSL https://opencode.ai/install | bash, or npm i -g opencode-ai, or brew install anomalyco/tap/opencode
  • At least one AI provider configured via opencode auth login (OpenCode needs a model to use tool output)
  • The MCP server you want to add — either an npm package, a local binary, or a remote HTTP server; check the server's own docs for its exact transport command or URL
  • Node.js if the MCP server is distributed as an npm package (e.g. npx @upstash/context7-mcp)

Steps

  1. 01

    Install OpenCode

    If you have not installed OpenCode yet, pick one of the three official methods. The curl installer is the quickest single-step option:

    # Option 1 — curl installer (recommended for a quick start)
    curl -fsSL https://opencode.ai/install | bash
    
    # Option 2 — npm global install
    npm i -g opencode-ai
    
    # Option 3 — Homebrew (macOS/Linux)
    brew install anomalyco/tap/opencode
    
    # Verify the install
    opencode --version
  2. 02

    Configure at least one AI provider

    OpenCode stores your API keys locally and supports 75+ providers. Before MCP tools are useful, the agent needs a model to act on their output. Run the login subcommand and follow the prompts to add your first provider:

    opencode auth login
    # alias:
    opencode providers login
  3. 03

    Add an MCP server with opencode mcp add

    Run the add command with a name you choose for the server. For a remote HTTP MCP server, pass the URL with --url and any required HTTP headers with --header. For a local server that needs environment variables, pass them with --env. If you omit these flags, OpenCode will prompt you interactively. The name you give here is what you will use later in auth, logout, and debug commands. Examples (per-server exact URLs and required headers must be confirmed in each server's own docs):

    # Remote HTTP MCP server with an auth header
    opencode mcp add github --url https://mcp.example.com/github --header Authorization="Bearer <token>"
    
    # Remote server with no extra headers
    opencode mcp add context7 --url https://mcp.context7.com
    
    # Local stdio server with an environment variable
    opencode mcp add myserver --env API_KEY=your_key_here
    
    # Interactive (OpenCode prompts for details)
    opencode mcp add myserver
  4. 04

    Verify the server is listed and its status

    After adding a server, confirm it registered correctly and check its reported status. The list command (alias: ls) shows every configured MCP server:

    opencode mcp list
    # or the shorter alias:
    opencode mcp ls
  5. 05

    Authenticate an OAuth-enabled MCP server

    Some MCP servers (such as official GitHub or Atlassian servers) use OAuth rather than a static API key. After adding the server with mcp add, run mcp auth with the same name you used. OpenCode opens a browser flow and stores the credential locally:

    opencode mcp auth github
  6. 06

    Remove OAuth credentials with mcp logout

    To revoke stored OAuth credentials for a server — for example, to switch accounts or rotate access — run mcp logout with the server name. This removes the saved OAuth token but does not delete the server's configuration entry; the server remains registered and will still appear in opencode mcp list:

    opencode mcp logout github
  7. 07

    Debug an OAuth connection with mcp debug

    If a server authenticated but tools are still not appearing, the debug command prints diagnostic information about the OAuth connection for that server. This is the first place to look when auth appears to succeed but the agent cannot see tools:

    opencode mcp debug github
  8. 08

    Start OpenCode and confirm tools are available

    Launch the TUI. Once inside a session, the agent should list available tools from your connected MCP servers when you ask it what it can do. If you prefer headless usage, opencode run executes a single task:

    # Interactive TUI
    opencode
    
    # Headless single-task
    opencode run "list the open issues in this repo using GitHub MCP"

Popular MCP servers

  • Context7

    Injects up-to-date library documentation into context, reducing hallucinated or outdated API usage. Most useful when working with fast-moving frameworks.

    opencode mcp add context7 --url https://mcp.context7.com
  • GitHub

    Access repos, issues, pull requests, CI runs, and code search from inside the agent. Confirm the server's current URL and auth method in its own docs. If it uses OAuth, run opencode mcp auth github after adding.

    opencode mcp add github --url <github-mcp-url>
  • Playwright

    Browser automation and UI testing. Lets the agent navigate pages, click elements, and capture screenshots — useful for front-end and end-to-end test tasks. Confirm the transport command or URL in the Playwright MCP docs.

    opencode mcp add playwright --url <playwright-mcp-url>
  • Exa

    Semantic web search. The most widely used search MCP in coding agents as of 2026. Requires an Exa API key — confirm current pricing and the server URL on exa.ai.

    opencode mcp add exa --url <exa-mcp-url> --header Authorization="Bearer <exa-api-key>"
  • Desktop Commander

    Terminal execution and filesystem access from the agent. Useful for tasks that span multiple projects or need shell commands the agent would otherwise have to prompt you for. Typically runs as a local server — confirm the exact invocation in its own docs.

    opencode mcp add desktop-commander --env SOME_KEY=value

Troubleshooting

Tools from a connected server do not appear in the session
Run opencode mcp list to check the server status. If it shows an error, re-run opencode mcp add with the correct flags: --url for a remote server, --header for HTTP headers, --env for environment variables needed by a local server. If the server uses OAuth, run opencode mcp auth <name> to complete authentication, then opencode mcp debug <name> to confirm the token is valid. Also check that the server process itself starts correctly outside of OpenCode by running its command directly in a terminal.
opencode mcp auth opens a browser but the callback fails
Ensure your browser can reach localhost on the redirect port the server expects. Some OAuth servers require the redirect URI to be registered in their developer console — confirm on the server's own docs. After a failed flow, run opencode mcp logout <name> to clear any partial OAuth credential (note: this clears the token only, not the server config), then retry opencode mcp auth <name>.
Agent performance degrades after adding several MCP servers
Connecting more than 5–7 MCP servers sends a very long tool list to the model, which can degrade agent performance. Remove servers you are not actively using. The opencode mcp list command shows all configured servers; there is currently no disable-without-delete command, so remove unused entries and re-add them when needed.
opencode: command not found after npm install
The npm global bin directory may not be on your PATH. Run npm prefix -g to find the global prefix directory (e.g. /opt/homebrew or /usr/local); the bin directory is that path plus /bin. Add it to your shell profile: export PATH="$(npm prefix -g)/bin:$PATH" Then reload your shell (source ~/.zshrc or source ~/.bashrc). Alternatively, use the curl installer or Homebrew method, which place the binary in a standard location.
MCP server added but opencode mcp list shows it as disconnected on every launch
Check that the server's transport command (the binary or npx invocation) is available on PATH at the time OpenCode launches. If the server is an npm package, install it globally (npm i -g <package>) rather than relying on npx at runtime, which can fail when network access is restricted or the package version changes.

FAQ

What is the difference between opencode mcp add and opencode mcp auth?
opencode mcp add registers a server's connection details (the transport command or URL and the name you give it). The --url flag specifies a remote HTTP MCP server; --header passes HTTP headers (e.g. an auth token); --env sets environment variables for a local server. opencode mcp auth is a separate step only needed for OAuth-enabled servers — it opens a browser flow to log in and stores the resulting token. Servers that use a static API key (passed via --header or --env at add time) do not need mcp auth.
How many MCP servers can I connect to OpenCode at once?
There is no hard limit in the mcp surface, but a practical limit exists: connecting more than 5–7 servers sends a very long tool list to the model, which tends to degrade agent performance. Connect only the servers you are actively using in a given session.
Does OpenCode support remote (HTTP) MCP servers or only local stdio servers?
Both are supported, verified against v1.17.8 (installed and run 2026-06-20). Remote HTTP MCP servers are added with opencode mcp add <name> --url <url>, with optional --header KEY=VALUE for HTTP headers. Local servers that need environment variables use --env KEY=VALUE. For the exact URL and configuration each server requires, check that server's own documentation.
How do I remove an MCP server I no longer want?
The surface captured on 2026-06-20 shows mcp add, list, auth, logout, and debug. Note that opencode mcp logout <name> only clears stored OAuth credentials — it does not delete the server configuration entry itself. A dedicated mcp remove command was not present in v1.17.8. Check opencode.ai or run opencode mcp --help for the current command set, as this may have been added in a later release. You can also edit the OpenCode config file directly — confirm the config file location on opencode.ai.
Can I use MCP servers with opencode run (headless mode) as well as the TUI?
Yes. MCP servers are configured at the application level, not per session. Once added and authenticated, they are available in both opencode (TUI), opencode run "<message>" (headless single task), and opencode serve (headless server mode).