# Connect OpenCode to XgenPlus Mail

To connect OpenCode, make your token, then add the XgenPlus server to `opencode.json`, either `~/.config/opencode/opencode.json` for all projects or `opencode.json` in one project. Set the XGENPLUS_TOKEN environment variable to your token and start OpenCode from the same terminal. `opencode mcp list` should show xgenplus as connected.

## How to connect OpenCode to XgenPlus Mail

1. Create an agent password in webmail under **Settings › Security › AI Agents (MCP)** and copy its token, or [make your token](/developers/mcp-make-a-token/).
2. Open `~/.config/opencode/opencode.json` for all projects, or create `opencode.json` in one project folder.
3. Paste the block below. If the file already has an `mcp` section, add `xgenplus` inside it.
4. Set the token and start OpenCode in the same terminal. Windows PowerShell: `$env:XGENPLUS_TOKEN = "<TOKEN>"; opencode`. Mac or Linux: `export XGENPLUS_TOKEN="<TOKEN>"`, then `opencode`.
5. Run `opencode mcp list` and check that **xgenplus** shows as connected.
6. Test the connection: ask the assistant to "Call xgenplus_get_mailbox_profile". If it lists your permissions, the token works. If it fails with a sign-in problem, the token is wrong or the mailbox is blocked. If it says the agent can't sign in right now, check the agent in webmail: it may be paused, expired or have **Login** unticked.

## When to use it

> Arjun writes code in OpenCode at acme.in. He asks it to find this week's bug reports from customers and turn them into a task list in his project.

## Configuration

<div class="callout admin"><div><b>Making your token</b><ol><li>In XgenPlus webmail, go to <b>Settings › Security › AI Agents (MCP)</b> and click <b>Create agent password</b>.</li><li>On <b>Your agent is ready</b>, copy the <b>Token for AI apps</b>. It is already encoded, so paste it where this guide says <code>&lt;TOKEN&gt;</code>, after <code>Bearer </code> with one space.</li></ol><p>Chose your own password, or need to make the token again? It is your email address and agent password joined by a colon, with no spaces, in base64. Replace the sample values with yours, run the command on your own computer, and copy the line it prints.</p><b>Windows (PowerShell):</b><pre><code>[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('you@xgenplus.com:AGENT_PASSWORD'))</code></pre><b>Mac or Linux (Terminal):</b><pre><code>printf '%s' 'you@xgenplus.com:AGENT_PASSWORD' | base64 | tr -d '\n'</code></pre><p>For example, <code>you@xgenplus.com:AGENT_PASSWORD</code> becomes <code>eW91QHhnZW5wbHVzLmNvbTpBR0VOVF9QQVNTV09SRA==</code>. <b>Base64 is not encryption:</b> keep the token as secret as a password. Never paste it into a chat with the AI, a shared file or a code repository, and never use online base64 encoder websites, because they would receive your agent password. If your agent password contains a single quote (<code>'</code>), these commands break, so create a new agent password without one. More help: <a href="/developers/mcp-make-a-token/">Make your MCP token</a>.</p></div></div>

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "xgenplus": {
      "type": "remote",
      "url": "https://mcp.xgenplus.com/mcp",
      "enabled": true,
      "headers": { "Authorization": "Bearer {env:XGENPLUS_TOKEN}" }
    }
  }
}
```

Keep `{env:XGENPLUS_TOKEN}` exactly as shown. OpenCode fills in the token from the environment variable when it starts.

## Good to know

- OpenCode writes environment variables as `{env:NAME}`, not `${env:NAME}` as Cursor does. With the wrong form, or with the variable not set, OpenCode sends an empty token and the server refuses the connection.
- When the server refuses a token, OpenCode may offer an OAuth sign-in. XgenPlus does not offer OAuth sign-in yet, so check the token and the variable instead.
- **"max_tokens cannot exceed ..." errors** come from your AI model's provider, not from XgenPlus. OpenCode asked for a longer answer than the model allows. Set a lower output limit for that model in `opencode.json`, below the provider's limit for that model:

```json
"provider": {
  "<provider>": { "models": { "<model>": { "limit": { "context": 128000, "output": 8000 } } } }
}
```

## Common questions

**How do I keep the token for every new terminal?**

On Windows, run `setx XGENPLUS_TOKEN "<TOKEN>"` once and open a new terminal. On Mac or Linux, add the `export XGENPLUS_TOKEN="<TOKEN>"` line to your shell profile.

**Why are the tools called xgenplus_list_folders and so on?**

OpenCode puts the server name in front of each tool name. xgenplus_list_folders is the list_folders tool from the XgenPlus server.


Source: https://docs.xgenplus.com/developers/mcp-opencode/
