Connecting AI Agents (MCP)
Connect Claude Desktop, Claude Code, or other MCP-compatible agents to TrekMail.
Article details
Type, difficulty, plans, and last updated info.
▼
Article details
Type, difficulty, plans, and last updated info.
- Type
- Reference
- Difficulty
- Intermediate
- Plans
- Starter · Pro · Agency
- Last updated
- Apr 29, 2026
The TrekMail MCP server lets AI agents manage your email infrastructure through natural language. It exposes 181 tools covering domains, DNS, spam metrics, mailboxes, invites, forwarding, mail filters, auto-reply, sieve, safe deletion, SMTP configuration, Cloudflare DNS integration, Drive file storage, support tickets, account and billing, email migrations, email verification, and the full webmail feature surface — messages, folders, attachments, drafts, scheduled send, contacts, contact groups, calendar, compose helpers, identities, templates, and blocked senders.
What you get
- 181 agent tools covering domains, DNS, spam metrics, mailboxes, invites, forwarding, sieve, safe deletion, SMTP configuration, Cloudflare DNS integration, support tickets, account and billing, email migrations, email verification (8 verifier tools), 38 Drive tools for file storage, and the full webmail API surface (52 message tools).
- Dual-token architecture — separate ops token (infrastructure) and message token (full webmail operations).
- Automatic idempotency — retries never create duplicate resources.
- Two-step delete — mailbox deletion requires explicit intent + confirmation.
- Destructive operations gate — delete tools are disabled by default.
- Sending safety gates — email sending requires both an environment gate and per-call confirmation.
- Migration safety gates — migration write tools are disabled by default and require per-call confirmation.
- Full audit logging — every API and MCP operation is logged with 90-day retention.
Before you start
- Create an API token on the AI Agents & API → Tokens page.
- For email read/send, create a message token via the API using your ops token (see the Connect Agent tab for instructions).
- All plans can connect agents. Nano plans can use Email Verifier tools only. Starter plans add read-only infrastructure tools plus verifier; Starter plans also have mailbox forwarding available via the dashboard (not via API write tools). Pro and Agency plans get full access (read + write).
- Have Node.js 18+ installed (for local setup), or Docker for container-based setup.
- First time? The Guide button on the AI Agents & API page walks you through connection methods, token setup, and the audit log step by step.
Install the MCP server
Clone the repository and build:
git clone https://github.com/trekmail/mcp-server trekmail-mcp
cd trekmail-mcp
npm install
npm run build
Claude Desktop
Add this to your Claude Desktop MCP configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"trekmail": {
"command": "node",
"args": ["./trekmail-mcp/build/index.js"],
"env": {
"TREKMAIL_BASE_URL": "https://trekmail.net",
"TREKMAIL_API_TOKEN": "tm_live_your_token",
"TREKMAIL_MESSAGE_TOKEN": "tm_msg_your_token",
"TREKMAIL_ALLOW_SENDING": "false",
"TREKMAIL_ALLOW_MIGRATION": "false"
}
}
}
}
Update the args path to point to where you cloned the repository. Replace the tokens with your own. You can omit TREKMAIL_MESSAGE_TOKEN if you only need infrastructure tools, or omit TREKMAIL_API_TOKEN if you only need message tools. At least one token is required.
Claude Code
Add this to your Claude Code MCP settings (.claude/settings.json or project-level config):
{
"mcpServers": {
"trekmail": {
"command": "node",
"args": ["./trekmail-mcp/build/index.js"],
"env": {
"TREKMAIL_BASE_URL": "https://trekmail.net",
"TREKMAIL_API_TOKEN": "tm_live_your_token",
"TREKMAIL_MESSAGE_TOKEN": "tm_msg_your_token",
"TREKMAIL_ALLOW_SENDING": "false",
"TREKMAIL_ALLOW_MIGRATION": "false"
}
}
}
}
Docker
If you prefer Docker, build the image from the repo and run it:
git clone https://github.com/trekmail/mcp-server trekmail-mcp
cd trekmail-mcp
docker build -t trekmail-mcp .
docker run -i \
-e TREKMAIL_BASE_URL=https://trekmail.net \
-e TREKMAIL_API_TOKEN=tm_live_your_token \
-e TREKMAIL_MESSAGE_TOKEN=tm_msg_your_token \
-e TREKMAIL_ALLOW_SENDING=false \
-e TREKMAIL_ALLOW_MIGRATION=false \
trekmail-mcp
Local npm (development)
git clone https://github.com/trekmail/mcp-server trekmail-mcp
cd trekmail-mcp
npm install && npm run build
TREKMAIL_BASE_URL=https://trekmail.net \
TREKMAIL_API_TOKEN=tm_live_your_token \
TREKMAIL_MESSAGE_TOKEN=tm_msg_your_token \
TREKMAIL_ALLOW_SENDING=false \
TREKMAIL_ALLOW_MIGRATION=false \
npm start
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
TREKMAIL_BASE_URL |
Yes | — | Your TrekMail URL (https://trekmail.net) |
TREKMAIL_API_TOKEN |
At least one token | — | Ops token starting with tm_live_ (infrastructure tools) |
TREKMAIL_MESSAGE_TOKEN |
At least one token | — | Message token starting with tm_msg_ (email read/send tools) |
TREKMAIL_TIMEOUT_MS |
No | 30000 |
Request timeout in milliseconds |
TREKMAIL_ALLOW_DESTRUCTIVE |
No | false |
Enable destructive tools (delete intents, domain delete, password change, pause mailbox, delete message, SMTP config, revoke message token, delete Cloudflare token, Drive trash/purge/empty-trash, delete folder, empty folder, cancel scheduled message, delete contact, delete contact group, delete calendar event, delete identity, delete template, unblock sender) |
TREKMAIL_ALLOW_SENDING |
No | false |
Enable the send_message tool |
TREKMAIL_ALLOW_MIGRATION |
No | false |
Enable migration write tools (start_migration, retry_migration, delete_migration, delete_bulk_migration, update_bulk_migration_job_password, test_migration_connection). Note: cancel_migration and cancel_bulk_migration are always available as safety operations. |
Drive tools for agents
With an ops token that includes Drive scopes, the MCP server exposes 38 Drive tools for spaces, usage, browsing, uploads, files, folders, Trash, bulk operations, public share links, and read-only Drive Add-on status. The complete MCP server now exposes 181 tools.
For a Drive-only agent, set TREKMAIL_API_TOKEN and grant only the scopes the workflow needs. Keep TREKMAIL_ALLOW_DESTRUCTIVE=false unless the agent is running a reviewed purge or empty-trash job. Drive Add-on purchase, resize, and cancel are not MCP tools; agents can read add-on status and pricing, but billing changes stay in the dashboard.
See Drive MCP Tools Overview and Connecting AI Agents to TrekMail Drive.
Available tools
The MCP server exposes these tools to connected agents. Tools are registered conditionally based on which tokens are provided.
Domain tools (ops token)
| Tool | Description |
|---|---|
list_domains |
List domains with optional status/search filters |
get_domain |
Get details for a specific domain |
create_domain |
Add a new domain to the account |
delete_domain |
Delete a domain (gated: requires TREKMAIL_ALLOW_DESTRUCTIVE) |
update_domain_catch_all |
Configure or clear the catch-all address |
retry_domain_dkim |
Retry DKIM key provisioning |
update_domain_note |
Update the admin note on a domain |
bulk_add_domains |
Add up to 20 domains in one call |
DNS tools (ops token)
| Tool | Description |
|---|---|
get_dns_requirements |
Get required DNS records for a domain |
dns_recheck |
Trigger DNS verification (returns check ID) |
get_dns_check |
Poll DNS check results |
Mailbox tools (ops token)
| Tool | Description |
|---|---|
list_mailboxes |
List mailboxes with optional filters |
get_mailbox |
Get details for a specific mailbox |
create_mailbox_generated_password |
Create a mailbox with auto-generated password (optional storage_allocation_mb carves out dedicated storage from the account pool) |
change_mailbox_password |
Change the password for a mailbox |
update_mailbox_note |
Update the admin note on a mailbox |
pause_mailbox |
Disable a mailbox (set status to disabled) |
resume_mailbox |
Re-enable a paused mailbox |
enable_imap |
Enable IMAP access for a mailbox (required for Message API) |
create_invite |
Send a setup invite to a recipient (optional storage_allocation_mb pre-allocates dedicated storage that the recipient inherits at redeem) |
create_invites_bulk |
Send up to 100 invites in one call (per-item storage_allocation_mb supported) |
create_mailboxes_bulk |
Create up to 100 mailboxes in one call (per-item storage_allocation_mb supported) |
get_forwarding |
Get forwarding config for a mailbox |
set_forwarding |
Configure forwarding rules |
Sieve tools (ops token)
| Tool | Description |
|---|---|
get_sieve_script |
Get the raw Sieve script for a mailbox |
upload_sieve_script |
Upload a raw Sieve script for a mailbox |
Delete tools (ops token)
| Tool | Description |
|---|---|
create_delete_intent |
Step 1: create a time-limited delete intent |
confirm_delete_intent |
Step 2: confirm and execute deletion (gated: requires TREKMAIL_ALLOW_DESTRUCTIVE) |
Migration tools (ops token)
| Tool | Description |
|---|---|
test_migration_connection |
Validate IMAP credentials and discover source folders with counts |
list_migrations |
List migrations with optional status/mailbox filters |
get_migration |
Get detailed migration status with per-folder breakdown |
start_migration |
Start a new email migration (gated: TREKMAIL_ALLOW_MIGRATION + confirm_start) |
cancel_migration |
Cancel a running migration (always available — safety operation, requires confirm_cancel) |
retry_migration |
Retry a failed or cancelled migration (gated: TREKMAIL_ALLOW_MIGRATION + confirm_retry) |
delete_migration |
Delete a completed/failed migration record (gated: TREKMAIL_ALLOW_MIGRATION + confirm_delete) |
preview_bulk_migration |
Validate and preview a bulk migration batch (gated: TREKMAIL_ALLOW_MIGRATION) |
start_bulk_migration |
Start a bulk migration batch (gated: TREKMAIL_ALLOW_MIGRATION + confirm_start) |
list_bulk_migrations |
List bulk migration batches with optional status filter |
get_bulk_migration |
Get details of a bulk migration batch |
cancel_bulk_migration |
Cancel an active bulk batch (requires confirm_cancel) |
retry_bulk_migration |
Retry failed jobs in a batch (gated: TREKMAIL_ALLOW_MIGRATION + confirm_retry) |
resume_bulk_migration |
Resume a paused batch (requires confirm_resume) |
delete_bulk_migration |
Delete a terminal bulk migration batch (gated: TREKMAIL_ALLOW_MIGRATION + confirm_delete) |
update_bulk_migration_job_password |
Update source password for a failed job (gated: TREKMAIL_ALLOW_MIGRATION) |
Ticket tools (ops token)
| Tool | Description |
|---|---|
list_tickets |
List support tickets with optional filters |
get_ticket |
Get ticket details |
get_ticket_messages |
Get messages in a ticket thread |
create_ticket |
Create a new support ticket |
reply_to_ticket |
Reply to an existing ticket |
close_ticket |
Close a ticket |
SMTP tools (ops token)
| Tool | Description |
|---|---|
get_smtp_config |
View current SMTP mode and connection details |
update_smtp_config |
Update SMTP configuration (platform or custom) |
delete_smtp_connection |
Delete a custom SMTP connection |
test_smtp |
Start an async SMTP connection test (returns job ID) |
get_smtp_test_status |
Poll SMTP test results |
Spam metrics tools (ops token)
| Tool | Description |
|---|---|
get_spam_metrics |
Get daily spam protection metrics for a domain (inbound, spam caught, rejected, clean) |
get_spam_summary |
Get aggregated spam protection summary for a domain (spam rate, status, top triggered rules) |
Account tools (ops token)
| Tool | Description |
|---|---|
get_account |
View account info, plan, limits, and usage |
get_billing_status |
View billing status and subscription details |
list_invoices |
List invoice history |
Message token management (ops token)
| Tool | Description |
|---|---|
create_message_token |
Create a message API token for a mailbox (returns the plaintext token once) |
list_message_tokens |
List all message tokens for a mailbox |
revoke_message_token |
Revoke a message token (gated: requires TREKMAIL_ALLOW_DESTRUCTIVE) |
Message tools (message token)
The message token unlocks 52 tools covering the full webmail surface. Tools are organized by feature area.
Core messages
| Tool | Description |
|---|---|
list_messages |
List messages in a folder with cursor pagination |
read_message |
Get a single message with full body and inline attachments |
send_message |
Send an email from the mailbox (requires dual safety gates) |
delete_message |
Delete a message permanently (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
move_message |
Move a message to a different IMAP folder |
update_message_flags |
Mark read/unread, starred/unstarred on a message |
get_raw_message |
Download the full RFC822 raw source of a message |
report_spam |
Report a message as spam — moves to Junk and trains the filter |
report_ham |
Mark a Junk message as not spam — moves to Inbox and trains the filter |
bulk_action |
Apply an action (read, star, delete, move, spam) to up to 50 messages at once |
Folders
| Tool | Description |
|---|---|
list_folders |
List all IMAP folders for the mailbox |
create_folder |
Create a new IMAP folder |
rename_folder |
Rename an existing folder |
delete_folder |
Delete a folder and its contents (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
empty_folder |
Permanently delete all messages in Trash or Junk (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Attachments
| Tool | Description |
|---|---|
download_attachment |
Download a single attachment by index — returns base64 content |
download_all_attachments |
Download all attachments from a message as a base64 ZIP |
Drafts
| Tool | Description |
|---|---|
save_draft |
Save a new draft to the IMAP Drafts folder |
update_draft |
Replace an existing draft (deletes old UID, appends updated version) |
Scheduled send
| Tool | Description |
|---|---|
schedule_message |
Schedule a message for future delivery (requires TREKMAIL_ALLOW_SENDING + confirm_send) |
list_scheduled |
List all pending scheduled messages for the mailbox |
cancel_scheduled |
Cancel a pending scheduled message (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Contacts
| Tool | Description |
|---|---|
list_contacts |
List contacts with optional search filter |
create_contact |
Create a contact — upserts if email already exists |
update_contact |
Update a contact's fields |
delete_contact |
Delete a contact (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
import_contacts |
Import contacts from base64-encoded CSV or VCF content |
export_contacts |
Export all contacts as CSV or VCF — returns base64 content |
Contact groups
| Tool | Description |
|---|---|
create_contact_group |
Create a named contact group |
rename_contact_group |
Rename a contact group |
delete_contact_group |
Delete a contact group (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
add_group_members |
Add contacts to a group by ID |
remove_group_members |
Remove contacts from a group |
Calendar
| Tool | Description |
|---|---|
list_calendar_events |
List calendar events in a date range |
create_calendar_event |
Create a new event with title, start/end, location, and notes |
update_calendar_event |
Update an existing event |
delete_calendar_event |
Delete a calendar event (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Compose helpers
These tools prepare the data for a reply or forward — they do not send anything. Pass the returned data directly to send_message or save_draft.
| Tool | Description |
|---|---|
get_reply_data |
Pre-populate a reply (To, Re: subject, quoted body, In-Reply-To header) |
get_reply_all_data |
Pre-populate a reply-all (To + Cc from all original recipients) |
get_forward_data |
Pre-populate a forward (Fwd: subject, forwarded body, original attachment metadata) |
Identities (send-from addresses)
| Tool | Description |
|---|---|
list_identities |
List all send-from identities for the mailbox |
create_identity |
Create an identity using the mailbox address or a configured alias |
update_identity |
Update identity name, reply-to, or HTML signature |
delete_identity |
Delete an identity — cannot delete the default (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Templates
| Tool | Description |
|---|---|
list_templates |
List all saved message templates |
create_template |
Create a template with name, subject, and HTML body |
update_template |
Update a template |
delete_template |
Delete a template (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Blocked senders
| Tool | Description |
|---|---|
list_blocked_senders |
List all blocked email addresses and domains |
block_sender |
Block a specific email address or entire domain (e.g., @spam.com) |
unblock_sender |
Remove a block (gated: TREKMAIL_ALLOW_DESTRUCTIVE) |
Email Verifier tools (ops token)
| Tool | Description |
|---|---|
verify_email |
Verify a single email address |
verify_email_bulk |
Submit a bulk verification job |
verify_job_status |
Check job progress and results |
verify_job_download |
Download job results as CSV |
verify_credits |
Check remaining credit balance |
verify_list_jobs |
List all verification jobs |
verify_cancel_job |
Cancel a running job and refund unprocessed credits |
verify_delete_job |
Permanently delete a job and all results (GDPR) |
Email Verifier tools are available on all plans, including Nano. The only limitation is your credit balance.
Cloudflare tools (ops token)
| Tool | Description |
|---|---|
validate_cloudflare_token |
Validate a Cloudflare API token |
list_cloudflare_zones |
List DNS zones accessible by a Cloudflare token |
connect_cloudflare_domains |
Connect domains to a Cloudflare account |
preview_cloudflare_dns |
Preview DNS changes that would be applied via Cloudflare |
apply_cloudflare_dns |
Apply DNS changes to Cloudflare-managed zones |
list_cloudflare_tokens |
List stored Cloudflare tokens |
delete_cloudflare_token |
Delete a stored Cloudflare token (gated: requires TREKMAIL_ALLOW_DESTRUCTIVE) |
Cloudflare tools are available on Pro and Agency plans.
Safety and destructive operations
By default, TREKMAIL_ALLOW_DESTRUCTIVE is false. With this setting, delete tools return an error explaining how to enable them. Set it to true only if you trust the agent to handle mailbox deletion.
Even with destructive operations enabled, deletion always requires two steps and the agent must explicitly set confirm: true. See Safety Rails and Delete Intents for details.
Sending safety gates
The send_message and schedule_message tools have two independent safety gates that must both pass:
- Environment gate:
TREKMAIL_ALLOW_SENDING=truemust be set when starting the MCP server. - Per-call gate: The agent must pass
confirm_send=trueas a parameter on every call.
This dual-gate design prevents accidental email sends. Set TREKMAIL_ALLOW_SENDING=false (the default) if your agent should only read messages. Note that list_scheduled works without any gate — the sending gate applies only to creating or sending scheduled messages.
Migration safety gates
Migration write tools (start_migration, retry_migration, delete_migration, delete_bulk_migration, update_bulk_migration_job_password, test_migration_connection, preview_bulk_migration, start_bulk_migration, retry_bulk_migration) have two independent safety gates:
- Environment gate:
TREKMAIL_ALLOW_MIGRATION=truemust be set when starting the MCP server. - Per-call gate: Each tool requires its own confirmation parameter (
confirm_start=true,confirm_retry=true, orconfirm_delete=true).
cancel_migration, cancel_bulk_migration, and resume_bulk_migration are always available regardless of the environment gate — they are safety/resumption operations. They still require per-call confirmation parameters.
Read-only migration tools (list_migrations, get_migration, list_bulk_migrations, get_bulk_migration) work without any gates.
Quick fixes
- Agent cannot connect: Verify the
build/index.jspath is correct and you rannpm run buildafter cloning. - "Missing bearer token" errors: Check that at least one of
TREKMAIL_API_TOKENorTREKMAIL_MESSAGE_TOKENis set. - Read-only tools work but writes fail: Your token is on a Starter plan. Upgrade to Pro for full API write access.
- Delete tools return errors: Set
TREKMAIL_ALLOW_DESTRUCTIVE=truein the environment. This applies to all delete/destructive tools — messages, folders, contacts, calendar, identities, templates, blocked senders, and scheduled messages. - Send tool returns "Sending is disabled": Set
TREKMAIL_ALLOW_SENDING=truein the environment. - Send tool returns "Send not confirmed": The agent must pass
confirm_send=trueon eachsend_messageorschedule_messagecall. - No message tools appear: Ensure
TREKMAIL_MESSAGE_TOKENis set with a validtm_msg_token. - Migration write tools return errors: Set
TREKMAIL_ALLOW_MIGRATION=truein the environment. - 503 on migration start: The server is at migration capacity. Retry in a few minutes.
- Attachment download fails: Attachments are returned as base64. Large attachments (up to 25 MB) may take a few seconds.
download_all_attachmentsreturns a base64-encoded ZIP of all attachments. - Draft disappeared after update:
update_draftdeletes the old draft UID and creates a new one. Always use the returned new UID for subsequent operations. - Calendar event not found: Events are scoped to the specific mailbox. Confirm the message token was issued for the correct mailbox.
Related articles
Jump to nearby guides that continue the workflow.