> ## Documentation Index
> Fetch the complete documentation index at: https://docs.operata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect OpenCode to the Operata MCP server

> Add the Operata MCP Server to OpenCode so you can query Operata data over the Model Context Protocol from your editor.

Connect OpenCode to the Operata MCP Server so you can ask Operata-data questions from OpenCode's chat.

OAuth is the recommended way to connect. Use an API key only for automated, non-interactive integrations. For the difference, roles, and prerequisites, see the [MCP overview](/docs/guides-mcp-intro).

## Before you start

* An Operata account. For **OAuth**, a user with the **Admin** or **User** role; for an **API key**, an [Operata API key](/docs/api-authentication). See [Before you start](/docs/guides-mcp-intro#before-you-start).
* OpenCode, installed and signed in.

## Open OpenCode's MCP configuration

OpenCode reads MCP servers from its configuration file (`opencode.json` or your client's MCP configuration). Add the server to the `mcpServers` object.

## Add the Operata MCP server

### Connect over OAuth

```json opencode.json theme={null}
{
  "mcpServers": {
    "operata": {
      "command": "npx",
      "args": ["mcp-remote@latest", "https://mcp.operata.io/mcp"]
    }
  }
}
```

### Connect with an API key

Use the API key endpoint for automated integrations. The key can only reach the single group it was created in.

```json opencode.json theme={null}
{
  "mcpServers": {
    "operata": {
      "command": "npx",
      "args": [
        "mcp-remote@latest",
        "https://api.operata.io/v1/mcp",
        "--header",
        "Authorization:${AUTH_HEADER}"
      ],
      "env": {
        "AUTH_HEADER": "Bearer <your-operata-api-key>"
      }
    }
  }
}
```

Replace `<your-operata-api-key>` with your key.

## Reload OpenCode

Restart OpenCode. On an OAuth connection, a browser window opens on first use to sign in to Operata and authorize the session.

## Select a group

On an OAuth session, pick the group you want to query: run `list_groups`, then `switch_group`. An API-key session is already fixed to its own group. See [Groups and regions](/docs/guides-mcp-intro#groups-and-regions).

## Ask OpenCode a question that uses Operata data

In OpenCode's chat, ask a question that needs Operata data:

> Run a query against Operata for the average MOS across all contacts yesterday.

OpenCode calls the right Operata tool — `traces_query` for an aggregate like this — and renders the result.

## Result

OpenCode lists `operata` as a connected MCP server with the full Operata tool surface. A chat question that needs Operata data invokes a tool and returns a real value from your account. A `401` in the tool-call trace means the credential is wrong or expired; a `403` means a group problem. See [Troubleshooting](/docs/guides-mcp-troubleshooting).

## Related

* [MCP overview](/docs/guides-mcp-intro) — authentication, groups, and testing for every client.
* [MCP tools reference](/docs/guides-mcp-tools) — every tool, its parameters, and examples.
* [Connect Claude](/docs/guides-mcp-claude) — Claude Desktop, Claude Code, and the Claude API.
* [Connect Cursor](/docs/guides-mcp-cursor) — Cursor's MCP configuration.
* [Connect ChatGPT](/docs/guides-mcp-chatgpt) — a ChatGPT custom connector over OAuth.
* [Troubleshoot the MCP server](/docs/guides-mcp-troubleshooting) — common failure modes and fixes.
* [Authentication](/docs/api-authentication) — mint the API keys the server uses.
