文档
Documentação em Português
Servidores MCP

Servidores MCP

OpenCode suporta o Model Context Protocol (MCP) para adicionar ferramentas externas via servidores locais e remotos.

Importante: Servidores MCP adicionam ao seu contexto, então tenha cuidado com quais você habilita.

Habilitando Servidores MCP

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

Servidores MCP Locais

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

Opções de Servidor Local

OpçãoTipoObrigatório
typeStringSim ("local")
commandArraySim
environmentObjectNão
timeoutNumberNão (padrão: 5000)

Servidores MCP Remotos

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

Autenticação OAuth

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

Gerenciando Ferramentas MCP

Global

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

Por Agente

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

Exemplos

Sentry

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

Busca de Código GitHub

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