mcp-email-server

mcp-email-server

Connects AI assistants to Microsoft 365 via the Graph API, enabling email search, attachment extraction, and OneDrive file reading through natural conversation.

Category
访问服务器

README

Personal MCP Server - Microsoft 365 + Claude

Connect your AI to everything Microsoft 365 has to offer. Read emails, manage files, query calendars, search across your organization, all through natural conversation in Cowork.

This project is a personal Model Context Protocol (MCP) server that bridges Cowork's agentic AI with the Microsoft Graph API. It runs on Azure, stays online 24/7, and gives your AI real access to your Microsoft 365 workspace not just summaries or previews, but actual data it can reason over, act on, and help you with.

The current implementation focuses on email and OneDrive. The architecture is built to extend to anything Microsoft Graph exposes: Calendar, Teams, SharePoint, Contacts, Planner, and beyond.


Why This Matters

Most people use AI as a chat assistant. They copy-paste emails in, ask questions, copy answers out. It works, but it is slow, manual, and the AI never has full context.

This changes that.

When Cowork is connected to your MCP server, it has direct, live access to your actual data. You stop being a middleman. Instead of you bringing information to the AI, the AI reaches into your systems, finds what it needs, and acts on your behalf.

That shift from assistant to agent is where the real productivity gains are.


What You Can Do Today

The server currently exposes five tools to Cowork:

Email Intelligence Ask Cowork to search your inbox with any combination of filters: sender, date range, keywords, or whether the email has attachments. It reads the full email, not just a snippet.

Attachment Extraction Cowork can download attachments from any email directly into your OneDrive, organized automatically by sender and date. No manual downloading, no digging through folders.

Document Understanding Once a file is in OneDrive, Cowork can open it and read the contents — PDFs, Word documents, Excel spreadsheets, CSVs, images. It extracts the text and reasons over it, so you can ask questions about documents you have not even opened yourself.


Real Scenarios - What This Looks Like in Practice

Scenario 1 - The Weekly Vendor Review A procurement manager receives dozens of invoices every week from different suppliers. Instead of opening each one, downloading attachments, and manually checking figures, they open Cowork and say: "Pull all invoices received this month, download them, and give me a summary of total amounts by vendor." Cowork does it in under a minute. What used to take an hour is done before the first coffee.

Scenario 2 - The Contract Audit A legal team needs to review all contracts signed in Q1. The contracts are scattered across email attachments from multiple senders. A paralegal tells Cowork: "Find all emails from our external counsel between January and March that have PDF attachments, download them, and flag any that mention termination clauses." Cowork searches, downloads, reads each document, and returns a structured report.

Scenario 3 - The Sales Follow-Up A sales representative has been in back-and-forth emails with a prospect for two weeks. Before a big call, they ask Cowork: "Summarize everything exchanged with this prospect, pull any documents they sent, and highlight any commitments we made." Cowork reads the entire thread and the attachments, then gives a clean briefing in seconds.

Scenario 4 - The Executive Briefing A chief of staff needs a Monday morning summary for the executive team. They set up a recurring Cowork task: every Monday at 8am, search all emails from the weekend across key domains, pull any attachments, and generate a structured briefing document. It is waiting in OneDrive before anyone walks into the office.

Scenario 5 - The Compliance Check A compliance officer needs to verify that all required reports were submitted on time. They ask Cowork: "Find every email from our reporting team in the last quarter that contains an Excel attachment, download them all, and confirm the submission dates match our schedule." Cowork cross-references the email timestamps with the file contents and flags any gaps.


Architecture

Your Computer                       Azure (Cloud)
─────────────                       ──────────────────────────────────
Cowork / Claude Desktop             MCP Email Server
  │                                   │
  └── mcp-remote (local proxy) ──────▶│  MCPApp (ASGI)
       HTTPS + X-API-Key              │  ├── /health
                                      │  ├── API key auth
                                      │  ├── Host header normalization
                                      │  └── /mcp (FastMCP)
                                      │       ├── search_emails
                                      │       ├── get_email_details
                                      │       ├── download_attachment_to_onedrive
                                      │       ├── list_onedrive_files
                                      │       └── read_onedrive_file
                                      │
                              ┌───────┴────────┐
                              ▼                ▼
                    Microsoft Graph API     OneDrive
                    (OAuth2 · Mail.Read)    (EmailAttachments/)
                    (Files.ReadWrite.All)

Transport: FastMCP · Streamable HTTP Platform: Azure Container Apps Auth: OAuth2 Client Credentials (Azure AD) + X-API-Key middleware


Connecting to Cowork

Install Node.js from nodejs.org, then open Cowork's developer settings and add:

{
  "mcpServers": {
    "ms-email-server": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://mcp-email-server.thankfulmeadow-426e0542.eastus.azurecontainerapps.io/mcp",
        "--header",
        "X-API-Key:mcp-email-secret-key-2026"
      ]
    }
  }
}

Restart Cowork. The tools will appear automatically.


OneDrive Storage Structure

All downloaded attachments are organized without any manual effort:

OneDrive/
└── EmailAttachments/
    └── sender@company.com/
        └── 2026/
            └── 03/
                └── abc123_invoice.pdf

Extending to the Full Microsoft 365 Surface

The current tools cover email and files. Microsoft Graph exposes far more, and this server is designed to grow. Adding a new capability means writing one function. Some natural extensions:

  • Calendar - let Cowork read your schedule, find free slots, summarize upcoming meetings
  • Teams - search messages, pull files shared in channels
  • SharePoint - query document libraries across your organization
  • Contacts - look up colleagues, enrich email context with org data
  • Planner / Tasks - create and track tasks from email conversations automatically

Each of these follows the same pattern already established here: authenticate once via Azure AD, call the Graph API, return structured data to Cowork.


Deploying Your Own Instance

Prerequisites

  • Azure CLI installed and authenticated via az login
  • An Azure subscription
  • A Microsoft 365 account

1. Register an Azure AD Application

  1. Go to portal.azure.com and open App registrations
  2. Create a new registration, select single-tenant, and copy the Client ID and Tenant ID
  3. Under Certificates and secrets, create a new client secret and copy the value immediately
  4. Under API permissions, add Mail.Read and Files.ReadWrite.All as Application permissions
  5. Click Grant admin consent

2. Activate OneDrive

Sign in to portal.office.com and open OneDrive once to provision your storage.

3. Configure Environment Variables

Copy .env.example to .env and fill in your values:

TENANT_ID=your-azure-tenant-id
CLIENT_ID=your-azure-client-id
CLIENT_SECRET=your-azure-client-secret
USER_EMAIL=your@email.com
API_KEY=choose-a-strong-random-key

4. Verify Access

pip install -r requirements.txt
python test_auth.py

5. Deploy to Azure

az group create --name mcp-email-rg --location eastus
az containerapp env create --name mcp-email-env --resource-group mcp-email-rg --location eastus

az containerapp up \
  --name mcp-email-server \
  --resource-group mcp-email-rg \
  --environment mcp-email-env \
  --source . \
  --ingress external \
  --target-port 8000

az containerapp update \
  --name mcp-email-server \
  --resource-group mcp-email-rg \
  --set-env-vars \
    TENANT_ID="your-tenant-id" \
    CLIENT_ID="your-client-id" \
    CLIENT_SECRET="your-client-secret" \
    USER_EMAIL="your@email.com" \
    API_KEY="your-secret-key"

6. Update Cowork Config

Replace the server URL and API key in your Cowork MCP config with your own Azure deployment URL.


Codebase Overview

File Purpose
main.py ASGI server, request pipeline, all five MCP tools
graph_client.py Microsoft Graph API client, OAuth2 token management
onedrive_client.py OneDrive read and write operations
file_reader.py Text extraction from PDF, Word, Excel, CSV, images
config.py Configuration loaded entirely from environment variables
test_auth.py Validates Graph API credentials and mailbox access
Dockerfile Container definition for Azure deployment

Health Check

curl https://your-server-url.azurecontainerapps.io/health

Expected response: {"status": "ok"}

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选