{"slug": "claude-agent-sdk-email-connect-an-mcp-inbox", "title": "Claude Agent SDK email: connect an MCP inbox", "summary": "A tutorial shows how to give a Claude Agent SDK agent its own email inbox by connecting the Trotta Mail MCP server (https://api.trotta.email/mcp) as an HTTP server in mcp_servers with a bearer header, listing five mcp__trotta__ tools in allowed_tools and setting permission_mode to \"dontAsk\" so every send is denied. Run on claude-agent-sdk 0.2.189, the server reports \"connected\", offers 15 mcp__trotta__ tools, and a call to send_message is denied; switching to \"default\" mode with a can_use_tool callback makes each send stop for human approval.", "body_md": "# Give a Claude Agent SDK agent its own email inbox\n\nPass 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.\n\nUpdated\n\n## Install the SDK and get a key\n\n```\npip install claude-agent-sdk\nnpm install @anthropic-ai/claude-agent-sdk   # for TypeScript\n\ncurl -X POST https://api.trotta.email/v1/agents/signup \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"display_name\": \"Riley\"}'\n```\n\nExport the returned `api_key` as `TROTTA_MAIL_API_KEY`. The SDK also needs your model credentials, such as `ANTHROPIC_API_KEY`.\n\n## A Python agent that reads and drafts\n\n``` python\nimport asyncio\nimport os\n\nfrom claude_agent_sdk import ClaudeAgentOptions, ResultMessage, SystemMessage, query\n\noptions = ClaudeAgentOptions(\n    mcp_servers={\n        \"trotta\": {\n            \"type\": \"http\",\n            \"url\": \"https://api.trotta.email/mcp\",\n            \"headers\": {\"Authorization\": f\"Bearer {os.environ['TROTTA_MAIL_API_KEY']}\"},\n        }\n    },\n    strict_mcp_config=True,\n    tools=[],  # no shell, no file tools\n    allowed_tools=[\n        \"mcp__trotta__list_inboxes\",\n        \"mcp__trotta__get_inbox_updates\",\n        \"mcp__trotta__read_message\",\n        \"mcp__trotta__thread_context\",\n        \"mcp__trotta__create_draft\",\n    ],\n    permission_mode=\"dontAsk\",  # anything not listed is denied\n)\n\nasync def main() -> None:\n    async for message in query(\n        prompt=\"What is new in my inboxes? Draft a reply to anything that needs one.\",\n        options=options,\n    ):\n        if isinstance(message, SystemMessage) and message.subtype == \"init\":\n            print(message.data.get(\"mcp_servers\"))\n        if isinstance(message, ResultMessage):\n            print(message.result)\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\nRun 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.\n\n| Option | What it does here | \n|---|---|\n| `strict_mcp_config` | Ignores MCP servers configured elsewhere on the machine | \n| `tools=[]` | Removes the built-in shell and file tools | \n| `allowed_tools` | Runs the listed calls without asking | \n| `permission_mode=\"dontAsk\"` | Denies a call that would need approval | \n\n## The same agent in TypeScript\n\n``` js\nimport { query } from \"@anthropic-ai/claude-agent-sdk\";\n\nfor await (const message of query({\n  prompt: \"What is new in my inboxes? Draft a reply to anything that needs one.\",\n  options: {\n    mcpServers: {\n      trotta: {\n        type: \"http\",\n        url: \"https://api.trotta.email/mcp\",\n        headers: { Authorization: `Bearer ${process.env.TROTTA_MAIL_API_KEY}` },\n      },\n    },\n    strictMcpConfig: true,\n    tools: [], // no shell, no file tools\n    allowedTools: [\n      \"mcp__trotta__list_inboxes\",\n      \"mcp__trotta__get_inbox_updates\",\n      \"mcp__trotta__read_message\",\n      \"mcp__trotta__thread_context\",\n      \"mcp__trotta__create_draft\",\n    ],\n    permissionMode: \"dontAsk\", // anything not listed is denied\n  },\n})) {\n  if (message.type === \"system\" && message.subtype === \"init\") console.log(message.mcp_servers);\n  if (message.type === \"result\" && message.subtype === \"success\") console.log(message.result);\n}\n```\n\n## How do you approve each send?\n\nSwitch to `default` mode and add `can_use_tool`. Listed tools still run on their own. A send now stops and asks you.\n\n``` python\nimport asyncio\nimport dataclasses\n\nfrom claude_agent_sdk import ResultMessage, query\nfrom claude_agent_sdk.types import HookMatcher, PermissionResultAllow, PermissionResultDeny\n\nfrom inbox_agent import options\n\nasync def ask_me(tool_name, tool_input, context):\n    print(f\"\\n{tool_name}\\n{tool_input}\")\n    if input(\"Allow this? (y/n): \").strip().lower() == \"y\":\n        return PermissionResultAllow(updated_input=tool_input)\n    return PermissionResultDeny(message=\"Your human said no. Leave a draft instead.\")\n\nasync def keep_open(input_data, tool_use_id, context):\n    return {\"continue_\": True}  # can_use_tool needs this in Python\n\nasync def prompt():\n    text = \"Reply to the newest message in my inbox.\"\n    yield {\"type\": \"user\", \"message\": {\"role\": \"user\", \"content\": text}}\n\nasync def main() -> None:\n    asking = dataclasses.replace(\n        options,\n        permission_mode=\"default\",\n        can_use_tool=ask_me,\n        hooks={\"PreToolUse\": [HookMatcher(matcher=None, hooks=[keep_open])]},\n    )\n    async for message in query(prompt=prompt(), options=asking):\n        if isinstance(message, ResultMessage):\n            print(message.result)\n\nasyncio.run(main())\n```\n\nThe SDK warns that the listed tools skip your callback. Here that is the plan.\n\n## Or keep the server in .mcp.json\n\n```\n{\n  \"mcpServers\": {\n    \"trotta\": {\n      \"type\": \"http\",\n      \"url\": \"https://api.trotta.email/mcp\",\n      \"headers\": { \"Authorization\": \"Bearer ${TROTTA_MAIL_API_KEY}\" }\n    }\n  }\n}\n```\n\nWith 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.\n\n## Which tools should the agent get?\n\nStart from the job and list only what it needs. The names below go in `allowed_tools`, each with the `mcp__trotta__` prefix.\n\n| Job | Tools to list | \n|---|---|\n| Morning summary | `get_inbox_updates` ,`read_message` | \n| Sign up to a service and read the code | `list_inboxes` ,`wait_for_message` | \n| Draft replies for a human to send | `read_message` ,`thread_context` ,`create_draft` | \n| Read an invoice PDF | `read_message` ,`read_attachment_text` | \n| Check text from outside the inbox | `scan_content` | \n| Answer mail on its own | `read_message` ,`reply_to_message` | \n\nAn 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.\n\n## What the agent reads\n\nTools 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.\n\nNo 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](https://trotta.email/threats/prompt-injection-by-email).\n\n## Questions\n\n### Does `allowed_tools` block the tools you leave out?\n\nNot by itself. It auto-approves what you list. `dontAsk` denies the rest, and `disallowed_tools` blocks a tool in every mode.\n\n### Is `bypassPermissions` safe with an inbox?\n\nNo. It approves MCP calls, sends included. Keep `dontAsk` or `default`, or put the send tools in `disallowed_tools`.\n\n### Do you need a Trotta Mail SDK as well?\n\nNo. MCP is enough. The `trottamail` and `trotta-mail` packages are for calling the REST API from your own code.\n\n### Is Trotta Mail made by Anthropic?\n\nNo. It is an independent product that the Agent SDK connects to as a remote MCP server.", "url": "https://wpnews.pro/news/claude-agent-sdk-email-connect-an-mcp-inbox", "canonical_source": "https://trotta.email/integrations/claude-agent-sdk", "published_at": "2026-12-03 00:00:00+00:00", "updated_at": "2026-12-03 18:45:04.545764+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["Claude Agent SDK", "Trotta Mail", "Anthropic", "ClaudeAgentOptions", "mcp_servers", "allowed_tools"], "also_reported_by": [], "takeaway": "Setting permission_mode to \"dontAsk\" with an explicit allowed_tools list of five mcp__trotta__ calls denies send_message outright, and switching to \"default\" mode with a can_use_tool callback makes each send pause for approval.", "recommendation": {"advice": "Run email agents with tools=[] and permission_mode=\"dontAsk\" plus an explicit allowed_tools list, then require a can_use_tool approval before any send executes.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/claude-agent-sdk-email-connect-an-mcp-inbox", "markdown": "https://wpnews.pro/news/claude-agent-sdk-email-connect-an-mcp-inbox.md", "text": "https://wpnews.pro/news/claude-agent-sdk-email-connect-an-mcp-inbox.txt", "jsonld": "https://wpnews.pro/news/claude-agent-sdk-email-connect-an-mcp-inbox.jsonld"}}