MDI MCP Server
An MCP server that integrates with Microsoft Defender for Identity via the Microsoft Graph API, enabling natural language queries and HTML report generation for alerts, incidents, risky users, and more.
README
MDI MCP Server
A Model Context Protocol (MCP) server that integrates with Microsoft Defender for Identity (MDI) via the Microsoft Graph API. Use it with VS Code + GitHub Copilot to query MDI data and generate styled HTML reports — all from natural language.
Features
| Category | Tools |
|---|---|
| Alerts & Incidents | Query MDI alerts by severity, fetch security incidents |
| Secure Score | Get latest score, identity-related control recommendations |
| Risky Users | List risky users, view risk detections from Identity Protection |
| Sensor Health | Check MDI sensor status, surface health issues |
| Activity Timeline | Suspicious logon events, directory changes (password resets, group changes) |
| Advanced Hunting | Run arbitrary KQL queries against Defender tables |
| HTML Reports | Generate dark-themed, print-friendly reports for any of the above |
Prerequisites
-
Python 3.10+
-
Azure AD App Registration with the following Application permissions:
SecurityAlert.Read.AllSecurityIncident.Read.AllSecurityEvents.Read.AllIdentityRiskyUser.Read.AllIdentityRiskEvent.Read.AllThreatHunting.Read.All
Grant admin consent after adding the permissions.
-
VS Code with GitHub Copilot extension installed.
Quick Start
1. Clone and install
git clone https://github.com/TigerToker/mdi-mcp-server.git
cd mdi-mcp-server
pip install -e .
2. Configure credentials
Copy .env.example to .env and fill in your Azure AD app registration details:
cp .env.example .env
# Edit .env with your AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET
3. Connect to VS Code + Copilot
The repo includes .vscode/mcp.json which auto-registers the server. Open the project folder in VS Code and Copilot will detect the MCP server.
Alternatively, add this to your User settings.json for global access:
"mcp": {
"servers": {
"mdi-mcp-server": {
"type": "stdio",
"command": "python",
"args": ["-m", "mdi_mcp_server.server"],
"cwd": "/path/to/mdi-mcp-server/src",
"env": {
"AZURE_TENANT_ID": "your-tenant-id",
"AZURE_CLIENT_ID": "your-client-id",
"AZURE_CLIENT_SECRET": "your-client-secret"
}
}
}
}
4. Start asking questions
In Copilot Chat, try:
- "Show me all high-severity MDI alerts from the last week"
- "Generate a comprehensive MDI report for the past 30 days"
- "Are there any risky users in my tenant?"
- "What's the health status of our MDI sensors?"
- "Run an Advanced Hunting query for failed logon attempts"
Project Structure
mdi-mcp-server/
├── src/mdi_mcp_server/
│ ├── server.py # MCP server entry point & tool definitions
│ ├── graph_client.py # Microsoft Graph API client
│ ├── report_generator.py # Jinja2-based HTML report builder
│ └── templates/
│ └── report.html # Dark-themed HTML report template
├── .vscode/mcp.json # VS Code MCP server configuration
├── .github/copilot-instructions.md
├── pyproject.toml
├── requirements.txt
└── .env.example
Available MCP Tools
Query Tools
| Tool | Description |
|---|---|
get_mdi_alerts |
Fetch MDI alerts with optional severity filter |
get_mdi_incidents |
Fetch security incidents |
get_secure_score |
Latest Secure Score snapshots |
get_secure_score_controls |
All Secure Score control profiles |
get_risky_users |
Risky users from Identity Protection |
get_risk_detections |
Individual risk detection events |
get_mdi_sensor_info |
MDI sensor & domain controller status |
get_mdi_health_issues |
MDI health alerts |
get_suspicious_activity_timeline |
Suspicious logon events |
get_identity_directory_events |
Directory change events |
run_custom_hunting_query |
Ad-hoc KQL via Advanced Hunting |
Report Generation Tools
| Tool | Description |
|---|---|
generate_alerts_report |
HTML report of MDI alerts |
generate_incidents_report |
HTML report of security incidents |
generate_risky_users_report |
HTML report of risky users |
generate_secure_score_report |
HTML report of Secure Score |
generate_sensor_health_report |
HTML report of sensor health |
generate_full_mdi_report |
Comprehensive report with all data |
Required Graph API Permissions
| Permission | Type | Purpose |
|---|---|---|
SecurityAlert.Read.All |
Application | Read security alerts (MDI alerts) |
SecurityIncident.Read.All |
Application | Read security incidents |
SecurityEvents.Read.All |
Application | Read security events |
IdentityRiskyUser.Read.All |
Application | Read risky user data |
IdentityRiskEvent.Read.All |
Application | Read risk detection events |
ThreatHunting.Read.All |
Application | Run Advanced Hunting queries |
GitHub Copilot Extension
This project also ships as a GitHub Copilot Extension — a standalone agent that responds to natural-language queries about MDI directly inside GitHub Copilot Chat.
How It Works
The extension runs a FastAPI server that implements the GitHub Copilot Extensions agent protocol. When you @mention the extension in Copilot Chat, your message is routed to the /agent endpoint, which parses your intent, queries the Graph API, and streams back a markdown response.
Running Locally
# Install dependencies
pip install -e .
# Set environment variables
export AZURE_TENANT_ID="your-tenant-id"
export AZURE_CLIENT_ID="your-client-id"
export AZURE_CLIENT_SECRET="your-client-secret"
export GITHUB_WEBHOOK_SECRET="your-webhook-secret"
# Start the server
uvicorn mdi_mcp_server.copilot_extension:app --host 0.0.0.0 --port 8080 --app-dir src
Docker
docker build -t mdi-copilot-extension .
docker run -p 8080:8080 \
-e AZURE_TENANT_ID="..." \
-e AZURE_CLIENT_ID="..." \
-e AZURE_CLIENT_SECRET="..." \
-e GITHUB_WEBHOOK_SECRET="..." \
mdi-copilot-extension
Deploy to Azure Container Apps
Use the provided deployment script:
.\deploy.ps1 -ResourceGroup "mdi-copilot-rg" -AcrName "myacr"
Or deploy manually via Bicep:
az deployment group create \
--resource-group mdi-copilot-rg \
--template-file infra/main.bicep \
--parameters containerImage="myacr.azurecr.io/mdi-copilot-extension:latest" \
azureTenantId="..." azureClientId="..." \
azureClientSecret="..." githubWebhookSecret="..."
Register the Extension
- Go to GitHub Settings → Developer Settings → GitHub Apps → Copilot Extensions
- Create a new Copilot Extension (or GitHub App with Copilot agent)
- Set the Agent URL to your deployed endpoint:
https://<your-app>.azurecontainerapps.io/agent - Set the Webhook Secret to match
GITHUB_WEBHOOK_SECRET - Install the app on your organization or account
Extension Commands
Once installed, use @mdi (or your extension name) in Copilot Chat:
@mdi show me high severity alerts from the last 7 days@mdi generate a full MDI report for the past 30 days@mdi are there any risky users?@mdi what's our secure score?@mdi check MDI sensor health
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。