Give OpenCode an email inbox over MCP

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

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
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
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
{
  "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
{
  "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 toTool it calls
Wait for the sign-up email on stagingtrotta_wait_for_message
Say what is new and what needs a replytrotta_get_inbox_updates
Read a thread before answeringtrotta_thread_context
Write a reply you will send yourselftrotta_create_draft
Check text you pasted from an emailtrotta_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

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