This is the single best starting point for an LLM agent or agent-platform developer integrating with the Mailagents Email Runtime.
If you only read one page first, read this one.
Mailagents is an email-first AI agent runtime built on:
- Cloudflare Workers
- Cloudflare Email Routing
- Cloudflare Queues
- Cloudflare R2
- Cloudflare D1
- Amazon SES
It provides:
- inbound email ingestion and normalization
- tenant-scoped agent and mailbox access
- mailbox-scoped high-level send and reply surfaces for common agent workflows
- drafts as the lower-level control point for outbound side effects
- asynchronous outbound delivery through SES
- MCP tools and composite workflows for agent orchestration
Think in this order:
- discover capabilities
- obtain a least-privilege bearer token
- read state before side effects
- prefer mailbox-scoped high-level send and reply surfaces
- use explicit
idempotencyKeyvalues for retryable side effects - branch only on stable error codes
Read these in order:
- docs/ai-onboarding.md
- docs/ai-auth.md
- docs/runtime-metadata.md
- docs/runtime-compatibility.md
- docs/agent-sdk-examples.md
- docs/agent-client-helper.md
Use these as deeper references:
- docs/ai-decision-rules.md
- docs/agent-workflow-packs.md
- docs/agent-capabilities.json
- docs/agent-client-helper.md
- docs/mcp-local.md
- docs/openapi.yaml
npm run example:agent:discovernpm run example:agent:reply-draftnpm run example:agent:operator-send
Three discovery layers are available:
- runtime metadata
Path:
/v2/meta/runtimeUse for richer environment-aware discovery. - compatibility contract
Path:
/v2/meta/compatibilityUse for stable agent branching logic and long-lived integrations. - compatibility schema
Path:
/v2/meta/compatibility/schemaUse for CI validation, SDK fixtures, and contract snapshot testing. - agent capabilities example fixture
Path:
docs/agent-capabilities.jsonUse as a repository-pinned admin-enabled example response and integration fixture.
Current shared dev URLs:
Default integration auth is a signed bearer token.
For mailboxes created through the signup API, the first bearer token is
returned inline by default from POST /public/signup. The same token may also
be delivered through the configured operator channel. Runtimes can explicitly
disable inline return if they want operator-channel-only bootstrap.
If that signup API token later expires, recovery should use
POST /public/token/reissue. That endpoint only emails a refreshed token to
the original operatorEmail from signup and does not return the token inline.
If the signup API token is still valid and the agent wants to rotate it without
emailing the operator, use POST /v1/auth/token/rotate. That authenticated
route can return the rotated token inline, deliver it back to the mailbox
itself, or both.
Minimum common scopes by job:
- read-only mail agent
mail:readtask:read
- reply-capable mail agent
mail:readtask:readdraft:createdraft:readdraft:send
- provisioning agent
agent:createagent:updateagent:bind
- recovery operator
mail:replay
Use:
- short expirations
- mailbox-scoped tokens when possible
- the narrowest scope set that still completes the workflow
- prefer reads before writes
- prefer
list_messages,send_email, andreply_to_messagefor mailbox-scoped agents - treat high-level send and reply calls as draft-backed side effects
- treat
send_draftas the lower-level delivery primitive when the workflow needs explicit draft control - treat replay as recovery, not as implicit permission to send
- keep admin and debug routes out of normal agent workflows
- reuse the same
idempotencyKeywhen retrying the same logical send or replay
Primitive tools:
list_messagesget_messageget_message_contentget_threadcreate_draftget_draftsend_draftreplay_message
Composite tools:
send_emailreply_to_messagereply_to_inbound_emailoperator_manual_send
When planning from tools/list, always inspect:
riskLevelsideEffectinghumanReviewRequiredsupportsPartialAuthorizationsendAdditionalScopes
Do not branch on free-form error text.
Branch on stable MCP error codes from the compatibility contract, such as:
auth_unauthorizedauth_missing_scopeaccess_mailbox_deniedresource_message_not_foundresource_draft_not_foundidempotency_conflictidempotency_in_progress
Suggested behavior:
auth_missing_scopeStop and request broader authorization.access_mailbox_deniedStop and request mailbox approval or a different token.resource_*_not_foundRefresh identifiers or upstream state.idempotency_in_progressRetry after a short delay.idempotency_conflictTreat as a different logical request unless caller reuse is intentional.
If you are trying to:
- understand the product and safety model
- understand auth and scopes
- orchestrate reply and send workflows
- copy working requests quickly
- start from a lightweight TypeScript helper
- integrate against the stable contract
- validate compatibility in CI
- start from a pinned fixture instead of a live endpoint
- read
/v2/meta/compatibility - validate against
/v2/meta/compatibility/schema - obtain a mailbox-scoped token, usually via the configured operator delivery path triggered by
POST /public/signup - call
tools/list - filter out tools that require human review when automation is not allowed
- prefer read tools first
- use
list_messagesto inspect mailbox state - use
send_emailandreply_to_messagefor the common mailbox workflow - drop down to
create_draftandsend_draftonly when explicit draft control is required - use
idempotencyKeyon side-effecting retries - record the compatibility version you integrated against