feat: add mcp.json support for Claude/Cursor compatibility
Summary
- Add support for loading MCP servers from standalone
mcp.jsonfiles, enabling compatibility with Claude Code, Cursor, VS Code, and other tools that use the mcp.json format - Users no longer need to manually transform their existing mcp.json configurations to opencode.json format
Supported Locations
Loads mcp.json from these locations (in order of priority, lowest to highest):
Global:
-
~/.cursor/mcp.json -
~/.claude/mcp.json -
~/.config/opencode/mcp.json -
~/.opencode/mcp.json
Project:
5. <project>/.cursor/mcp.json
6. <project>/.claude/mcp.json
7. <project>/.opencode/mcp.json
8. <project>/mcp.json
Features
- Automatic transformation from mcp.json format to OpenCode format
- Support for both local (stdio) and remote (HTTP/SSE) servers
- Environment variable syntax normalization (
${env:VAR}->{env:VAR}) -
opencode.jsonmcp config takes priority over mcp.json for same-named servers
Example
mcp.json (Claude/Cursor format):
{
"mcpServers": {
"my-server": {
"command": "npx",
"args": ["-y", "mcp-server"],
"env": {
"API_KEY": "${env:MY_API_KEY}"
}
},
"remote-server": {
"url": "https://api.example.com/mcp",
"headers": {
"Authorization": "Bearer ${env:MY_TOKEN}"
}
}
}
}
This is automatically transformed to OpenCode's internal format and merged with any existing mcp config in opencode.json.
OC Session: https://opncd.ai/share/3fw3GKgV
mcp import Command
Import MCP servers from a base64-encoded mcp.json string. This enables easy sharing and importing of MCP server configurations that use the Claude/Cursor mcp.json format.
This can easily reduce the friction of importing or installing 3rd party MCP servers.
Usage
opencode mcp import <base64-data>
Input Format
The input should be base64-encoded JSON following the mcp.json format:
{
"mcpServers": {
"local-server": {
"command": "npx",
"args": ["-y", "mcp-server"],
"env": {
"API_KEY": "your-api-key"
}
},
"remote-server": {
"url": "https://example.com/mcp",
"headers": {
"Authorization": "Bearer ${env:MY_TOKEN}"
}
}
}
}
Example
# Create base64 from mcp.json content
echo '{"mcpServers":{"my-server":{"url":"https://mcp.example.com"}}}' | base64
# Import it
opencode mcp import eyJtY3BTZXJ2ZXJzIjp7Im15LXNlcnZlciI6eyJ1cmwiOiJodHRwczovL21jcC5leGFtcGxlLmNvbSJ9fX0K
What It Does
- Decodes and validates the base64-encoded mcp.json data
- Shows a preview of servers to be imported (name, type, URL/command)
- Asks for confirmation before importing
- Lets you choose where to save:
-
Project:
./opencode.json -
Global:
~/.opencode/opencode.json
-
Project:
- Handles conflicts - warns if servers already exist and asks whether to overwrite
- Merges with existing configuration
Notes
- Environment variables using
${env:VAR}syntax are automatically converted to OpenCode's{env:VAR}format - The mcp.json format is automatically transformed to OpenCode's internal format
- Existing servers in opencode.json are preserved unless you choose to overwrite