Give a Claude Agent SDK agent its own email inbox
Pass Trotta Mail in mcp_servers with type http, the URL https://api.trotta.email/mcp and a bearer header. List what the agent may call in allowed_tools by its mcp__trotta__ names, and set permission_mode to dontAsk. The agent can then read screened mail and leave drafts, and every send is denied.
Updated
Install the SDK and get a key
pip install claude-agent-sdk
npm install @anthropic-ai/ claude-agent-sdk # for TypeScript
curl -X POST https://api.trotta.email/ v1/ agents/ signup \
-H "Content-Type: application/ json" \
-d '{"display_name": "Riley"}'Export the returned api_key as TROTTA_MAIL_API_KEY. The SDK also needs your model credentials, such as ANTHROPIC_API_KEY.
A Python agent that reads and drafts
import asyncio
import os
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, SystemMessage, query
options = ClaudeAgentOptions(
mcp_servers={
"trotta": {
"type": "http",
"url": "https://api.trotta.email/ mcp",
"headers": {"Authorization": f"Bearer {os.environ['TROTTA_MAIL_API_KEY']}"},
}
},
strict_mcp_config=True,
tools=[], # no shell, no file tools
allowed_tools=[
"mcp__trotta__list_inboxes",
"mcp__trotta__get_inbox_updates",
"mcp__trotta__read_message",
"mcp__trotta__thread_context",
"mcp__trotta__create_draft",
],
permission_mode="dontAsk", # anything not listed is denied
)
async def main() -> None:
async for message in query(
prompt="What is new in my inboxes? Draft a reply to anything that needs one.",
options=options,
):
if isinstance(message, SystemMessage) and message.subtype == "init":
print(message.data.get("mcp_servers"))
if isinstance(message, ResultMessage):
print(message.result)
if __name__ == "__main__":
asyncio.run(main())Run on claude-agent-sdk 0.2.189, the server reports connected, 15 mcp__trotta__ tools are offered, and a call to send_message is denied.
| Option | What it does here |
|---|---|
strict_mcp_config | Ignores MCP servers configured elsewhere on the machine |
tools=[] | Removes the built-in shell and file tools |
allowed_tools | Runs the listed calls without asking |
permission_mode="dontAsk" | Denies a call that would need approval |
The same agent in TypeScript
import { query } from "@anthropic-ai/ claude-agent-sdk";
for await (const message of query({
prompt: "What is new in my inboxes? Draft a reply to anything that needs one.",
options: {
mcpServers: {
trotta: {
type: "http",
url: "https://api.trotta.email/ mcp",
headers: { Authorization: `Bearer ${process.env.TROTTA_MAIL_API_KEY}` },
},
},
strictMcpConfig: true,
tools: [], // no shell, no file tools
allowedTools: [
"mcp__trotta__list_inboxes",
"mcp__trotta__get_inbox_updates",
"mcp__trotta__read_message",
"mcp__trotta__thread_context",
"mcp__trotta__create_draft",
],
permissionMode: "dontAsk", // anything not listed is denied
},
})) {
if (message.type === "system" && message.subtype === "init") console.log(message.mcp_servers);
if (message.type === "result" && message.subtype === "success") console.log(message.result);
}How do you approve each send?
Switch to default mode and add can_use_tool. Listed tools still run on their own. A send now stops and asks you.
import asyncio
import dataclasses
from claude_agent_sdk import ResultMessage, query
from claude_agent_sdk.types import HookMatcher, PermissionResultAllow, PermissionResultDeny
from inbox_agent import options
async def ask_me(tool_name, tool_input, context):
print(f"\n{tool_name}\n{tool_input}")
if input("Allow this? (y/ n): ").strip().lower() == "y":
return PermissionResultAllow(updated_input=tool_input)
return PermissionResultDeny(message="Your human said no. Leave a draft instead.")
async def keep_open(input_data, tool_use_id, context):
return {"continue_": True} # can_use_tool needs this in Python
async def prompt():
text = "Reply to the newest message in my inbox."
yield {"type": "user", "message": {"role": "user", "content": text}}
async def main() -> None:
asking = dataclasses.replace(
options,
permission_mode="default",
can_use_tool=ask_me,
hooks={"PreToolUse": [HookMatcher(matcher=None, hooks=[keep_open])]},
)
async for message in query(prompt=prompt(), options=asking):
if isinstance(message, ResultMessage):
print(message.result)
asyncio.run(main())The SDK warns that the listed tools skip your callback. Here that is the plan.
Or keep the server in .mcp.json
{
"mcpServers": {
"trotta": {
"type": "http",
"url": "https://api.trotta.email/ mcp",
"headers": { "Authorization": "Bearer ${TROTTA_MAIL_API_KEY}" }
}
}
}With the default setting sources, the SDK reads this from the working directory. Remove mcp_servers and strict_mcp_config from the code, or the file is ignored.
Which tools should the agent get?
Start from the job and list only what it needs. The names below go in allowed_tools, each with the mcp__trotta__ prefix.
| Job | Tools to list |
|---|---|
| Morning summary | get_inbox_updates, read_message |
| Sign up to a service and read the code | list_inboxes, wait_for_message |
| Draft replies for a human to send | read_message, thread_context, create_draft |
| Read an invoice PDF | read_message, read_attachment_text |
| Check text from outside the inbox | scan_content |
| Answer mail on its own | read_message, reply_to_message |
An agent no human has claimed yet can only reply, up to 50 sends a day, and write to its own organization's inboxes. To create more inboxes it uses create_inbox with an API key; before the claim it can hold 2.
What the agent reads
Tools return the safe view: hidden text is removed, instructions aimed at a model are marked and risky links are defanged. Sender text arrives between markers that label it as data, not instructions. Held mail has a reason and no content.
No filter catches everything, which is why the sample leaves sending out. A plausible request can still arrive as ordinary mail. See prompt injection by email.
Questions
Does allowed_tools block the tools you leave out?
Not by itself. It auto-approves what you list. dontAsk denies the rest, and disallowed_tools blocks a tool in every mode.
Is bypassPermissions safe with an inbox?
No. It approves MCP calls, sends included. Keep dontAsk or default, or put the send tools in disallowed_tools.
Do you need a Trotta Mail SDK as well?
No. MCP is enough. The trottamail and trotta-mail packages are for calling the REST API from your own code.
Is Trotta Mail made by Anthropic?
No. It is an independent product that the Agent SDK connects to as a remote MCP server.