# Outlook MCP Starter

A small, independent Python MCP server for a single user's Microsoft-hosted Outlook mailbox. It connects an MCP client to Microsoft Graph through the official MCP Python SDK and Microsoft Authentication Library (MSAL).

**Status:** source starter, checked with offline unit tests and real local MCP protocol discovery. Microsoft sign-in and live mailbox operations still need to be tested with your own account. No Microsoft account is connected in this package.

[Read the illustrated guide](https://shefaahsan.com/blog/build-outlook-mcp-server/) · [Guide source](docs/outlook-mcp-guide.md)

## Included tools

| Tool | Purpose | Default |
| --- | --- | --- |
| `outlook_list_messages` | Read a first page from Inbox or another known folder; optionally unread only | Enabled |
| `outlook_search_messages` | Search by a Graph search expression, such as `from:person@example.com` | Enabled |
| `outlook_get_message` | Read one message by ID, including body and reply-to information | Enabled |
| `outlook_create_draft` | Save a new plain-text draft | Opt-in |
| `outlook_create_reply_draft` | Save a reply draft to an existing message | Opt-in |

The host AI summarizes the returned text and composes suggested replies. The MCP server supplies the mailbox access. This starter has no sending, deleting, attachment download, calendar, category-editing, or shared-mailbox tools.

Read tools request delegated `Mail.Read`. Draft mode requests delegated `Mail.ReadWrite` instead. Microsoft defines that write permission more broadly than drafts, although this server exposes only draft creation. `Mail.Send` is not requested. [Microsoft permission definitions](https://learn.microsoft.com/en-us/graph/permissions-reference#mailreadwrite)

## Requirements

- Python 3.11 or newer, on a computer with a browser.
- An Outlook.com/Hotmail or Microsoft 365 mailbox.
- Permission to register a Microsoft Entra application or an application registration supplied by your administrator.
- An available OS credential store: Windows DPAPI, macOS Keychain, or an unlocked Linux Secret Service/libsecret session.

The mailbox must be hosted by Microsoft. Merely opening a Gmail or other IMAP account in the Outlook app does not make it accessible through these Microsoft Graph tools. Sovereign Microsoft clouds are outside this starter's scope. [Outlook mail API overview](https://learn.microsoft.com/en-us/graph/outlook-mail-concept-overview)

## 1. Register a Microsoft application

In Microsoft Entra admin center, open App registrations and create an app for this starter.

1. Choose the supported account audience. For a personal Outlook.com account, the registration must include personal Microsoft accounts. For an organization's own use, prefer that organization's tenant and policy.
2. In Authentication, add the **Mobile and desktop applications** platform with redirect URI **`http://localhost`**.
3. In API permissions, add Microsoft Graph **delegated** permission `Mail.Read`.
4. Copy the application's **Application (client) ID** into the local configuration below. This identifier is not a password.
5. Complete any consent required by your organization. This local public-client flow does not use a client secret.

The registration's audience and configured authority must agree. Use `common` for an app registered for work/school and personal accounts, `consumers` for personal accounts, or your tenant UUID for a single organization.

Sources: [Microsoft account audiences](https://learn.microsoft.com/en-us/entra/identity-platform/single-and-multi-tenant-apps), [MSAL interactive sign-in and PKCE](https://learn.microsoft.com/en-us/entra/msal/python/getting-started/acquiring-tokens#interactive-acquire-token), [PublicClientApplication](https://learn.microsoft.com/en-us/python/api/msal/msal.application.publicclientapplication).

## 2. Install locally

Clone this repository with Git, or [download the source ZIP](https://shefaahsan.com/downloads/outlook-mcp-starter.zip) and extract it. Open a terminal in the project folder.

```bash
git clone https://github.com/shifawrites6-ai/outlook-mcp-starter.git
cd outlook-mcp-starter
```

### Windows PowerShell

```powershell
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .
Copy-Item config.example.json config.json
```

### macOS or Linux

```bash
python3 -m venv .venv
.venv/bin/python -m pip install -e .
cp config.example.json config.json
```

Edit `config.json`:

```json
{
  "client_id": "YOUR_APPLICATION_CLIENT_UUID",
  "tenant_id": "common",
  "enable_drafts": false
}
```

The MCP SDK is deliberately pinned to the tested v1.29 maintenance release. Moving to SDK v2 requires a separate migration and test pass. [SDK maintenance documentation](https://py.sdk.modelcontextprotocol.io/v1/)

## 3. Sign in

On Windows:

```powershell
.\.venv\Scripts\python.exe -m outlook_mcp login --config config.json
```

On macOS or Linux:

```bash
.venv/bin/python -m outlook_mcp login --config config.json
```

Sign in on the Microsoft page using the intended mailbox account. Tokens are kept in an encrypted local MSAL cache, separate for each client ID, tenant, and read/draft mode. The server never opens a sign-in prompt during a tool call; use this local command again when authorization needs renewal. Run under the same OS account and credential-store session as your MCP host.

If encrypted storage cannot initialize, setup stops. On a Linux server without an unlocked desktop keyring, this starter needs a different, reviewed secret-storage deployment rather than a plaintext cache fallback. [Microsoft's encrypted persistence library](https://github.com/AzureAD/microsoft-authentication-extensions-for-python)

## 4. Connect a local MCP client

The server speaks **stdio**. Use an absolute Python executable and an absolute config path. For a client that accepts an `mcpServers` JSON configuration, a Windows example is:

```json
{
  "mcpServers": {
    "outlook": {
      "command": "C:/path/to/outlook-mcp-starter/.venv/Scripts/python.exe",
      "args": ["-m", "outlook_mcp", "serve", "--config", "C:/path/to/outlook-mcp-starter/config.json"]
    }
  }
}
```

On macOS/Linux, use `/absolute/path/to/outlook-mcp-starter/.venv/bin/python` and the corresponding config path. Client configuration formats vary. The example is not a JSON file you can upload directly into ChatGPT.

Suggested first requests:

- “Show my latest 10 inbox messages.”
- “Find emails from person@example.com.”
- “Read the message I select and summarize what needs a reply.”

## 5. Enable draft creation when needed

Set `enable_drafts` to `true`, add the Microsoft Graph delegated `Mail.ReadWrite` permission to the app registration, and run `login` again. The separate draft-mode cache requires a new sign-in. Restart the MCP server and refresh tool discovery.

Two draft tools now appear. A draft call saves a draft in Outlook; it does not send it. Read the source message and inspect recipients before requesting a reply draft. Microsoft determines the reply recipient from the original message's reply-to/from fields. Repeating a draft call can create duplicates. [Create draft](https://learn.microsoft.com/en-us/graph/api/user-post-messages?view=graph-rest-1.0), [Create reply draft](https://learn.microsoft.com/en-us/graph/api/message-createreply?view=graph-rest-1.0)

## Connect to ChatGPT

For this private local starter, a **Secure MCP Tunnel** can bridge its stdio process to ChatGPT. This requires a running tunnel client, a Platform tunnel ID, a runtime API key, appropriate tunnel permissions, and matching ChatGPT custom-MCP access. It is not connected automatically by downloading this package.

In the supported web interface, use **Plugins → + → Add custom MCP server → Tunnel**. Keep any tunnel connection limited to the owner of this signed-in mailbox: this starter is single-user and has no per-caller authorization layer for shared use.

Current OpenAI documentation lists full custom-MCP support for Business and Enterprise/Edu, and custom read/fetch access for Pro. Verify the options shown in the intended account before setting up hosting or a tunnel.

Sources: [Custom MCP access](https://help.openai.com/en/articles/12584461-connecting-custom-mcp-servers-in-chatgpt), [Secure MCP Tunnel](https://developers.openai.com/api/docs/guides/secure-mcp-tunnels).

## Limits and validation

List/search tools return a bounded first page of up to 50 items. `has_more` and `pagination_supported: false` explicitly describe incomplete results; no mailbox-wide completeness claim is appropriate. Message bodies are capped at 20,000 characters, with truncation metadata. A single response is capped at 2 MiB.

The client blocks HTTP redirects and uses a fixed Microsoft Graph origin. It makes no automatic retries. If Microsoft does not confirm whether a draft was created, inspect Outlook Drafts before repeating the request. Email content is untrusted data, not instructions to execute tools.

Run offline tests with your virtual-environment Python:

```bash
python -m unittest discover -s tests -v
```

The tests use synthetic data and mock Graph responses, plus a real stdio MCP handshake and tool discovery. They do not prove that a specific tenant permits sign-in or that a live mailbox operation succeeds.

## Public sharing

See **PUBLIC_SHARING.md** for source distribution, a hosted multiuser service, and public plugin submission. The included MIT license covers this project's source. Dependencies retain their own licenses. This is an independent project, not an official Microsoft or OpenAI product.
