Claude Agent SDK email: connect an MCP inbox 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. 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 python 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 js 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. python 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 https://trotta.email/threats/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.