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
- Locate the OpenCode config file. OpenCode reads its configuration from
~/.config/opencode/config.jsonon Linux and macOS, and%APPDATA%\opencode\config.jsonon Windows. Create it if it does not exist. - Add an
mcpServersobject to the config. Each key is a name you choose; the value is the connection settings for that server. - For a local stdio server, provide
commandandargs. For a remote HTTP server, provideurland any required headers for authentication. - Save the file and restart OpenCode. The tools from connected servers should appear in the tool list when you start a new session.
- 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.
{
"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.
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 accountFree for one person · No credit card · Works with Claude, ChatGPT, Cursor and more
How to do this with fenbs
- Create a free account and add a project for the current codebase.
- Connect fenbs to OpenCode by adding
https://fenbs.ai/api/mcpas a remote MCP server in your OpenCode config. Sign in with your fenbs account when prompted. - 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.
- 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.
- 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.