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 |
Prerequisites (Entra ID / Exchange admin)
-
Register an app in Entra ID and create a client secret.
-
Add the Office 365 Exchange Online → IMAP.AccessAsApp application permission and grant admin consent.
-
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
-
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 every step once against INBOX 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.AccessAsAppcan read every mailbox it has been granted access to. GrantFullAccessonly 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.
.envis 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.1
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 |
|---|---|---|---|---|
| airun_mailbox_mcp-0.1.1.tar.gz | 15.5 kB | Without provenance | Details for airun_mailbox_mcp-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| airun_mailbox_mcp-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for airun_mailbox_mcp-0.1.1-py3-none-any.whl |
Total release size: 31.9 kB
Release files / airun_mailbox_mcp-0.1.1.tar.gz
| Download URL | airun_mailbox_mcp-0.1.1.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
891c56325bd44e7e6dd7e3c01ae8983c9320d04304225575e04d1c23f3b37933
|
|
BLAKE2b-256 checksum How to use checksums |
8fb47e75889c4b28048ba4c97ef60f0c864bf1cf7fe570c752881d8fd294bc59
|
| 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.1-py3-none-any.whl
| Download URL | airun_mailbox_mcp-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80269b2bbbaf7da69a841f7c48aac22ca650b41d32d8ab40649b0cfb04500189
|
|
BLAKE2b-256 checksum How to use checksums |
f281b6b1c01c2dc9ac8be7d82a8cd6db638d174471809dc181de2da4ad6e1eb2
|
| 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.1
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.