Microsoft Entra ID MCP Server 标志

Microsoft Entra ID MCP Server

社区
hieuttmmo

MCP server for interacting with EntraID through Microsoft Graph API.

发布者hieuttmmo
代码仓库entraid-mcp-server
语言Python
复刻数
18
星标数
41
可用工具
0
传输类型stdio
分类
链接
  • 将工具接入 AI 工作流

    Microsoft Entra ID MCP Server 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 41 个 Star 和 18 个 Fork。

EntraID MCP Server (Microsoft Graph FastMCP)

This project provides a modular, resource-oriented FastMCP server for interacting with Microsoft Graph API. It is designed for extensibility, maintainability, and security, supporting advanced queries for users, sign-in logs, MFA status, and privileged users.

Features

  • Modular Resource Structure:
    • Each resource (users, sign-in logs, MFA, etc.) is implemented in its own module under src/msgraph_mcp_server/resources/.
    • Easy to extend with new resources (e.g., groups, devices).
  • Centralized Graph Client:
    • Handles authentication and client initialization.
    • Shared by all resource modules.
  • Comprehensive User Operations:
    • Search users by name/email.
    • Get user by ID.
    • List all privileged users (directory role members).
  • Full Group Lifecycle & Membership Management:
    • Create, read, update, and delete groups.
    • Add/remove group members and owners.
    • Search and list groups and group members.
  • Application & Service Principal Management:
    • List, create, update, and delete applications (app registrations).
    • List, create, update, and delete service principals.
    • View app role assignments and delegated permissions for both applications and service principals.
  • Sign-in Log Operations:
    • Query sign-in logs for a user for the last X days.
  • MFA Operations:
    • Get MFA status for a user.
    • Get MFA status for all members of a group.
  • Password Management:
    • Reset user passwords directly with custom or auto-generated secure passwords.
    • Option to require password change on next sign-in.
  • Permissions Helper:
    • Suggest appropriate Microsoft Graph permissions for common tasks.
    • Search and explore available Graph permissions.
    • Helps implement the principle of least privilege by recommending only necessary permissions.
  • Error Handling & Logging:
    • Consistent error handling and progress reporting via FastMCP context.
    • Detailed logging for troubleshooting.
  • Security:
    • .env and secret files are excluded from version control.
    • Uses Microsoft best practices for authentication.

Project Structure

src/msgraph_mcp_server/
├── auth/           # Authentication logic (GraphAuthManager)
├── resources/      # Resource modules (users, signin_logs, mfa, ...)
│   ├── users.py            # User operations (search, get by ID, etc.)
│   ├── signin_logs.py      # Sign-in log operations
│   ├── mfa.py              # MFA status operations
│   ├── permissions_helper.py # Graph permissions utilities and suggestions
│   ├── applications.py       # Application (app registration) operations
│   ├── service_principals.py # Service principal operations
│   └── ...                 # Other resource modules
├── utils/          # Core GraphClient and other ultilities tool, such as password generator..
├── server.py       # FastMCP server entry point (registers tools/resources)
├── __init__.py     # Package marker

Usage

1. Setup

  • Clone the repo.
  • Create a config/.env file with your Azure AD credentials:
    TENANT_ID=your-tenant-id
    CLIENT_ID=your-client-id
    CLIENT_SECRET=your-client-secret
  • (Optional) Set up certificate-based auth if needed.

2. Testing & Development

You can test and develop your MCP server directly using the FastMCP CLI:

bash
fastmcp dev '/path/to/src/msgraph_mcp_server/server.py'

This launches an interactive development environment with the MCP Inspector. For more information and advanced usage, see the FastMCP documentation.

3. Available Tools

User Tools

  • search_users(query, ctx, limit=10) — Search users by name/email
  • get_user_by_id(user_id, ctx) — Get user details by ID
  • get_privileged_users(ctx) — List all users in privileged directory roles
  • get_user_roles(user_id, ctx) — Get all directory roles assigned to a user
  • get_user_groups(user_id, ctx) — Get all groups (including transitive memberships) for a user

Group Tools

  • get_all_groups(ctx, limit=100) — Get all groups (with paging)
  • get_group_by_id(group_id, ctx) — Get a specific group by its ID
  • search_groups_by_name(name, ctx, limit=50) — Search for groups by display name
  • get_group_members(group_id, ctx, limit=100) — Get members of a group by group ID
  • create_group(ctx, group_data) — Create a new group (see below for group_data fields)
  • update_group(group_id, ctx, group_data) — Update an existing group (fields: displayName, mailNickname, description, visibility)
  • delete_group(group_id, ctx) — Delete a group by its ID
  • add_group_member(group_id, member_id, ctx) — Add a member (user, group, device, etc.) to a group
  • remove_group_member(group_id, member_id, ctx) — Remove a member from a group
  • add_group_owner(group_id, owner_id, ctx) — Add an owner to a group
  • remove_group_owner(group_id, owner_id, ctx) — Remove an owner from a group

Group Creation/Update Example:

  • group_data for create_group and update_group should be a dictionary with keys such as:
    • displayName (required for create)
    • mailNickname (required for create)
    • description (optional)
    • groupTypes (optional, e.g., ["Unified"])
    • mailEnabled (optional)
    • securityEnabled (optional)
    • visibility (optional, "Private" or "Public")
    • owners (optional, list of user IDs)
    • members (optional, list of IDs)
    • membershipRule (required for dynamic groups)
    • membershipRuleProcessingState (optional, "On" or "Paused")

See the groups.py docstrings for more details on supported fields and behaviors.

Sign-in Log Tools

  • get_user_sign_ins(user_id, ctx, days=7) — Get sign-in logs for a user

MFA Tools

  • get_user_mfa_status(user_id, ctx) — Get MFA status for a user
  • get_group_mfa_status(group_id, ctx) — Get MFA status for all group members

Device Tools

  • get_all_managed_devices(filter_os=None) — Get all managed devices (optionally filter by OS)
  • get_managed_devices_by_user(user_id) — Get all managed devices for a specific user

Conditional Access Policy Tools

  • get_conditional_access_policies(ctx) — Get all conditional access policies
  • get_conditional_access_policy_by_id(policy_id, ctx) — Get a single conditional access policy by its ID

Audit Log Tools

  • get_user_audit_logs(user_id, days=30) — Get all relevant directory audit logs for a user by user_id within the last N days

Password Management Tools

  • reset_user_password_direct(user_id, password=None, require_change_on_next_sign_in=True, generate_password=False, password_length=12) — Reset a user's password with a specific password value or generate a secure random password

Permissions Helper Tools

  • suggest_permissions_for_task(task_category, task_name) — Suggest Microsoft Graph permissions for a specific task based on common mappings
  • list_permission_categories_and_tasks() — List all available categories and tasks for permission suggestions
  • get_all_graph_permissions() — Get all Microsoft Graph permissions directly from the Microsoft Graph API
  • search_permissions(search_term, permission_type=None) — Search for Microsoft Graph permissions by keyword

Application Tools

  • list_applications(ctx, limit=100) — List all applications (app registrations) in the tenant, with paging
  • get_application_by_id(app_id, ctx) — Get a specific application by its object ID (includes app role assignments and delegated permissions)
  • create_application(ctx, app_data) — Create a new application (see below for app_data fields)
  • update_application(app_id, ctx, app_data) — Update an existing application (fields: displayName, signInAudience, tags, identifierUris, web, api, requiredResourceAccess)
  • delete_application(app_id, ctx) — Delete an application by its object ID

Application Creation/Update Example:

  • app_data for create_application and update_application should be a dictionary with keys such as:
    • displayName (required for create)
    • signInAudience (optional)
    • tags (optional)
    • identifierUris (optional)
    • web (optional)
    • api (optional)
    • requiredResourceAccess (optional)

Service Principal Tools

  • list_service_principals(ctx, limit=100) — List all service principals in the tenant, with paging
  • get_service_principal_by_id(sp_id, ctx) — Get a specific service principal by its object ID (includes app role assignments and delegated permissions)
  • create_service_principal(ctx, sp_data) — Create a new service principal (see below for sp_data fields)
  • update_service_principal(sp_id, ctx, sp_data) — Update an existing service principal (fields: displayName, accountEnabled, tags, appRoleAssignmentRequired)
  • delete_service_principal(sp_id, ctx) — Delete a service principal by its object ID

Service Principal Creation/Update Example:

  • sp_data for create_service_principal and update_service_principal should be a dictionary with keys such as:
    • appId (required for create)
    • accountEnabled (optional)
    • tags (optional)
    • appRoleAssignmentRequired (optional)
    • displayName (optional)

Example Resource

  • greeting://{name} — Returns a personalized greeting

Extending the Server

  • Add new resource modules under resources/ (e.g., groups.py, devices.py).
  • Register new tools in server.py using the FastMCP @mcp.tool() decorator.
  • Use the shared GraphClient for all API calls.

Security & Best Practices

  • Never commit secrets: .env and other sensitive files are gitignored.
  • Use least privilege: Grant only the necessary Microsoft Graph permissions to your Azure AD app.
  • Audit & monitor: Use the logging output for troubleshooting and monitoring.

Required Graph API Permissions

API / PermissionTypeDescription
AuditLog.Read.AllApplicationRead all audit log data
AuthenticationContext.Read.AllApplicationRead all authentication context information
DeviceManagementManagedDevices.Read.AllApplicationRead Microsoft Intune devices
Directory.Read.AllApplicationRead directory data
Group.Read.AllApplicationRead all groups
GroupMember.Read.AllApplicationRead all group memberships
Group.ReadWrite.AllApplicationCreate, update, delete groups; manage group members and owners
Policy.Read.AllApplicationRead your organization's policies
RoleManagement.Read.DirectoryApplicationRead all directory RBAC settings
User.Read.AllApplicationRead all users' full profiles
User-PasswordProfile.ReadWrite.AllApplicationLeast privileged permission to update the passwordProfile property
UserAuthenticationMethod.Read.AllApplicationRead all users' authentication methods
Application.ReadWrite.AllApplicationCreate, update, and delete applications (app registrations) and service principals

Note: Group.ReadWrite.All is required for group creation, update, deletion, and for adding/removing group members or owners. Group.Read.All and GroupMember.Read.All are sufficient for read-only group and membership queries.

Advanced: Using with Claude or Cursor

Using with Claude (Anthropic)

To install and run this server as a Claude MCP tool, use:

bash
fastmcp install '/path/to/src/msgraph_mcp_server/server.py' \
  --with msgraph-sdk --with azure-identity --with azure-core --with msgraph-core \
  -f /path/to/.env
  • Replace /path/to/ with your actual project path.
  • The -f flag points to your .env file (never commit secrets!).

Using with Cursor

Add the following to your .cursor/mcp.json (do not include actual secrets in version control):

json
{
  "EntraID MCP Server": {
    "command": "uv",
    "args": [
      "run",
      "--with", "azure-core",
      "--with", "azure-identity",
      "--with", "fastmcp",
      "--with", "msgraph-core",
      "--with", "msgraph-sdk",
      "fastmcp",
      "run",
      "/path/to/src/msgraph_mcp_server/server.py"
    ],
    "env": {
      "TENANT_ID": "<your-tenant-id>",
      "CLIENT_ID": "<your-client-id>",
      "CLIENT_SECRET": "<your-client-secret>"
    }
  }
}
  • Replace /path/to/ and the environment variables with your actual values.
  • Never commit real secrets to your repository!

License

MIT

将 Microsoft Entra ID MCP Server MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Microsoft Entra ID MCP Server 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Microsoft Entra ID MCP Server 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Microsoft Entra ID MCP Server MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "entraid-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Microsoft Entra ID MCP Server MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Microsoft Entra ID MCP Server MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Microsoft Entra ID MCP Server 帮我完成这项任务吗?
Microsoft Entra ID MCP Server
当然。我已阅读。
以下是我使用 Microsoft Entra ID MCP Server 得到的结果。

常见问题

Microsoft Entra ID MCP Server MCP 服务器有什么用途?

Microsoft Entra ID MCP Server 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Microsoft Entra ID MCP Server MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Microsoft Entra ID MCP Server,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Microsoft Entra ID MCP Server MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Microsoft Entra ID MCP Server 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Microsoft Entra ID MCP Server MCP 连接到 TypingMind?

Microsoft Entra ID MCP Server 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Microsoft Entra ID MCP Server MCP 在 TypingMind 中提供哪些工具?

Microsoft Entra ID MCP Server 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Microsoft Entra ID MCP Server MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Microsoft Entra ID MCP Server 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇