imap-mcp
A security-focused Model Context Protocol server (sc-imap-mcp
3.0.0, tool_set_version: "3.0.0") that mediates LLM agent access
to IMAP mailboxes under strict message-centric authorization,
non-interference, flow monotonicity, cryptographic draft provenance, and
tamper-evident hash-chained auditing.
Security boundary & deployment posture
Important (LIM 0019, ADR 0051):
imap-mcpenforces policy strictly across the MCP protocol and attachment-sink boundaries. However, if you runimap-mcpover localstdiounder the same OS user as a CLI agent that has unrestricted host shell or file-write permissions, that agent can edit~/.config/imap-mcp/policies/*.yamldirectly on disk.
- Adversarial / production sandbox: Run
imap-mcpunder a dedicated OS user or as a loopback Kubernetes sidecar container with read-only/config,/secrets, and/sinkmounts (guide).- Workstation convenience (
stdio): Restrict shell/file-edit access to~/.config/imap-mcpin your agent harness.
Quick start
# Install via pipx (isolated environment, global CLI)
pipx install "sc-imap-mcp[tracing]"
# Or from local source
pipx install --force "./server[tracing]"
Configure (~/.config/imap-mcp)
Each server instance serves strictly one configured caller in
callers.yaml (ADR 0049):
~/.config/imap-mcp/
├── accounts.yaml # IMAP accounts, secret_store, audit, wal, attachment_sink
├── callers.yaml # Exactly ONE caller entry per instance
└── policies/
└── my-policy.yaml # Message-centric folder & rule grants
accounts.yaml
accounts:
- id: user@company.com
provider: google # or "imap-standard"
host: imap.gmail.com
port: 993 # 993 = implicit TLS (IMAP4_SSL)
auth:
type: xoauth2 # or "password"
secret_ref: secret://accounts/user@company.com/refresh_token
oauth_scope: https://mail.google.com/
token_cache: persist_all # or "memory_only"
- id: accounting@company.com
provider: imap-standard
host: imap.company.com
port: 993
user: mail2223 # optional explicit IMAP login username
auth:
type: password
secret_ref: secret://accounts/accounting@company.com/password
secret_store:
backend: file_dir # "file_dir", "env_var", or "gpg_file"
path: ~/.config/imap-mcp/secrets
acknowledge_plaintext: true # required for file_dir (ADR 0050)
audit:
directory: ~/.config/imap-mcp/audit
hot_days: 90
delete_after_days: 365
wal:
path: ~/.config/imap-mcp/wal.db
attachment_sink:
directory: ~/Desktop/tmp/imap-mcp-outdir
Note on Gmail / M365 OAuth scopes (ADR 0050): Google IMAP (
https://mail.google.com/) and Microsoft 365 IMAP do not offer a read-only IMAP OAuth scope. On those providers, theimap-mcppolicy is your sole read/write authorization boundary.
callers.yaml
callers:
- id: my-agent
policy: my-policy
auth:
type: stdio_trusted # stdio only; HTTP requires shared_token
policies/my-policy.yaml
name: my-policy
accounts:
user@company.com:
- path: INBOX
mode: whitelist
default: NONE
mark_seen: true
move_out: true
rules:
- match: { flagged: true }
grant: FULL
- match: { from_domain: hornbach.de }
grant: FULL
- path: "[Gmail]/Sent Mail"
mode: whitelist
default: NONE
rules:
- match: { flagged: true }
grant: FULL
- match: { provenance: own }
grant: FULL
- match: { to_domain: hornbach.de }
grant: FULL
- path: "[Gmail]/Drafts"
mode: blacklist
default: FULL
draft_append: true
draft_edit: true
move_out: true
draft_recipients:
allowed_domains: [company.com, hornbach.de]
rules: []
- path: "[Gmail]/Trash"
mode: blacklist
default: METADATA
accept_incoming: true
rules: []
Policy model (3.0.0)
Linear visibility levels (ADR 0002, ADR 0043)
NONE < COUNT < METADATA < ENVELOPE < HEADERS < BODY < FULL
NONEis strictly non-interfering: Hidden accounts, folders, andNONEmessages never alter any caller-visible count, pagination field, or error type (not_foundis returned identically for missing, foreign, and< METADATAobjects; ADR 0044).- Gmail multi-label composition (ADR 0040):
Account-wide
blacklistcaprules apply across all folders, and[Gmail]/All Mailor[Gmail]/Starrednever escalate visibility above a message's specific labels.
Closed predicate grammar (ADR 0041)
| Predicate | Min criteria floor |
Matches |
|---|---|---|
from_address / from_domain |
ENVELOPE |
Exact parsed From: addr-spec or DNS/IDNA domain |
to_address / to_domain |
ENVELOPE |
Any parsed To: addr-spec or exact domain |
cc_address / cc_domain |
ENVELOPE |
Any parsed Cc: addr-spec or exact domain |
recipient_address / recipient_domain |
ENVELOPE |
Any parsed To:, Cc:, or Bcc: address/domain |
all_recipients_in_domains |
ENVELOPE |
Non-empty recipients and every recipient in domain list |
subject_contains |
ENVELOPE |
Case-folded Unicode-NFC substring in decoded Subject: |
has_attachment |
BODY |
At least one MIME attachment part (ADR 0047) |
flagged |
METADATA |
IMAP \Flagged star (read-only to agents; human curation signal) |
provenance: "own" |
METADATA |
Authentic message/draft authored by this caller_id (ADR 0042) |
newer_than / older_than |
METADATA |
INTERNALDATE age (1s..36500d / 100y) |
since / before |
METADATA |
INTERNALDATE UTC calendar bounds (YYYY-MM-DD) |
size_gt / size_lt |
METADATA |
RFC822 size in bytes (1..1073741824) |
Folder write capabilities & invariants (ADR 0045)
| Capability | Governing tools | Per-message read floor & invariant |
|---|---|---|
mark_seen |
mark_seen, bulk_mark_seen |
eff_vis >= METADATA |
mark_tagged |
mark_tagged, bulk_mark_tagged |
eff_vis >= ENVELOPE; user keywords only (\Flagged and all \-system flags forbidden) |
move_out |
move, discard_draft |
eff_src >= ENVELOPE and eff_dst <= eff_src (relocation_would_escalate otherwise) |
copy_out |
copy |
eff_src >= ENVELOPE and eff_dst <= eff_src |
accept_incoming |
target of move, copy, discard_draft |
Destination folder must grant accept_incoming: true |
draft_append |
create_draft, create_reply_draft |
\Drafts folder only; reply requires source eff_vis >= BODY; enforces draft_recipients |
draft_edit |
update_draft |
\Drafts folder + verified X-SC-Provenance ownership; enforces draft_recipients |
MCP Tool Surface 3.0.0 (27 tools)
Read tools (13)
list_accounts, list_folders, list_labels (Google), folder_stats,
search, list_messages, fetch_envelope, fetch_headers,
fetch_body, list_attachments, fetch_attachment, list_drafts,
get_draft.
Write tools (10)
mark_seen, bulk_mark_seen, mark_tagged, bulk_mark_tagged, move,
copy, create_draft, create_reply_draft, update_draft,
discard_draft.
Meta tools (4)
describe_policy, get_caller_identity, get_transaction_status,
tool_surface_info.
Upgrading from 2.x to 3.0.0
- Retired tools & capabilities:
add_attachment,replace_attachment,delete_attachment, andmodify_messageare removed (ADR 0045, ADR 0052). Pass structuredattachmentstocreate_draftorupdate_draftfor own drafts. Addcopy_out: trueon folders from whichcopyis allowed. - Predicate keys: Replace
from:withfrom_address:,to:withto_address:(orrecipient_address:), andto_contains:with exactto_domain:/recipient_domain:(ADR 0041). - Secret store & single caller: Add
acknowledge_plaintext: trueundersecret_storewhen usingfile_dir(ADR 0050), and keep exactly one caller entry percallers.yaml(ADR 0049). - Non-interfering responses:
matched_total,filtered_out,outside_scope_total,hidden_*_count,canonical_all_mail_uid,matched_rule_index, andlist_folders.message_countare replaced bytotal_visible,returned_count, staticcompleteness, and Gmailobject_id(ADR 0040, ADR 0043). - Per-caller read-only attachment delivery:
fetch_attachmentwrites<sink>/<caller_id>/<uuid4_hex>_<name>.<ext>(0400) viaopenat+O_NOFOLLOW | O_EXCLand returnssaved_to+saved_path(ADR 0047). Clean aged artifacts periodically viasystemd-tmpfilesorfind <sink> -type f -mtime +30 -delete(LIM 0015).
OAuth2 bootstrap & remediation
Run imap-mcp-oauth-bootstrap interactively on a workstation to mint a
refresh token (or clear a persisted needs_rebootstrap state after
invalid_grant, ADR 0059, ADR 0064):
IMAP_MCP_CONFIG_DIR=~/.config/imap-mcp \
IMAP_MCP_OAUTH_CLIENT_ID=your-client-id.apps.googleusercontent.com \
IMAP_MCP_OAUTH_CLIENT_SECRET=your-client-secret \
imap-mcp-oauth-bootstrap --account user@company.com
Environment variables
| Variable | Required | Description |
|---|---|---|
IMAP_MCP_CONFIG_DIR |
yes | Path to the configuration directory |
IMAP_MCP_CALLER_ID |
stdio_trusted |
Caller identity for stdio transport |
IMAP_MCP_OAUTH_CLIENT_ID |
xoauth2 |
OAuth2 client ID |
IMAP_MCP_OAUTH_CLIENT_SECRET |
xoauth2 |
OAuth2 client secret |
IMAP_MCP_SERVER_HMAC_KEY |
env_var store |
64-hex-char HMAC key when using read-only env_var secret store |
IMAP_MCP_APPEND_TIMEOUT |
no | Seconds to wait for a tagged IMAP APPEND response before append_timeout (default: 30) |
IMAP_MCP_POOL_MAX_SIZE |
no | Pooled IMAP connections per account per process (default: 2, ADR 0055) |
IMAP_MCP_POOL_IDLE_TTL |
no | Idle connection TTL in seconds (default: 120) |
IMAP_MCP_POOL_MAX_AGE |
no | Maximum connection age in seconds (default: 1800) |
IMAP_MCP_POOL_ACQUIRE_TIMEOUT |
no | Seconds to wait before pool_exhausted (default: 30) |
OTEL_EXPORTER_OTLP_ENDPOINT |
no | OTLP collector endpoint (e.g. http://localhost:4317) |
OTEL_RESOURCE_ATTRIBUTES |
no | Extra OTel resource attributes |
IMAP_MCP_TRACE_PAYLOADS |
no | off, redacted (default), or full (ADR 0053) |
IMAP_MCP_TRACE_PAYLOAD_MAX_CHARS |
no | Max chars per payload in full mode (default: 16384) |
Documentation
- ADRs (65 records,
0000–0064):docs/adr/README.md - Limitation Records (
0001–0024):docs/limitations/README.md - Closed Code Registry:
docs/contract/registry.yaml(ADR 0062) - Error-Path Analysis:
docs/error_path_analysis.md - Spec-Audit Archive:
docs/spec-audit/ - Roadmap:
docs/ROADMAP.md - Operations:
docs/ops/kubernetes-sidecar-deployment.md,docs/ops/arc-runner-setup.md
License
GPL-3.0-or-later. See LICENSE.
Metadata
Release files for sc-imap-mcp 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sc_imap_mcp-3.0.0.tar.gz | 147.5 kB | With provenance | Details for sc_imap_mcp-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sc_imap_mcp-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for sc_imap_mcp-3.0.0-py3-none-any.whl |
Total release size: 277.8 kB
Release files / sc_imap_mcp-3.0.0.tar.gz
| Download URL | sc_imap_mcp-3.0.0.tar.gz |
|---|---|
| Size | 147.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21e66d1f1a3cfe6e4689277229424fabcebf1c81d12b3f352a3db14710608979
|
|
BLAKE2b-256 checksum How to use checksums |
0e339593c0c8c71087de667994c6b52853b994c4f87d498ad347b5c573ee0160
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / sc_imap_mcp-3.0.0-py3-none-any.whl
| Download URL | sc_imap_mcp-3.0.0-py3-none-any.whl |
|---|---|
| Size | 130.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0284874361c686505a00a9afd3d31d71eb46162f6485b902a6359be06a6b17f7
|
|
BLAKE2b-256 checksum How to use checksums |
1204afa41351ed56715fc1bd3bb218fdaed18e795eea6b8ce4134b2c6655aa19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for sc-imap-mcp 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sc_imap_mcp-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.