opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add mcp.json support for Claude/Cursor compatibility

Open R44VC0RP opened this issue 1 month ago • 2 comments

Summary

  • Add support for loading MCP servers from standalone mcp.json files, 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:

  1. ~/.cursor/mcp.json
  2. ~/.claude/mcp.json
  3. ~/.config/opencode/mcp.json
  4. ~/.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.json mcp 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

R44VC0RP avatar Dec 18 '25 13:12 R44VC0RP

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

  1. Decodes and validates the base64-encoded mcp.json data
  2. Shows a preview of servers to be imported (name, type, URL/command)
  3. Asks for confirmation before importing
  4. Lets you choose where to save:
    • Project: ./opencode.json
    • Global: ~/.opencode/opencode.json
  5. Handles conflicts - warns if servers already exist and asks whether to overwrite
  6. 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

R44VC0RP avatar Dec 18 '25 13:12 R44VC0RP