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.
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.
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.
{
"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:
{
"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 runopencode service restart.No MCP servers configuredstraight after a restart. Runopencode mcp listagain.- Still on 1.x? The same
mcp.serversblock 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.