outlooklivemcp
by aminkh17
README.md
# outlooklivemcp
A local [Model Context Protocol](https://modelcontextprotocol.io) server that gives an AI
agent access to a **personal Outlook.com / Hotmail / Live mailbox** over Microsoft Graph —
mail, folders, server-side search, drafts, contacts, and sending, with a config-driven
**allowlist of From addresses** and an automatic **signature**.
Works with the Microsoft account you already have. A single signed-in mailbox can send as
any address you allow (for example a personalized domain alias), and several MCP client
sessions share one login through a background daemon.
```text
create_draft → review in Outlook → send_draft (nothing sends without you)
```
## Features
| Area | Tools |
|---|---|
| Accounts | `list_accounts`, `get_my_profile` |
| Mail | `list_mail_folders`, `list_messages`, `search_messages`, `get_message` |
| Drafts | `create_draft`, `update_draft`, `list_drafts`, `send_draft`, `delete_draft` |
| Sending | `send_mail`, `reply_to_message` |
| Mail actions | `move_message`, `mark_message_read`, `delete_message` |
| Contacts | `list_contact_folders`, `list_contacts`, `search_contacts`, `get_contact`, `create_contact`, `update_contact`, `delete_contact` |
- **23 tools**, each accepting an optional `account` id; omit it to use the default account.
- **Drafts for review** — `create_draft` puts a message in the Drafts folder; it is never
sent. Review it in Outlook or with `get_message`, then `send_draft` (which refuses
anything that is not a draft), `update_draft`, or `delete_draft`.
- **Sender allowlist** — `send_mail` and `create_draft` reject any From address outside
the account's configured `senders`, enforced before any network call.
- **Automatic signature** — appended to outgoing mail and replies; opt out per call with
`signature: false`, or change the text in config any time (no restart needed).
- **Shared daemon** — one background process owns the login, so any number of MCP sessions
share it without racing token refreshes.
- Device-code login: no client secret, no redirect URI, no web server.
## Requirements
- Node.js 20 or newer
- A Microsoft account (personal Outlook.com / Hotmail / Live, or a work/school account)
- A Microsoft Entra tenant where you can register an app — see below
## 1. Register an app in Microsoft Entra
The server talks to Microsoft Graph as a **public client** (no secret). You need one app
registration in a tenant you control.
If you don't have a tenant:
- Signing up for a free Azure account at <https://azure.microsoft.com/free> creates a
default directory — that works, no payment needed.
- Any tenant where you can create app registrations is fine.
Then:
1. Open <https://entra.microsoft.com> → **Identity** → **Applications** →
**App registrations** → **New registration**.
2. **Name:** anything you like. Note that Microsoft rejects display names containing
"Outlook" — pick something else, for example `My Mail Bridge`.
3. **Supported account types:** choose
**Accounts in any organizational directory and personal Microsoft accounts**.
This is required for a personal Outlook.com mailbox; a single-tenant app cannot sign
one in.
4. Leave **Redirect URI** empty — device code flow does not need one.
5. Click **Register** and copy the **Application (client) ID** from the Overview page.
6. Go to **Authentication** → set **Allow public client flows** to **Yes** → **Save**.
(If the preview blade does not save, switch to the old experience at the top of the
Authentication page and set it there.)
7. Go to **API permissions** → **Add a permission** → **Microsoft Graph** →
**Delegated permissions**, and add:
- `User.Read`
- `Mail.ReadWrite`
- `Mail.Send`
- `Contacts.ReadWrite`
- `offline_access`
No client secret is needed or wanted. For a personal account you consent as yourself
during login; admin consent is not required.
## 2. Install and build
```bash
git clone https://github.com/aminkh17/outlooklivemcp.git
cd outlooklivemcp
npm install
npm run build
```
## 3. Configure
```bash
node dist/index.js init
```
This writes a template to `~/.outlooklivemcp/config.json`. Edit it and put your
**Application (client) ID** in:
```json
{
"clientId": "YOUR-APPLICATION-CLIENT-ID",
"tenant": "common",
"scopes": [
"offline_access",
"User.Read",
"Mail.ReadWrite",
"Mail.Send",
"Contacts.ReadWrite"
],
"accounts": [
{
"id": "personal",
"label": "My mailbox",
"loginHint": "you@outlook.com",
"senders": ["you@outlook.com"],
"senderNames": { "you@outlook.com": "My Name" },
"signature": "My Name\nexample.com",
"defaultSender": "you@outlook.com"
}
]
}
```
| Key | Meaning |
|---|---|
| `clientId` | Application (client) ID from step 1 |
| `tenant` | `common` for an app that supports personal accounts; `consumers` if you registered personal-accounts-only |
| `accounts[].id` | Short id used in tool calls and token storage |
| `loginHint` | Optional hint shown during login; never sent to Microsoft |
| `senders` | The only addresses this account may send from — a hard allowlist |
| `senderNames` | Optional friendly name per address, used for the From display name |
| `signature` | Appended to every outgoing message; edit any time, no restart |
| `defaultSender` | Used when a tool call omits `from` |
Add more objects under `accounts` for additional mailboxes — each signs in separately and
keeps its own tokens.
### Sending from a custom domain alias
If your Microsoft account has a personalized domain (a grandfathered Outlook.com custom
domain, or an alias added at account.microsoft.com), put that address in `senders`:
```json
"senders": ["you@yourdomain.com"],
"defaultSender": "you@yourdomain.com"
```
The address must belong to the signed-in mailbox. Another person's alias on a shared
domain is **not** sendable from your token — that account must be added as its own entry
under `accounts` and sign in itself.
## 4. Sign in
```bash
node dist/index.js login --account personal
```
Open the printed URL, enter the code, and approve the permissions. Tokens are stored in
`~/.outlooklivemcp/tokens.json` with `0600` permissions and refreshed automatically.
```bash
node dist/index.js accounts # login state per account
node dist/index.js whoami # calls GET /me to confirm
```
## 5. Wire it into your MCP client
**OpenCode** (`~/.config/opencode/opencode.json`):
```json
{
"mcp": {
"outlook": {
"type": "local",
"command": ["node", "/absolute/path/to/outlooklivemcp/dist/index.js", "serve"],
"enabled": true
}
}
}
```
**Claude Desktop** (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"outlook": {
"command": "node",
"args": ["/absolute/path/to/outlooklivemcp/dist/index.js", "serve"]
}
}
}
```
Any MCP client that speaks stdio works. The server logs only to stderr.
## Shared daemon
`dist/index.js` is a thin stdio proxy. The first tool call starts a detached daemon
(`dist/daemon.js`) that owns the token store, and every session talks to it over
`~/.outlooklivemcp/daemon.sock`.
- The daemon starts automatically on demand; there is only ever one.
- One process refreshes tokens, so several MCP sessions can share one login safely.
- `config.json` is reloaded on every request — changing `senders`, `senderNames`, or
`signature` takes effect immediately, no restart.
- After 10 minutes idle it exits and restarts on the next call.
- Logs go to `~/.outlooklivemcp/daemon.log` (rotated at 5 MB). The socket is mode `0600`.
```bash
node dist/index.js status # health, pid, uptime, signed-in accounts
node dist/index.js stop-daemon # stop it; it restarts on demand
npm run daemon # run it in the foreground for debugging
```
## CLI
```
outlooklivemcp [serve] Start the MCP server on stdio (default)
outlooklivemcp init [--force] Write a template config file
outlooklivemcp login [--account id] Sign in with the device-code flow
outlooklivemcp logout [--account id] Remove stored tokens for an account
outlooklivemcp accounts Show configured accounts and login state
outlooklivemcp whoami [--account id] Call GET /me and print the profile
outlooklivemcp config Show resolved config and token paths
outlooklivemcp status Show daemon health
outlooklivemcp stop-daemon Stop the shared daemon
outlooklivemcp help Show this help
```
## Environment variables
| Variable | Purpose |
|---|---|
| `OUTLOOKLIVEMCP_HOME` | State directory (default `~/.outlooklivemcp`) |
| `OUTLOOKLIVEMCP_CONFIG` | Config file path |
| `OUTLOOKLIVEMCP_CLIENT_ID` | Override the app client id |
| `OUTLOOKLIVEMCP_TENANT` | Override the OAuth tenant |
| `OUTLOOKLIVEMCP_IDLE_TIMEOUT` | Daemon idle timeout in seconds |
| `OUTLOOKLIVEMCP_DEBUG=1` | Verbose logging to stderr |
## Notes on Outlook.com personal accounts
Learned the hard way, and worth knowing before you fight deliverability:
- **The From display name is account-wide.** Outlook.com consumer accounts stamp outgoing
mail with the profile display name and ignore any name set on the message. You cannot
have a different From name per alias — verified across `from.name`, `sender.name`, and
`replyTo` variants, and `PATCH /me` returns 405 for consumer accounts. The signature is
therefore the reliable way to brand mail from an alias. (Work/school accounts honour
`senderNames` in this server's config.)
- **DKIM is not available on consumer personalized domains.** Microsoft generates DKIM
keys only for domains added to a Microsoft 365 / Exchange Online tenant. The consumer
personalized-domain platform neither signs your mail nor exposes selectors to publish.
The only route is moving the domain into a tenant.
- **DMARC you can do, and it passes on SPF alone.** Because a personalized domain's
`Return-Path` matches its `From` and its SPF authorises Outlook, publishing
`_dmarc.<domain> TXT "v=DMARC1; p=none; rua=mailto:you@<domain>; fo=1"` at your DNS
host is enough to satisfy DMARC. Start with `p=none` (monitoring only).
## Security notes
- Tokens live in `~/.outlooklivemcp/tokens.json`, mode `0600`. Treat that file like a
password.
- The sender allowlist is enforced in code before any network call.
- `send_draft` refuses any message whose `isDraft` flag is false, so it cannot re-send
mail from another folder.
- The server never logs message bodies or tokens.
- The daemon socket is a Unix socket with mode `0600`, so only your user can connect.
- All logs go to stderr; stdout is reserved for MCP JSON-RPC.
- To revoke access, remove the app at <https://account.live.com/consent/Manage> and delete
the token file.
## Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| `AADSTS700016` / `AADSTS50059` | App is single-tenant, or wrong tenant | Set supported account types to include personal accounts; use `tenant: "common"` |
| `AADSTS7000218` | Public client flow disabled | Authentication → Allow public client flows → Yes |
| `403 ErrorAccessDenied` on mail | Missing consent | Re-run `login` and accept all scopes |
| `invalid_grant` on refresh | Refresh token expired or revoked | `outlooklivemcp login --account <id>` |
| `Account "x" is not signed in` | No token yet | `outlooklivemcp login --account x` |
| `"..." is not an allowed sender` | `from` not in config | Add it to `senders` for that account |
| `Could not find a property named 'notes'` style Graph errors | Wrong property name | Contact notes map to Graph's `personalNotes` |
| Name on sent mail is your account name, not your config name | Outlook.com consumer behaviour | See the platform notes above; use the signature |
| `550 5.7.520 ... AS(4810)` on send | Microsoft's outbound content filter, not the recipient | Resend as plain text without marketing styling, links, or emoji; do not retry the identical message |
## Development
```bash
npm run build # compile to dist/
npm run typecheck
npm run smoke # start the server, list tools, check config validation
npm run daemon # run the daemon in the foreground
```
`scripts/smoke.mjs` starts the server over stdio and lists every tool without touching
Graph. `scripts/livetest.mjs` and `scripts/drafttest.mjs` exercise live Graph calls and
need a signed-in account.
## Acknowledgements
Architecture modelled on a shared-daemon pattern: a thin stdio proxy per MCP session and
one background daemon that owns the credentials.
## Support
If this project saves you time, you can buy me a coffee:
☕️ **<https://buymeacoffee.com/amin17>**
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues