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

# OpenCode

> Connect the 2extract MCP server to OpenCode so its agent can provision proxies while it writes your code.

OpenCode reads MCP servers from the `mcp` section of its config file, `opencode.json`.

***

## Global or per project?

| File | Scope | Use when |
| :- | :- | :- |
| `~/.config/opencode/opencode.json` | Every project | It is your personal key and you want it everywhere |
| `opencode.json` in the repository root | One repository | The whole team should get the same tools |

***

## Add the server

OpenCode can read the key from an environment variable, so the key never lands in the config file. Export it in your shell profile:

```bash icon="terminal" theme={null}
export EXTRACT_API_KEY=2xt_YOUR_API_KEY
```

Then add the server:

```json opencode.json icon="brackets-curly" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "2extract": {
      "type": "remote",
      "url": "https://mcp.2extract.com/mcp",
      "enabled": true,
      "headers": {
        "Authorization": "Bearer {env:EXTRACT_API_KEY}"
      }
    }
  }
}
```

`{env:EXTRACT_API_KEY}` is replaced with the value of the variable when OpenCode starts. Already have servers configured? Add `2extract` as another key inside the existing `mcp` object.

<Note>
  Because the key comes from the environment, a project-level `opencode.json` with this config is safe to commit. Each teammate exports their own key.
</Note>

***

## Verify

Start OpenCode and ask:

> What is my 2extract balance?

<Check>
  A number comes back, and no proxy was created.
</Check>

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="OpenCode does not see the server">
    Check that `type` is `remote`, `enabled` is `true`, and the URL keeps the `/mcp` path. Then restart OpenCode - the config is read at startup.
  </Accordion>

  <Accordion title="Unauthorized on every call">
    The variable must be set in the shell that starts OpenCode. Run `echo $EXTRACT_API_KEY` there; an empty line means OpenCode sends `Bearer` with no key. The variable holds the bare key (`2xt_...`) - the config adds `Bearer`.
  </Accordion>

  <Accordion title="Some tools fail, others work">
    A scope problem rather than a connection problem. The key is missing the scope those tools need - see [Overview](/ai/mcp-server/overview#scopes-an-agent-needs).
  </Accordion>
</AccordionGroup>

***

## Next steps

<CardGroup cols={2}>
  <Card title="Tools" icon="wrench" href="/ai/mcp-server/tools">
    Everything the agent can call.
  </Card>

  <Card title="Other clients" icon="plug" href="/ai/clients/other">
    Any other MCP client.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.