# OpenCode email MCP: give OpenCode an inbox

> The opencode.json block for an email MCP server with a bearer key, the Code Mode switch, and the rules that make OpenCode ask before it sends mail.

Source: https://trotta.email/integrations/opencode

Add a server named trotta under mcp.servers in opencode.json: type remote, URL https://api.trotta.email/mcp and an Authorization header that reads {env:TROTTA_MAIL_API_KEY}. opencode mcp list should show it connected. OpenCode allows tool calls without asking by default, so add ask rules for the tools that send.

Updated December 3, 2026

## Add the email server to OpenCode

No key yet? This returns an inbox and its `api_key` with no account. Export the key as `TROTTA_MAIL_API_KEY`.

Sign up:

```bash
curl -X POST https://api.trotta.email/v1/agents/signup \
  -H "Content-Type: application/json" \
  -d '{"display_name": "Riley"}'
```

Then run this in a shell where the variable is set. The single quotes keep `{env:...}` as written, so the key stays out of the file.

Add, restart, list:

```bash
opencode mcp add trotta --global \
  --url https://api.trotta.email/mcp \
  --header 'Authorization=Bearer {env:TROTTA_MAIL_API_KEY}'

opencode service restart
opencode mcp list
# ✓ trotta  connected   (empty at first? run it again)
```

The restart matters. OpenCode's background service reads the variable when it starts, not when you export it.

`~/.config/opencode/opencode.json`:

```json
{
  "mcp": {
    "servers": {
      "trotta": {
        "type": "remote",
        "url": "https://api.trotta.email/mcp",
        "oauth": false,
        "headers": {
          "Authorization": "Bearer {env:TROTTA_MAIL_API_KEY}"
        }
      }
    }
  }
}
```

`oauth: false` says this server uses the key, with no browser sign-in. To sign in instead, leave out `headers` and `oauth`, then run `opencode mcp auth trotta`.

## Make OpenCode ask before it sends

OpenCode allows an action unless a rule says otherwise, MCP tools included. On 2.4.4, `send_message` ran with no prompt. Add these rules to the same file:

Permission rules:

```json
{
  "permissions": [
    { "action": "trotta_send_message", "resource": "*", "effect": "ask" },
    { "action": "trotta_reply_to_message", "resource": "*", "effect": "ask" },
    { "action": "trotta_answer_invitation", "resource": "*", "effect": "ask" }
  ]
}
```

With the rule in place, an `opencode run` with nobody to ask rejected the send. In the app you approve or reject it. The `--auto` flag approves anything not denied, so use `deny` if you run that way.

## Why don't the mail tools show up by name?

OpenCode 2 puts MCP tools behind its `execute` tool, called Code Mode. Add `"codemode": false` to the server entry and the model gets all 15 tools by name, each starting with `trotta_`.

| Ask OpenCode to | Tool it calls |
| --- | --- |
| Wait for the sign-up email on staging | `trotta_wait_for_message` |
| Say what is new and what needs a reply | `trotta_get_inbox_updates` |
| Read a thread before answering | `trotta_thread_context` |
| Write a reply you will send yourself | `trotta_create_draft` |
| Check text you pasted from an email | `trotta_scan_content` |

## What OpenCode reads, and what it cannot

Each message is screened before delivery and read in the safe view, with hidden text removed, instructions aimed at a model marked and risky links defanged. Held mail shows a reason and no content. No filter catches everything.

Until a human claims the agent, it only replies, up to 50 sends a day, and writes to its own organization's inboxes. There is no IMAP or SMTP.

## Troubleshooting

- **`needs authentication`.** The service started without the key. Export it, then run `opencode service restart`.
- **`No MCP servers configured` straight after a restart.** Run `opencode mcp list` again.
- **Still on 1.x?** The same `mcp.servers` block connected on opencode 1.19.6. Version 1 writes permission rules differently, so follow its own docs for those.

## Questions

### Where does OpenCode keep MCP servers?

In `opencode.json` or `opencode.jsonc`, under `mcp.servers`: `~/.config/opencode` for every project, or the project's own file.

### Should the key go in the project config?

No. Keep the `{env:TROTTA_MAIL_API_KEY}` reference. A literal key in a project file goes wherever the repository goes.

### Can OpenCode read a verification code?

Yes, in an inbox of its own. `wait_for_message` with `has_code` set returns the message that carries it.

### Is Trotta Mail part of OpenCode?

No. It is an independent product that OpenCode connects to as a remote MCP server.

## Sources

- [OpenCode docs: MCP servers](https://opencode.ai/docs/mcp-servers/)
- [OpenCode docs: Permissions](https://opencode.ai/docs/permissions/)
- [Trotta Mail guide for agents (llms.txt)](https://api.trotta.email/llms.txt)

## Related

- [Give Claude Code an email inbox over MCP](https://trotta.email/integrations/claude-code) Integrations
- [Give Cline an email inbox with a remote MCP server](https://trotta.email/integrations/cline) Integrations
- [MCP](https://trotta.email/docs/mcp) Docs
- [An email MCP server for any MCP client](https://trotta.email/integrations/mcp) Integrations
- [Email testing with real inboxes](https://trotta.email/learn/email-testing-with-real-inboxes) Guides
- [Verification codes for AI agents](https://trotta.email/learn/verification-codes-for-ai-agents) Guides

Give your agent an inbox of its own. One call, or one minute in the console.

[Get an inbox](https://trotta.email/signup) [Read the docs](https://trotta.email/docs)
