M365 Email MCP Server
An MCP (Model Context Protocol) server that enables AI agents to send and receive email through Microsoft 365 using the Microsoft Graph API.
Features
- send_email — Send emails from the agent account (supports To, CC, BCC)
- list_emails — List recent inbox emails with subject, sender, date, and preview
- read_email — Read the full content of a specific email
- reply_email — Reply to a specific email
Prerequisites
1. Azure Entra ID App Registration
- Go to Azure Portal → Microsoft Entra ID → App registrations → New registration
- Name:
M365ToolsMcp(or your choice) - Supported account types: Single tenant
- Click Register
2. Add API Permissions
- Go to API permissions → Add a permission → Microsoft Graph → Application permissions
- Add:
-Mail.ReadWrite
-Mail.Send - Click Grant admin consent for your tenant
3. Create Client Secret
- Go to Certificates & secrets → New client secret
- Copy the secret value immediately (it won't be shown again)
4. Record Configuration Values
You'll need:
- Tenant ID (from Overview page)
- Client ID / Application ID (from Overview page)
- Client Secret (from step 3)
Configuration
Update appsettings.json:```json
{
"AzureAd": {
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret"
},
"Email": {
"UserId": "email@domain.com"
}
}
> **For development**, use .NET User Secrets instead:
>```bash
> dotnet user-secrets init
> dotnet user-secrets set "AzureAd:TenantId" "your-tenant-id"
> dotnet user-secrets set "AzureAd:ClientId" "your-client-id"
> dotnet user-secrets set "AzureAd:ClientSecret" "your-client-secret"
> ```
## Running```bash
dotnet run
The server starts on http://localhost:5000 by default with HTTP/SSE transport.
Connecting from an MCP Client
Point your MCP client (e.g., OpenClaw, VS Code Copilot, Claude Desktop) to:```
http://localhost:5067/
The server exposes tools via the standard MCP protocol over HTTP with Server-Sent Events.
## Project Structure```
├── Program.cs # ASP.NET Core host + MCP server setup
├── appsettings.json # Configuration (Entra ID, email)
├── Services/
│ └── GraphEmailService.cs # Microsoft Graph email operations
└── Tools/
├── SendEmailTool.cs # send_email MCP tool
├── ListEmailsTool.cs # list_emails MCP tool
├── ReadEmailTool.cs # read_email MCP tool
└── ReplyEmailTool.cs # reply_email MCP tool
