文档
English Docs
MCP Servers

MCP Servers

OpenCode supports the Model Context Protocol (MCP) to add external tools via local and remote servers.

Important: MCP servers add to your context, so be careful with which ones you enable.

Enabling MCP Servers

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "server-name": {
      "enabled": true
    }
  }
}

Local MCP Servers

{
  "mcp": {
    "my-local-server": {
      "type": "local",
      "command": ["npx", "-y", "my-mcp-command"],
      "enabled": true,
      "environment": {
        "MY_ENV_VAR": "value"
      }
    }
  }
}

Local Server Options

OptionTypeRequired
typeStringYes ("local")
commandArrayYes
environmentObjectNo
timeoutNumberNo (default: 5000)

Remote MCP Servers

{
  "mcp": {
    "my-remote-server": {
      "type": "remote",
      "url": "https://my-mcp-server.com",
      "headers": {
        "Authorization": "Bearer API_KEY"
      }
    }
  }
}

OAuth Authentication

opencode mcp auth server-name
opencode mcp list
opencode mcp logout server-name

Managing MCP Tools

Global

{
  "tools": {
    "my-mcp*": false
  }
}

Per-Agent

{
  "agent": {
    "my-agent": {
      "tools": {
        "my-mcp*": true
      }
    }
  }
}

Examples

Sentry

{
  "mcp": {
    "sentry": {
      "type": "remote",
      "url": "https://mcp.sentry.dev/mcp"
    }
  }
}

GitHub Code Search

{
  "mcp": {
    "gh_grep": {
      "type": "remote",
      "url": "https://mcp.grep.app"
    }
  }
}