Skip to main content
Glama
iCloud Relay

iCloud Relay

by naofumi

icloud-relay

Stateless MCP bridge from Grok Bot (Cursor) to iCloud Mail.

Hosted as a Cursor App with Streamable HTTP MCP at:

https://icloud-relay.apps.grok.bot/mcp

The relay never stores mailbox passwords. Clients send an Apple ID and an app-specific password only in connector request headers for that call. A shared relay token gates tools/call. SMTP send is off unless you explicitly enable it.

License: MIT

Features

  • List folders (Unicode NFC/NFD paths)

  • Search with filters, newest-first date order, and cursor pagination

  • Peek-read (decoded text/html; never sets \Seen on read)

  • Mark read/unread

  • Create drafts (plain and/or HTML multipart/alternative)

  • Optional SMTP send (two-step confirm token, 15s delay) when MAIL_SEND_ENABLED=true

Out of scope: push/IDLE, attachment byte download, move/delete, folder admin. Full matrix: docs/FEATURES.md.

Related MCP server: imap-mcp-server

Security model

Control

Behavior

Credentials

Only X-iCloud-Mail-User / X-iCloud-Mail-Password per request — not in app env or this repo

Relay gate

RELAY_ACCESS_TOKEN via X-iCloud-Relay-Token (fail closed)

Client IP

Rate limits use platform x-vercel-forwarded-for only; missing IP is 403 unless local RELAY_ALLOW_INSECURE=1

Concurrency

Per-mailbox, per-IP, and process caps (withMailSlot)

Send

Disabled by default; preview → wait → confirm with HMAC token

Logging

Passwords are never logged or echoed

Treat the public MCP URL like any credentialed proxy: keep the relay token secret, use Apple app-specific passwords, and prefer drafts over send.

Connect from Grok Bot

  1. Add a Remote HTTPS connector to https://icloud-relay.apps.grok.bot/mcp.

  2. Set secure headers in the connector only:

    • X-iCloud-Mail-User — Apple ID email

    • X-iCloud-Mail-Password — app-specific password

    • X-iCloud-Relay-Token — same value as the app secret RELAY_ACCESS_TOKEN

  3. Reconnect and confirm tools load.

Run locally

npm install
npm test
npm run build
npm start

Local server: http://127.0.0.1:3847 (/ status, /health, /mcp).

# Local tool calls without a deployed relay token:
RELAY_ALLOW_INSECURE=1 npm start

# Point IMAP at the FakeImap fixture (see tests):
IMAP_HOST=127.0.0.1 IMAP_PORT=<port> IMAP_SECURE=0

App secrets (Cursor Apps):

Name

Purpose

RELAY_ACCESS_TOKEN

Shared gate for tools/call

MAIL_SEND_ENABLED

Set true only if SMTP send should be allowed

Architecture

Grok Bot  --HTTPS MCP-->  Cursor App (api/mcp.js)
                              |
                         ImapFlow / SMTP  -->  iCloud Mail
  • src/mcp/ — Streamable HTTP JSON-RPC (/mcp)

  • src/mail/ — IMAP, SMTP, MIME compose, sanitize, send-intent

  • src/limits.ts — rate limits and concurrency slots

  • api/ + scripts/build.mjs — Cursor Apps / Vercel-style bundle

  • test/fixtures/fake-imap-server.ts — offline IMAP for unit/E2E

Each /mcp POST is independent (no session store).

Verification (for agents)

  • Drive the real HTTP surface: .cursor/skills/verify-icloud-relay/ (FakeImap + free ports)

  • Formal concurrency caps: .cursor/skills/verify-mail-slots/ — TLA+/TLC model of withMailSlot plus formal/mail-slots/check-code.mjs

  • Invariants and layout: AGENTS.md

node --import tsx .cursor/skills/verify-icloud-relay/bin/verify.mjs launch
node --import tsx .cursor/skills/verify-icloud-relay/bin/verify.mjs drive health-status
node --import tsx .cursor/skills/verify-icloud-relay/bin/verify.mjs cleanup

bash formal/mail-slots/run.sh
node --import tsx formal/mail-slots/check-code.mjs

License

MIT © 2026 Naofumi Kagami

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables local AI agents to search and read iCloud Mail, draft and send reviewed replies, and manage calendar events via a local MCP connection.
      19
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to work with IMAP mail accounts over a Streamable HTTP MCP endpoint, with per-user login-key authentication, isolated account directories, and encrypted (write-only) credential storage behind a self-hosted gateway.
      GPL 3.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to search, read, draft, move and flag mail in self-hosted IMAP mailboxes over MCP Streamable HTTP, protected by OAuth 2.1 with per-client, per-folder and per-operation rules, encrypted credentials and a full audit log. A Go sidecar handles header reads with caching, while structured errors, request ids and verified write outcomes keep unattended operation reliable.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Gives Grok Bot and other MCP clients read and send access to a mailbox over HTTPS when they can't reach mail servers directly. It exposes tools to list folders, search and read messages with their attachments, and optionally send plain-text mail with replies threaded to the original.
      MIT