Skip to main content

airun-mailbox-mcp

A read-only Model Context Protocol server that lets AI assistants (Claude Code, Claude Desktop, any MCP client) read an Exchange Online mailbox. It authenticates as an Entra ID application (OAuth client credentials) and talks to Exchange Online over IMAP with XOAUTH2, so no user sign-in is needed.

Folders are opened with EXAMINE and messages are fetched with BODY.PEEK, so the server never changes the mailbox: it doesn't mark messages as read, move them or delete them.

Tools

Tool Purpose
list_folders All folders (Inbox, Sent Items, subfolders, ...)
list_messages(folder, limit, offset, unread_only) Header summaries, newest first, with paging (up to 50 per call)
search_messages(folder, text, sender, recipient, subject, body, since, before, unread_only, limit) IMAP SEARCH; dates are YYYY-MM-DD; non-ASCII text is supported
get_message(uid, folder, max_chars) Headers, readable body (HTML is converted to text) and the attachment list
diagnose() Checks config, DNS, ports 443/993, the token request and the IMAP login; returns a report with a hint (never fails)

Prerequisites (Entra ID / Exchange admin)

  1. Register an app in Entra ID and create a client secret.

  2. Add the Office 365 Exchange Online → IMAP.AccessAsApp application permission and grant admin consent.

  3. In Exchange Online PowerShell, register the app's service principal and give it access to the mailbox:

    New-ServicePrincipal -AppId <CLIENT_ID> -ObjectId <ENTERPRISE_APP_OBJECT_ID>
    Add-MailboxPermission -Identity <MAILBOX_UPN> -User <ENTERPRISE_APP_OBJECT_ID> -AccessRights FullAccess
    
  4. Make sure IMAP is enabled for that mailbox.

See Microsoft's guide: Authenticate an IMAP, POP or SMTP connection using OAuth.

Configuration

Variable Description
TENANT_ID Entra ID tenant (directory) ID
CLIENT_ID Application (client) ID
CLIENT_SECRET Client secret value
MAILBOX_UPN Mailbox to read, e.g. support@example.com

Install and run

uvx airun-mailbox-mcp              # run without installing (recommended)
pip install airun-mailbox-mcp      # or install into an environment
airun-mailbox-mcp --transport streamable-http --port 8000   # HTTP at http://127.0.0.1:8000/mcp

stdio is the default transport. The streamable-http transport has no authentication, so bind it only to localhost or put it behind an authenticating proxy.

Claude Code

claude mcp add airun-mailbox --scope user \
  -e TENANT_ID=... -e CLIENT_ID=... -e CLIENT_SECRET=... -e MAILBOX_UPN=... \
  -- uvx airun-mailbox-mcp

To keep the secret out of ~/.claude.json, store the variables in a chmod 600 env file (see .env.example) and use -- uvx --env-file /path/to/.env airun-mailbox-mcp instead.

Claude Desktop / other MCP clients

{
  "mcpServers": {
    "airun-mailbox": {
      "command": "uvx",
      "args": ["airun-mailbox-mcp"],
      "env": {
        "TENANT_ID": "...",
        "CLIENT_ID": "...",
        "CLIENT_SECRET": "...",
        "MAILBOX_UPN": "support@example.com"
      }
    }
  }
}

Command-line helper

airun-fetch-messages [--mailbox UPN] [--limit 1-10] prints the newest Inbox messages as JSON. You can use it to check the credentials before you set up an MCP client.

Logging and troubleshooting

Logs go to stderr (stdout carries the MCP protocol). Each tool call logs its arguments, every network step (DNS, IMAP connect, token request, login, folder open, search, fetch) with its duration, and the result or error. Secrets and tokens are never logged.

Option Env variable Default Purpose
--log-level DEBUG AIRUN_LOG_LEVEL INFO DEBUG also logs when each step starts, so you can see where a hang begins
--log-file PATH AIRUN_LOG_FILE – Also append logs to a file (useful when the MCP host hides stderr)
– AIRUN_IMAP_TIMEOUT 20 Seconds per IMAP socket operation
– AIRUN_TOKEN_TIMEOUT 15 Seconds for the token request
– AIRUN_LOG_MCP=1 off Include the MCP SDK's DEBUG logs, which contain full JSON-RPC messages including email content

Test connectivity from the machine or container that runs the server:

airun-mailbox-mcp --check --log-level DEBUG

It runs the same checks as the diagnose tool, prints the JSON report and exits with code 0 on success. A timeout shows up as a tool error naming the step that failed (for example network timeout during 'imap connect'). This usually means outbound TCP to outlook.office365.com:993 is blocked. IMAP does not use HTTPS_PROXY.

Security notes

  • An app with IMAP.AccessAsApp can read every mailbox it has been granted access to. Grant FullAccess only on the mailboxes you need.
  • Email content is untrusted input. The server tells clients not to follow instructions found in messages, but treat what the model reads with care.
  • Never commit secrets. .env is ignored by git and is not included in the package.

Development

uv sync
uv run pytest
uv build

License

MIT

Metadata

Release files for airun-mailbox-mcp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airun-mailbox-mcp 0.1.2
File Size Uploaded Provenance Actions
airun_mailbox_mcp-0.1.2.tar.gz 17.3 kB Without provenance Details for airun_mailbox_mcp-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for airun-mailbox-mcp 0.1.2
File Interpreter ABI Platform Actions
airun_mailbox_mcp-0.1.2-py3-none-any.whl Python 3 none any Details for airun_mailbox_mcp-0.1.2-py3-none-any.whl

Total release size: 35.4 kB

Release files / airun_mailbox_mcp-0.1.2.tar.gz

Download URL airun_mailbox_mcp-0.1.2.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a8ed64dfd3b6d289ea964563b024c4205d4eadfc6cebff1d37d22f5ce3987ae8
BLAKE2b-256 checksum
How to use checksums
244ade6f6849976dccd8718423297fcd101f5713c9fdc7dd73f9909e945b25af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / airun_mailbox_mcp-0.1.2-py3-none-any.whl

Download URL airun_mailbox_mcp-0.1.2-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b68aa54e1476d95e25e6be63c5ffcdf762ba87aeb0833a5f8c9bde1b5aa6b7cb
BLAKE2b-256 checksum
How to use checksums
9024f5f10b94adfbd550b1bdfdd52d7351b3006852fbc0467930916461981f1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for airun-mailbox-mcp 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page