Outlook Email MCP Server
This server integrates Microsoft 365/Outlook email and SharePoint Excel capabilities into Claude Desktop via the Microsoft Graph API, enabling the following:
Authentication & Session Management
auth_login– Start login using Device Code Flowauth_confirm– Complete login after browser authenticationauth_status– Check current login statusauth_logout– Log out and clear saved tokens
Reading & Searching Emails
list_emails– List emails in a folder (inbox, drafts, sent, deleted, junk, archive, or custom) with a configurable limitread_email– Read the full content of an email by ID, with an option to mark it as readsearch_emails– Search emails by keyword (KQL), sender, subject, unread status, or attachment presence
Drafts Management
create_draft– Create a new draft with recipients (To/CC/BCC), subject, body, and importancelist_drafts– List all existing draftsupdate_draft– Update a draft's subject, body, or recipientsdelete_draft– Permanently delete a draftsend_draft– Send an existing draft
Sending Emails
send_email– Compose and send an email immediately (plain text or HTML), without saving as a draft
Email Management
mark_email_as_read– Mark an email as read or unread
Attachments
list_attachments– List all attachments for a given emailread_attachment– Read attachment content; supports txt, csv, json, html, xml, md, xlsx, pdf, and docx formats
SharePoint Integration
read_sharepoint_excel– Read an Excel (.xlsx) file from a SharePoint Online URL, with options for sheet name and max rows
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Outlook Email MCP Server List my unread emails from inbox"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Outlook Email MCP Server
MCP Server cho Claude Desktop để đọc và quản lý email Microsoft 365 / Outlook qua Microsoft Graph API.
Tính năng
Tool | Mô tả |
| Bắt đầu đăng nhập — trả về URL và mã xác thực |
| Hoàn tất đăng nhập sau khi xác thực trong browser |
| Kiểm tra trạng thái đăng nhập hiện tại |
| Đăng xuất, xóa token đã lưu |
| Liệt kê email theo folder |
| Đọc nội dung đầy đủ một email |
| Tìm kiếm email với nhiều điều kiện |
| Tạo email nháp mới |
| Liệt kê tất cả email nháp |
| Sửa nội dung email nháp |
| Xóa email nháp |
| Gửi email nháp đã tạo |
| Soạn và gửi email ngay |
| Đánh dấu email đã đọc / chưa đọc |
| Liệt kê file đính kèm của một email |
| Đọc nội dung file đính kèm (text/xlsx/pdf/docx/ảnh) |
| Đọc nội dung file Excel từ SharePoint Online |
| Đọc file Excel từ SharePoint, chỉ lấy các dòng khớp filter |
Related MCP server: outlook-mcp
Yêu cầu
Python 3.11 trở lên (nếu dùng
uvở Bước 3 - Cách 1, không cần cài Python trước —uvtự tải)Tài khoản Microsoft 365 hoặc Outlook.com
Quyền truy cập Azure Portal (để đăng ký app)
Hướng dẫn cài đặt
Bước 1: Tải source code
Tải hoặc clone repo này về máy, ví dụ vào thư mục:
C:\Projects\mcp-server\Ghi nhớ đường dẫn này — bạn sẽ dùng ở Bước 4.
Bước 2: Đăng ký Azure App
Bước này chỉ làm một lần duy nhất. Nếu đã có
AZURE_CLIENT_ID, bỏ qua.
Truy cập portal.azure.com và đăng nhập
Tìm "App registrations" → nhấn "New registration"
Điền thông tin:
Name:
M365 MCP Server(hoặc tên bất kỳ)Supported account types: chọn theo nhu cầu:
Accounts in any organizational directory and personal Microsoft accounts— nếu muốn dùng cả tài khoản cá nhân lẫn tổ chứcAccounts in this organizational directory only— nếu chỉ dùng trong nội bộ tổ chức
Redirect URI: để trống
Nhấn Register
Sau khi tạo xong, copy Application (client) ID — đây là
AZURE_CLIENT_ID
Cấp quyền API
Vào tab "API permissions" → "Add a permission" → "Microsoft Graph" → "Delegated permissions"
Tìm và thêm các quyền sau:
Mail.ReadMail.ReadWriteMail.SendUser.ReadSites.Read.All— cần choread_sharepoint_excel/filter_sharepoint_excelFiles.Read.All— cần choread_sharepoint_excel/filter_sharepoint_exceloffline_access
Nhấn "Grant admin consent for [tên tổ chức]" nếu bạn là admin (tùy chọn — xem phần Troubleshooting nếu không có quyền này)
Nếu app đã tạo trước đó và chỉ có 4 quyền đầu, quay lại "API permissions" để bổ sung
Sites.Read.All/Files.Read.All, nếu không 2 tool SharePoint sẽ báo lỗi 403.
Bật Device Code Flow
Vào tab "Authentication"
Kéo xuống phần "Advanced settings"
Bật "Allow public client flows" → Yes
Nhấn Save
Bước 3: Cài đặt dependencies
Mở terminal, điều hướng vào thư mục project:
cd "C:\Projects\mcp-server"Cách 1: Dùng uv (Khuyên dùng — tự quản lý virtual env)
Cài uv (nếu máy chưa có):
Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"macOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | shHoặc nếu máy đã có sẵn Python + pip:
pip install uvSau khi cài xong, đóng và mở lại terminal để PATH được cập nhật, rồi kiểm tra bằng
uv --version.uvtự quản lý phiên bản Python — không cần cài Python 3.11 riêng,uv syncbên dưới sẽ tự tải nếu máy chưa có.
Cài dependencies:
uv syncCách 2: Dùng pip thông thường
pip install "mcp[cli]" msal httpx python-dotenv html2text openpyxl pypdf python-docxBước 4: Tạo file .env
Trong thư mục project, copy file mẫu:
# Windows
copy .env.example .env
# macOS / Linux
cp .env.example .envMở file .env và điền AZURE_CLIENT_ID lấy từ Bước 2:
AZURE_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AZURE_TENANT_ID=commonGiá trị AZURE_TENANT_ID:
Giá trị | Dùng khi |
| Tài khoản cá nhân (Outlook.com) hoặc hỗn hợp |
| Chỉ tài khoản tổ chức (work/school) |
| Giới hạn đúng một tổ chức cụ thể |
Bước 5: Cấu hình Claude Desktop
Mở file cấu hình Claude Desktop:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Thêm vào trong mcpServers (thay đường dẫn bằng đường dẫn thực tế trên máy bạn):
Cách 1: Dùng uv (Khuyên dùng)
{
"mcpServers": {
"outlook-email": {
"command": "uv",
"args": [
"--directory",
"C:\\Projects\\mcp-server",
"run",
"server.py"
]
}
}
}Cách 2: Dùng python trực tiếp
{
"mcpServers": {
"outlook-email": {
"command": "python",
"args": [
"C:\\Projects\\mcp-server\\server.py"
]
}
}
}Lưu ý Windows: Dùng
\\thay vì\trong đường dẫn JSON.
Restart Claude Desktop sau khi lưu file config.
Bước 6: Đăng nhập lần đầu
Sau khi restart Claude Desktop:
Mở cuộc trò chuyện mới
Kiểm tra biểu tượng MCP tools xuất hiện (icon công cụ)
Yêu cầu Claude gọi tool
auth_login:"Hãy đăng nhập vào Outlook email cho tôi"
Claude sẽ trả về URL và mã xác thực ngay trong chat, ví dụ:
1. Mở trình duyệt và truy cập: https://login.microsoft.com/device 2. Nhập mã xác thực: ABCD1234 3. Đăng nhập bằng tài khoản Microsoft của bạn 4. Sau khi xác thực xong, gọi auth_confirmThực hiện theo hướng dẫn trong chat, sau đó yêu cầu Claude gọi
auth_confirm:"Tôi đã xác thực xong, hãy xác nhận đăng nhập"
Claude thông báo đăng nhập thành công.
Token được lưu tại
~/.outlook-mcp-tokens.jsonvà tự động refresh — có hiệu lực 90 ngày.
Sử dụng
Sau khi đăng nhập, bạn có thể dùng ngôn ngữ tự nhiên:
"Kiểm tra xem tôi đã đăng nhập chưa"
"Liệt kê 10 email mới nhất trong inbox"
"Tìm email từ boss@company.com"
"Tạo email nháp gửi cho colleague@company.com với tiêu đề Meeting tomorrow"
"Gửi email cho client@example.com nội dung cảm ơn hợp tác"
"Đánh dấu email vừa đọc là chưa đọc"Troubleshooting
"Need admin approval" khi đăng nhập
Tài khoản tổ chức (work/school) yêu cầu admin của tổ chức phải grant consent cho app.
Nếu bạn là admin:
Azure Portal → Enterprise Applications → tìm app → Permissions → Grant admin consent
Nếu bạn không phải admin:
Nhờ IT admin của tổ chức vào Azure Portal, tìm app theo tên, và grant consent
Hoặc admin nhấn "Have an admin account? Sign in with that account" ngay trên màn hình lỗi
Giới hạn người dùng (tùy chọn cho admin):
Azure Portal → Enterprise Applications → tên app → Properties → bật "Assignment required"
Sau đó vào Users and groups → chỉ add những người được phép dùng
MCP server không xuất hiện trong Claude Desktop
Kiểm tra đường dẫn trong
claude_desktop_config.jsoncó đúng khôngĐảm bảo đã restart Claude Desktop hoàn toàn (thoát hẳn, không chỉ đóng cửa sổ)
Chạy thử
python server.pytrong terminal để kiểm tra lỗi
Lỗi sau khi gọi auth_confirm
Đảm bảo bạn đã hoàn thành xác thực trên browser trước khi gọi
auth_confirmMã xác thực hết hạn sau ~15 phút — nếu quá thời gian, gọi lại
auth_loginđể lấy mã mới
Token hết hạn
Token tự động refresh. Nếu bị lỗi xác thực sau 90 ngày, gọi lại auth_login để đăng nhập mới.
Cấu trúc dự án
mcp-server/
├── server.py # Entry point
├── config.py # Cấu hình và constants
├── pyproject.toml # Dependencies
├── .env # Biến môi trường (KHÔNG commit file này)
├── .env.example # File mẫu
├── auth/ # Xác thực Microsoft
│ ├── device_flow.py # MSAL Device Code Flow
│ ├── token_cache.py # Lưu trữ token
│ ├── tools.py # MCP tools: login/confirm/status/logout
│ └── __init__.py
├── graph/ # Microsoft Graph API client
│ ├── client.py # HTTP client, pagination
│ └── __init__.py
├── mail/ # Email operations
│ ├── list_emails.py
│ ├── read_email.py
│ ├── search_emails.py
│ ├── drafts.py # create/list/update/delete/send draft
│ ├── send_email.py
│ ├── mark_as_read.py
│ ├── attachments.py # list_attachments, read_attachment
│ ├── folder_utils.py
│ └── __init__.py
├── sharepoint/ # Đọc file Excel từ SharePoint Online
│ ├── read_excel.py
│ ├── filter_excel.py
│ ├── excel_common.py # helper resolve URL / download / parse JSON dùng chung
│ └── __init__.py
└── utils/ # Tiện ích dùng chung
├── html_sanitizer.py
└── formatting.pyMở rộng
Để thêm tính năng mới (ví dụ Calendar):
Tạo thư mục
calendar_tools/với các file tương tựmail/(không đặt têncalendar/— trùng tên module chuẩn của Python, sẽ gây lỗi import)Viết
calendar_tools/__init__.pyvới hàmregister_calendar_tools(mcp)Thêm vào
server.py:from calendar_tools import register_calendar_tools register_calendar_tools(mcp)Thêm package vào
pyproject.toml→[tool.hatch.build.targets.wheel] packages
Không cần thay đổi file nào khác.
Available Tools
17 toolsauth_confirmA
Hoàn tất đăng nhập sau khi bạn đã nhập mã xác thực trong trình duyệt. Gọi tool này sau khi đã hoàn thành bước xác thực trên trang Microsoft.
Inputs: no named parameters. Returns: result
auth_loginA
Bắt đầu đăng nhập Microsoft 365 qua Device Code Flow. Tool này trả về URL và mã xác thực — mở URL đó trong trình duyệt, nhập mã, sau đó gọi auth_confirm để hoàn tất.
Inputs: no named parameters. Returns: result
auth_logoutA
Đăng xuất — xóa token đã lưu, yêu cầu đăng nhập lại lần sau.
Inputs: no named parameters. Returns: result
auth_statusA
Kiểm tra trạng thái đăng nhập Microsoft 365 hiện tại.
Inputs: no named parameters. Returns: result
create_draftA
Tạo email nháp mới trong folder Drafts.
Args: to: Địa chỉ email người nhận (nhiều địa chỉ cách nhau bằng dấu phẩy). cc: Địa chỉ CC (tùy chọn). bcc: Địa chỉ BCC (tùy chọn). subject: Tiêu đề email. body: Nội dung email (hỗ trợ plain text hoặc HTML). importance: Độ ưu tiên: low, normal, hoặc high.
Inputs: cc, to, bcc, body, +2 more. Returns: result
delete_draftA
Xóa vĩnh viễn một email nháp.
Args: message_id: ID của email nháp cần xóa.
Inputs: message_id (required). Returns: result
list_attachmentsA
Liệt kê tất cả file đính kèm của một email.
Args: message_id: ID của email (lấy từ list_emails hoặc search_emails).
Inputs: message_id (required). Returns: result
list_draftsB
Liệt kê các email nháp trong folder Drafts.
Args: limit: Số lượng nháp tối đa (1-50).
Inputs: limit. Returns: result
list_emailsA
Liệt kê email trong một folder.
Args: folder: Tên folder (inbox, drafts, sent, deleted, junk, archive) hoặc tên tùy chỉnh. limit: Số lượng email tối đa (1-50).
Inputs: limit, folder. Returns: result
mark_email_as_readA
Đánh dấu email là đã đọc hoặc chưa đọc.
Args: message_id: ID của email. is_read: True để đánh dấu đã đọc, False để đánh dấu chưa đọc.
Inputs: message_id (required), is_read. Returns: result
read_attachmentA
Đọc và trả về nội dung file đính kèm trong email.
Hỗ trợ: txt, csv, json, html, xml, md (text), xlsx (Excel), pdf (PDF), docx (Word). Ảnh và định dạng khác trả về thông báo.
Args: message_id: ID của email chứa file đính kèm. attachment_id: ID của file đính kèm (lấy từ list_attachments).
Inputs: message_id (required), attachment_id (required). Returns: result
read_emailA
Đọc nội dung đầy đủ của một email theo ID.
Args: message_id: ID của email (lấy từ list_emails hoặc search_emails). mark_as_read: Nếu True, đánh dấu email là đã đọc sau khi xem.
Inputs: message_id (required), mark_as_read. Returns: result
search_emailsA
Tìm kiếm email với các điều kiện lọc.
Args: query: Từ khóa tìm kiếm tự do (KQL). Ưu tiên hơn các filter khác. folder: Folder để tìm kiếm. from_address: Lọc theo địa chỉ email người gửi. subject: Lọc theo từ khóa trong tiêu đề. unread_only: Chỉ lấy email chưa đọc. has_attachments: Chỉ lấy email có đính kèm. limit: Số kết quả tối đa (1-50).
Inputs: limit, query, folder, subject, +3 more. Returns: result
send_draftB
Gửi một email nháp đã có sẵn.
Args: message_id: ID của email nháp cần gửi.
Inputs: message_id (required). Returns: result
send_emailA
Soạn và gửi email ngay lập tức (không lưu nháp).
Args: to: Địa chỉ email người nhận (nhiều địa chỉ cách nhau bằng dấu phẩy). subject: Tiêu đề email. body: Nội dung email. cc: Địa chỉ CC (tùy chọn). bcc: Địa chỉ BCC (tùy chọn). is_html: True nếu body là HTML, False nếu là plain text. importance: Độ ưu tiên: low, normal, hoặc high.
Inputs: to (required), body (required), subject (required), cc, +3 more. Returns: result
update_draftB
Cập nhật nội dung email nháp đang tồn tại.
Args: message_id: ID của email nháp cần cập nhật. subject: Tiêu đề mới (bỏ qua nếu không muốn thay đổi). body: Nội dung mới (bỏ qua nếu không muốn thay đổi). to: Người nhận mới (bỏ qua nếu không muốn thay đổi). cc: CC mới (bỏ qua nếu không muốn thay đổi). bcc: BCC mới (bỏ qua nếu không muốn thay đổi).
Inputs: message_id (required), cc, to, bcc, +2 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 17 tools
Each tool has a clearly distinct purpose: authentication tools are separate from email operations, and email operations cover separate actions (create, list, read, update, delete, send, search). There is no overlap between tools.
All tools use snake_case with a consistent verb_noun pattern (e.g., create_draft, list_emails, send_email). The authentication tools follow the auth_ prefix pattern, maintaining consistency within the subset.
17 tools is slightly above the typical well-scoped range but still reasonable for a comprehensive email server. Each tool serves a specific function without redundancy, though the inclusion of read_sharepoint_excel feels a bit out of place.
The tool set covers core email workflows (send, draft, read, search, list) but lacks important operations like deleting non-draft emails, replying/forwarding, and moving emails between folders. These gaps could lead to agent failures in common scenarios.
Related MCP Connectors
A MCP server for Outlook email that lets you search, read, and draft emails and replies.
A MCP server for Gmail that lets you search, read, and draft emails and replies.
Hosted MCP server for your Gmail, Outlook and IMAP mail, with mailboxes and scopes set per agent.
An MCP server that provides email capabilities, hosted on Alpic platform
Related MCP Servers
- FlicenseAqualityDmaintenanceA lightweight MCP server for personal Microsoft Outlook/Hotmail accounts, enabling email search, reading, attachment management, and folder operations via Microsoft Graph API with OAuth device-code flow.61-
- AlicenseAqualityCmaintenanceMCP server for sending and managing Microsoft Outlook email via the Microsoft Graph API, including drafts, replies, contacts, and directory search.22ISC
- AlicenseAqualityDmaintenanceA local stdio MCP server that enables reading, sending, and searching emails, as well as listing calendar events via Microsoft Graph API, using device-code authentication.10MIT
- AlicenseNot gradedqualityDmaintenanceMCP server providing full control over Outlook.com, Hotmail, Live, or Microsoft 365 email via Microsoft Graph API, enabling reading, searching, sending, and managing messages and folders securely.1MIT