OpenCode MCP Server Setup: Connect Tools and Shared Context

OpenCode supports MCP servers through a JSON config file, letting you add custom tools alongside its built-in capabilities. Here is how to configure MCP connections in OpenCode, authenticate with remote servers, and keep project rules and progress available across coding tools.

Updated 4 min read

OpenCode is an open-source, terminal-based coding assistant that supports MCP servers through its configuration file. Adding an MCP server gives OpenCode access to custom tools alongside the model's built-in capabilities. Tools like fenbs connect over MCP and share project rules, in-progress tasks, and where-we-left-off notes across coding assistants, so the same context is available whether you work in OpenCode, Claude Code, or another supported tool.

For an overview of the config format used across most clients, see MCP server configuration. The concepts are the same in OpenCode; the file location and key names may differ slightly from other clients.

Configure MCP servers in OpenCode

  1. Locate the OpenCode config file. OpenCode reads its configuration from ~/.config/opencode/config.json on Linux and macOS, and %APPDATA%\opencode\config.json on Windows. Create it if it does not exist.
  2. Add an mcpServers object to the config. Each key is a name you choose; the value is the connection settings for that server.
  3. For a local stdio server, provide command and args. For a remote HTTP server, provide url and any required headers for authentication.
  4. Save the file and restart OpenCode. The tools from connected servers should appear in the tool list when you start a new session.
  5. Test by asking OpenCode to list available tools or call a simple read-only tool from your new server. Fix any path or credential errors before using the connection for real work.
OpenCode MCP config example
{
  "mcpServers": {
    "fenbs": {
      "type": "remote",
      "url": "https://fenbs.ai/api/mcp"
    },
    "my-local-tool": {
      "type": "local",
      "command": "node",
      "args": ["/path/to/my-mcp-server/index.js"]
    }
  }
}

Authenticate with remote MCP servers

Remote MCP servers that follow the MCP authorization spec use OAuth: the first time you connect, the client opens a browser for you to sign in and approve access. After that, the client stores the token and uses it for future sessions. No key needs to be pasted into a config file.

If a server requires a bearer token or API key instead of OAuth, pass it as an HTTP header in the config. Store the token value in an environment variable rather than writing it directly in the config file, especially if the config is in a shared or version-controlled location.

Verify tools after setup

After adding a server, confirm that the tools it provides are visible and callable. Ask OpenCode to list available tools from the new connection, then run a low-stakes call — a read query or a status check — to verify the response is correct.

If a tool returns an error, check the server logs first. Common causes are a wrong path, a missing environment variable, or an expired credential. The MCP server spec describes the error response format so you can read what the server is telling the client.

Share project context across coding assistants

OpenCode, Claude Code, Cursor, and other MCP-compatible coding tools can all connect to the same fenbs project. When you work in OpenCode and add tasks or save progress, those updates are available to any other connected tool in the next session. You do not need to re-explain the project when you switch tools.

This is useful when different tools are better for different parts of the work: OpenCode for terminal-based tasks, Claude Code for larger edits, Cursor for refactoring. Each reads the same Decisions and rules, the same in-progress tasks, and the same Where we left off note.

OpenCode can run in non-interactive contexts such as shell scripts, editor integrations, and scheduled pipelines. When you add an MCP server in one of these environments, confirm that the authentication method does not require browser interaction. Remote servers using OAuth open a browser for the initial sign-in; that works in an interactive terminal session but not in a headless script. Complete the initial authorization interactively and verify that the tokens persist across sessions before running OpenCode in any automated context. For servers like fenbs, the initial sign-in happens once and the stored tokens refresh automatically. If you use a self-hosted MCP server with a different token lifecycle, test the full session flow before relying on it in a pipeline. Confirm that the token storage directory is accessible to the user account running OpenCode in that environment, and that the account has permission to write updated tokens after a refresh, especially on shared systems where home directories differ between users.

How fenbs helps

Keep project context available in every coding tool

Connect fenbs to OpenCode at the start of a session and ask it to read the project context. It gets the current rules, in-progress tasks, and where the previous session left off. Before you stop, ask it to save progress. The same record is available when you switch to Claude Code, Cursor, or another supported tool.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

How to do this with fenbs

  1. Create a free account and add a project for the current codebase.
  2. Connect fenbs to OpenCode by adding https://fenbs.ai/api/mcp as a remote MCP server in your OpenCode config. Sign in with your fenbs account when prompted.
  3. At the start of each coding session, ask OpenCode to read the project context from fenbs: rules, in-progress tasks, and where the last session left off.
  4. Add tasks, decisions, and notes during the session. Record design choices as Decisions and rules so they are available to any tool that connects next.
  5. Before you stop, ask OpenCode to save progress: what was completed, what is still in progress, and what the next session should start with.

fenbs does not read your local files or compile your code. It holds the project decisions and task status your coding assistant needs between sessions. For integrations with other supported tools, see Integrations.

Questions people ask.

Where is the OpenCode MCP config file?

OpenCode reads MCP server configuration from its main config file, located at ~/.config/opencode/config.json on Linux and macOS, and %APPDATA%\opencode\config.json on Windows. Add an mcpServers object to this file with the connection settings for each server.

Can OpenCode connect to remote MCP servers?

Yes. Provide the server URL in the config and include any required authentication headers. Remote servers that follow the MCP authorization spec use OAuth, which opens a browser for sign-in on the first connection.

How do I share project context between OpenCode and Claude Code?

Connect both tools to the same fenbs project over MCP. Each tool reads the same rules, tasks, and progress notes at the start of a session and can add to the same record. Work saved in one tool is immediately available in the other.

What should I ask OpenCode to do at the start of a session?

Ask it to read the project context from fenbs: the current rules, in-progress tasks, and where the last session left off. This gives it the shared decisions and current status before it starts any work.

Does fenbs work without connecting it as an MCP server?

fenbs has a web app and a phone app you can use directly without an MCP connection. The MCP connection is what lets a coding assistant like OpenCode read and update the project context during a session.

More in Connect your AI tools

All Connect your AI tools articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.