loading…
Search for a command to run...
loading…
A Model Context Protocol server that exposes the TrekMail API v1 as 185 agent tools for managing email infrastructure and messaging.
A Model Context Protocol server that exposes the TrekMail API v1 as 185 agent tools for managing email infrastructure and messaging.
A Model Context Protocol (MCP) server that exposes the TrekMail API v1 as 191 agent tools. This is a thin adapter — all business logic lives in the TrekMail API; this server handles transport, authentication, retries, and safety gates.
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 \
npm start
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 \
trekmail-mcp
The MCP server supports two independent token types. At least one is required:
| Token | Env Var | Prefix | Unlocks |
|---|---|---|---|
| Ops token | TREKMAIL_API_TOKEN |
tm_live_ |
133 infrastructure tools (domains, DNS, mailboxes, invites, aliases, forwarding, mail filters, auto-reply, sieve, delete intents, migrations, SMTP, tickets, account, billing, spam stats, verifier, message token management, Cloudflare DNS, Drive, and Drive sync-device passwords) |
| Message token | TREKMAIL_MESSAGE_TOKEN |
tm_msg_ |
52 message tools (messages, attachments, drafts, bulk actions, folders, scheduled send, contacts, contact groups, calendar, compose helpers, identities, templates, blocked senders) |
Tools are registered conditionally — only token types you provide get their tools. You can supply one or both:
# Infrastructure only
TREKMAIL_API_TOKEN=tm_live_your_token npm start
# Messages only
TREKMAIL_MESSAGE_TOKEN=tm_msg_your_token npm start
# Both
TREKMAIL_API_TOKEN=tm_live_your_token \
TREKMAIL_MESSAGE_TOKEN=tm_msg_your_token \
npm start
| Variable | Required | Default | Description |
|---|---|---|---|
TREKMAIL_BASE_URL |
Yes | — | Your TrekMail instance URL |
TREKMAIL_API_TOKEN |
At least one token | — | Ops token (must start with tm_live_) |
TREKMAIL_MESSAGE_TOKEN |
At least one token | — | Message token (must start with tm_msg_) |
TREKMAIL_TIMEOUT_MS |
No | 30000 |
Request timeout in milliseconds |
TREKMAIL_USER_AGENT |
No | trekmail-mcp/1.0.4 |
User-Agent header |
TREKMAIL_ALLOW_DESTRUCTIVE |
No | false |
Enable destructive tools (delete intents, domain delete, password change, pause, SMTP config, revoke token, delete Cloudflare token, Drive trash/purge/empty-trash, Drive sync-device revoke/rotate, message deletes) |
TREKMAIL_ALLOW_SENDING |
No | false |
Enable 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) |
TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_DESTRUCTIVE)storage_allocation_mb carves out dedicated storage from the account pool; omit for shared)TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_DESTRUCTIVE)storage_allocation_mb (sum across the batch is validated against the available pool)storage_allocation_mb pre-allocates dedicated storage; the recipient inherits it at redeem)storage_allocation_mb supported)TREKMAIL_ALLOW_DESTRUCTIVE)targets array (one or more destinations), keep_copy, and destination_limit (the plan-tier cap so the agent can preflight an set_forwarding call without trial-and-error).targets array accepts up to 30 entries client-side; the server enforces the actual per-plan cap — Starter 5, Pro 15, Agency 30 — and returns a 422 limit_exceeded error with the cap if you pass more. CRLF / loop / self-forward / MX validation is run per destination, so a single bad entry rejects the whole save.TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)timezone resolves naïve datetimes; explicit ISO offset always wins)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE=true)TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_DESTRUCTIVE)TREKMAIL_ALLOW_MIGRATION + confirm_start=true)confirm_cancel=true)TREKMAIL_ALLOW_MIGRATION + confirm_retry=true)TREKMAIL_ALLOW_MIGRATION + confirm_delete=true)TREKMAIL_ALLOW_MIGRATION)TREKMAIL_ALLOW_MIGRATION + confirm_start=true)confirm_cancel=true)TREKMAIL_ALLOW_MIGRATION + confirm_retry=true)confirm_resume=true)TREKMAIL_ALLOW_MIGRATION + confirm_delete=true)TREKMAIL_ALLOW_MIGRATION)TREKMAIL_ALLOW_DESTRUCTIVE)All mutating tools (POST/PUT) generate deterministic idempotency keys from sha256(tool_name + canonical_params). This means:
idempotency_key parameter on any mutating toolMailbox deletion requires two separate tool calls:
create_delete_intent → returns intent with 10-minute expiryconfirm_delete_intent → executes deletion (irreversible)Both delete tools require TREKMAIL_ALLOW_DESTRUCTIVE=true. Without it, they return an error message explaining how to enable.
The confirm_delete_intent tool has an additional confirm: true parameter that must be explicitly set.
The send_message tool has two independent safety gates that must both pass:
TREKMAIL_ALLOW_SENDING=true must be set in the environmentconfirm_send=true must be passed as a parameterThis dual-gate design prevents accidental email sends. The agent must both be configured to allow sending and explicitly confirm each send.
The start_migration, retry_migration, and delete_migration tools require TREKMAIL_ALLOW_MIGRATION=true in the environment. cancel_migration is always available as a safety operation. test_migration_connection requires the gate because it makes outbound IMAP connections. Read-only tools (list_migrations, get_migration) work without any gate.
Additionally, each write tool requires a per-call confirmation parameter (confirm_start, confirm_cancel, or confirm_retry set to true).
{
"mcpServers": {
"trekmail": {
"command": "node",
"args": ["/path/to/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": "true"
}
}
}
}
{
"mcpServers": {
"trekmail": {
"command": "node",
"args": ["/path/to/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": "true"
}
}
}
}
1. dns_recheck(domain_id: 5) → { check_id: 42 }
2. get_dns_check(check_id: 42) → { status: "pending" }
3. (wait) get_dns_check(check_id: 42) → { status: "complete", results: {...} }
1. create_mailbox_generated_password(domain_id: 5, local_part: "alice")
→ { id: 10, email: "[email protected]", password: "..." }
2. set_forwarding(mailbox_id: 10, enabled: true, targets: ["[email protected]"], keep_copy: true)
# Fan one shared mailbox out to several humans.
1. create_mailbox_generated_password(domain_id: 5, local_part: "sales")
→ { id: 14, email: "[email protected]", password: "..." }
2. get_forwarding(mailbox_id: 14)
→ { enabled: false, targets: [], keep_copy: false, destination_limit: 15 } # Pro plan
3. set_forwarding(
mailbox_id: 14,
enabled: true,
targets: ["[email protected]", "[email protected]", "[email protected]"],
keep_copy: true # also leave a copy in sales@ for record-keeping
)
# Carve out 5 GB just for this mailbox — other shared mailboxes can't grow into it.
1. create_mailbox_generated_password(
domain_id: 5,
local_part: "ceo",
storage_allocation_mb: 5120
) → { id: 11, email: "[email protected]", password: "...", is_pooled_storage: false, storage_allocation_mb: 5120 }
# Mix shared and dedicated in one call. The sum of all storage_allocation_mb
# across the batch is checked against the available pool — if it would
# over-commit, the entire batch is rejected with 422 storage_pool_exceeded.
1. bulk_create_mailboxes(items: [
{ domain_id: 5, local_part: "support" }, # shared
{ domain_id: 5, local_part: "founder", storage_allocation_mb: 10240 }, # 10 GB dedicated
{ domain_id: 5, local_part: "team-lead", storage_allocation_mb: 5120 }, # 5 GB dedicated
])
1. create_invite(domain_id: 5, local_part: "bob", recipient_email: "[email protected]")
→ { id: 1, status: "pending", invite_url: "..." }
# Pending dedicated invites count against the available pool until they
# are redeemed or expire — no over-committing.
1. create_invite(
domain_id: 5,
local_part: "exec",
recipient_email: "[email protected]",
storage_allocation_mb: 10240
) → { id: 2, status: "pending", storage_allocation_mb: 10240 }
# When the recipient redeems, the new mailbox inherits the 10 GB dedicated allocation.
# If the pool no longer fits at redeem time, the new mailbox falls back to shared
# (the recipient sees a notice on the success page) — redeem itself never fails.
1. create_delete_intent(mailbox_id: 10) → { id: 7, expires_at: "...", status: "pending" }
2. confirm_delete_intent(intent_id: 7, confirm: true) → { status: "confirmed" }
1. list_messages(folder: "INBOX", limit: 10, unread_only: true)
→ { messages: [...], pagination: { has_more: true, next_before_uid: 45 } }
2. read_message(uid: 50) → { from, subject, body_text, body_html, attachments: [...] }
1. test_migration_connection(source_host: "imap.gmail.com", source_port: 993, source_security: "ssl", source_email: "[email protected]", source_password: "app-password")
→ { success: true, folders: { "INBOX": 1234, "Sent": 567, ... } }
2. start_migration(mailbox_id: 10, provider: "gmail", source_host: "imap.gmail.com", source_port: 993, source_security: "ssl", source_email: "[email protected]", source_password: "app-password", target_password: "mailbox-pass", confirm_start: true)
→ { id: 5, status: "pending", ... }
3. get_migration(id: 5) → { status: "processing", progress: 45, folders: [...] }
4. (poll) get_migration(id: 5) → { status: "completed", progress: 100, imported_messages: 1801 }
1. send_message(
to: ["[email protected]"],
subject: "Weekly Report",
body_text: "Please find the report attached.",
confirm_send: true,
idempotency_key: "weekly-report-2026-02-07"
) → { status: "queued", message_id: "[email protected]", queued_at: "..." }
42 tools for the /api/v1/drive/* REST surface (38 file/folder/share/addon
tools + 4 sync-device password tools added 2026-05-23). Drive is available
through both the TrekMail REST API and this MCP server when the ops token
has the matching Drive scopes. See the TrekMail app/API docs for the full
REST reference.
| Tool | Purpose |
|---|---|
drive_spaces_list |
List Drive spaces this token can enumerate (account_drive + per-mailbox) |
drive_storage_summary |
Account-wide pool snapshot (used / limit / addon flags) |
drive_space_usage |
Per-space quota snapshot |
drive_browse_folder |
Cursor-paginated listing of one folder's files + subfolders |
drive_folder_tree |
Flat tree of every folder in a space |
drive_select_all_ids |
Bulk-select helper (capped at 5000 ids) |
drive_file_get |
File metadata |
drive_file_download_url |
Short-lived download URL (forced attachment) |
drive_file_rename / _move / _trash / _restore / _purge |
File CRUD |
drive_folder_create / _update / _move / _trash / _restore / _purge |
Folder CRUD; _update accepts name and/or color (#RRGGBB); _create accepts is_shared to publish to the whole account immediately |
drive_folder_share_with_account / _stop_sharing |
Toggle whether a folder is visible to every mailbox in the account (Phase H — moves the folder + subtree from mailbox-personal Drive to account-drive when needed) |
drive_trash_list / _empty |
Trash listing + nuke |
drive_bulk_trash / _restore / _move / _purge |
One call, N items (cap 5000) |
drive_share_create / _list / _revoke |
Public share-links (raw token returned ONCE) |
drive_file_upload |
High-level: one tool, full flow. Streams local file → returned upload URL(s) → registers as available. Use this by default. |
drive_upload_initiate / _complete / _refresh_parts / _abort |
Low-level multipart upload primitives — for agents that PUT bytes themselves |
drive_addon_get / _pricing / _cancellation_preview |
Drive Storage Add-on (read-only; purchase / resize / cancel are dashboard-only by product decision) |
drive_device_list |
List Drive sync-device passwords (label, scopes, mailbox binding, last-used, expiry, revoked-at; never plaintext) |
drive_device_create |
Mint a new dsync_… credential for rclone / Cyberduck / X-Plore / DAVx⁵ / Documents / FolderSync. Plaintext returned ONCE in data.password. Rate-limited 20/h per account |
drive_device_revoke / _rotate |
Revoke a device password (idempotent) or atomically rotate (revoke old + mint new, inherits label / scopes / mailbox). Both gated by TREKMAIL_ALLOW_DESTRUCTIVE=true. Rotate is rate-limited 10/h per account |
{space} parameters accept "account" (account-drive singleton),
"mailbox:N" (mailbox-personal), or a numeric DriveSpace.id.
Drive scopes light up for any account on a paid plan OR with an
active Drive Storage Add-on (mirrors how verify:* works for the
Email Verifier). Free + addon active is a fully supported path —
mint a token with drive:account:read etc. and it works. When the
addon enters its 7-day post-cancellation grace window, write/share/
purge tokens lose access; read tokens keep working.
Drive API/MCP scopes:
| Scope | Enables |
|---|---|
drive:account:read |
Browse Account Drive, inspect metadata, list folders/trash/share links, and request download URLs |
drive:account:write |
Upload files, create/update/move/trash/restore files and folders in Account Drive |
drive:account:share |
Create and revoke public share links for Account Drive files |
drive:account:purge |
Permanently purge trashed Account Drive files/folders and empty trash |
drive:mailbox:read |
Browse mailbox Drive spaces allowed by token mailbox constraints |
drive:mailbox:write |
Upload and mutate files/folders in allowed mailbox Drive spaces |
drive:mailbox:share |
Create and revoke public share links for allowed mailbox Drive files |
drive:mailbox:purge |
Permanently purge trashed files/folders in allowed mailbox Drive spaces |
drive:addon:read |
Read Drive Storage Add-on status, pricing, and cancellation preview |
Default — drive_file_upload (one tool, all three steps):
drive_file_upload(space="account", local_path="/path/to/report.pdf",
folder_id=42, client_mime="application/pdf")
The wrapper:
drive_upload_initiate.drive_upload_complete to register the file as available.drive_upload_abort to release
the quota reservation. (The reservation is also reclaimed by the
server-side cleanup — abort is a fast path, not a guarantee.)Low-level primitives (drive_upload_initiate etc.) stay available
for agents that want to drive the PUT phase themselves — e.g. uploads
from a remote source instead of the MCP host's filesystem.
Every mutating Drive tool stamps actor_type='api_token' and
api_token_id=<token id> on the audit row, so the dashboard's API
audit tab can filter by token. The mailbox/user context the token
is acting on behalf of is preserved in the existing mailbox_id /
metadata.actor_user_id fields.
# Install dependencies
npm install
# Run in dev mode (tsx, no build required)
TREKMAIL_BASE_URL=https://trekmail.net TREKMAIL_API_TOKEN=tm_live_test npm run dev
# Build
npm run build
# Run tests
npm test
# Watch tests
npm run test:watch
# Type-check only
npm run lint
Выполни в терминале:
claude mcp add trekmail-mcp-server -- npx Безопасность
Низкий рискАвтоматическая эвристика по публичным данным — не гарантия безопасности.