Skip to content
Agent Identities / Developer docs

Developer docs

Connect any agent to Mailrun.

Find the API reference, MCP connection steps, and webhook setup for your agent or application. Start here whether you use an MCP client or call the HTTP API directly.

Open the API reference

Choose your integration

An identity is the email address and phone number your agent uses. Free supplies a Mailrun-hosted email address and 1 domain of your own, with no phone. Solo, Team, and Scale support email and phone; Receptionist is phone only. Connect your own agent or use Mailrun’s hosted agents with your instructions.

MCP client

Connect the agent you use

Add Mailrun’s hosted MCP server to a client that supports Streamable HTTP and a bearer token. Give the agent access to the tools it needs.

Connect your client

HTTP API

Build your own integration

Call the HTTP API from your application. Follow the curl walkthrough to create an identity, send an email, and read the reply.

Try the API

Hosted agents

Email replies and phone calls

Set up the hosted email agent or hosted receptionist in the customer portal. The email agent answers from your instructions, playbook, and files on Solo, Team, or Scale with usage billing active. The receptionist answers calls, takes messages, and collects appointment requests for you to confirm. It does not check calendars or book appointments.

Explore hosted agents

API reference and guides

The API base is https://agent-api.mailrun.ai, with endpoints under /v1. Use the reference for endpoint schemas and the workflow guide for lifecycle and event handling.

  • API reference. Swagger UI documents every endpoint and its schemas. Open the API reference
  • Workflow guide. A plain Markdown document covering what the API is, domain onboarding, identity lifecycle, sending and reading mail, webhooks and events in section 5, the status-machine reference, and the error catalog. It also covers usage, metered voice billing, and voicemail. Read the workflow guide
  • OpenAPI document. The OpenAPI 3 specification in YAML, ready to import into tools and code generators. Get the OpenAPI document
  • API quickstart. A curl walkthrough on this site: create an identity, send an email, and read the reply. Follow the API quickstart
  • OAuth authorization-server metadata. An MCP client that supports sign-in reads this RFC 8414 metadata to discover the sign-in endpoints. Any MCP client that supports sign-in can connect with your Mailrun account, including Claude’s apps and Claude Code. You can also use an API key. Read the sign-in metadata

Connect an MCP client

Use https://agent-api.mailrun.ai/mcp with Streamable HTTP transport. API keys work with any remote MCP client that lets you set a bearer token.

  1. Create an API key at https://app.mailrun.ai/agent with only the scopes your agent needs. In any MCP client that supports sign-in, you can use your Mailrun account instead.
  2. Open your client’s MCP settings, which may be called Connectors, Integrations, or MCP servers. Add a remote server with the URL https://agent-api.mailrun.ai/mcp and select Streamable HTTP transport.
  3. Set the Authorization header to Bearer <your API key>. If your client supports sign-in, complete the prompt with your Mailrun account instead.
  4. Enable the tools you want and try a read-only call first: “List my Mailrun agent identities.”

This is the Claude Code command to add the server. Other clients take the same URL in their own MCP settings.

claude mcp add --transport http mailrun https://agent-api.mailrun.ai/mcp

Notes for your client

  • Claude. Sign in with your Mailrun account from claude.ai or the official desktop and mobile apps. Follow the Claude guide
  • Claude Code. Add the server with the terminal command above, then start Claude Code and run /mcp to choose Mailrun and sign in. See the Claude Code steps
  • Other MCP clients. Use the same server URL and sign in with your Mailrun account if your client supports sign-in. If it cannot sign in, or you prefer a key, use an API key from the customer portal as the bearer token.
  • Sign-in for another client. If sign-in does not work in your client, use an API key from the customer portal as a bearer token. Contact Mailrun if you need help. Contact Mailrun

Webhooks and replies

Yes, Mailrun supports webhooks. You don’t need to poll for replies. Register an HTTPS receiver with POST /v1/webhooks or the create_webhook MCP tool, then choose the event types to receive. An empty event-type list subscribes to all types except sms.received, which must be listed by name.

When new mail arrives, Mailrun’s mail server pushes it to the API. The API records an email.received event and POSTs it to every subscribed endpoint. Other events cover sending, delivery failures, calls, voicemail, domain lifecycle, and usage; the full list is in section 5 of the workflow guide.

  • Read the message. An email.received event carries message_id, thread_id, and size_bytes, never the subject or body. Fetch the message with GET /v1/identities/{id}/messages/{messageId}, using message_id as messageId. A reply to an email your agent sent has the same thread_id.
  • Verify each delivery. X-Mailrun-Timestamp contains Unix seconds. X-Mailrun-Signature contains sha256=<hex>, the HMAC-SHA256 of {timestamp}.{raw body} using your endpoint’s secret. Verify the signature against the raw body and reject timestamps more than 300 seconds from your clock. Save the whsec_... secret when you create the endpoint: it is returned once and cannot be read back. To rotate it, delete and recreate the endpoint.
  • Handle retries and gaps. Return a 2xx quickly. Non-2xx responses trigger retries with exponential backoff, up to six attempts. An endpoint that keeps failing is automatically disabled and a webhook.endpoint_disabled event is recorded; PATCH the endpoint to re-enable it. Deliveries can repeat, so deduplicate on the event id. If your receiver was down, recover missed events with GET /v1/events?since=<ISO timestamp>. It returns the same envelope as the webhook. Events are retained for 90 days.

Read section 5: Webhooks and events (plain Markdown)

Keys, scopes, and sign-in

You need an Agent Identities account. Both the HTTP API and MCP server use an Authorization: Bearer header. Create API keys at https://app.mailrun.ai/agent and give each integration only the scopes it needs. Keep keys on a server or trusted machine, never in browser code. Keys and sign-in use the same scopes. Rate limits, daily send caps per identity, and plan allowances apply identically through MCP and HTTP.

OAuth sign-in lets you use your Mailrun account and review permissions without copying a key. Any MCP client that supports sign-in can connect, including Claude’s apps and Claude Code. Clients that need to register themselves automatically cannot sign in yet. If your client cannot sign in, or you prefer a key, use an API key from the customer portal as a bearer token.

Manage API keys and connected apps

Read what each permission allows

Get help with an integration

When you contact Mailrun, include the identity id, the request_id from the error response, and the time the issue occurred.

Contact Mailrun

Agent Identities

Bring your agent to Mailrun.

Choose a plan and set up your account online. Free includes a Mailrun-hosted email address and 1 domain you already own. Add your root domain on the customer portal’s Agent page or through the API or MCP, then point its nameservers at Mailrun. Free does not support subdomains, and setup must finish before your domain’s mailboxes can be used. Create an API key in the customer portal and connect your agent. Our team can help if you need it.

Get started
AI agent email and phone API docs · Mailrun.ai