用户配置文件读取服务

一个通过Microsoft Graph读取用户配置文件的MCP服务器原型,适用于需要集成Microsoft Graph数据的开发场景。

  • by kevinbellinger
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 kevinbellinger/mcp-msgraph

使用说明

MCP MSGraph

原型 MCP(模型上下文协议) 从中读取用户配置文件的服务器 微软图形.
该项目演示了如何将MCP连接到存储在Microsoft Graph中的数据,作为概念验证。


创建Azure AD应用程序

  1. 登录到 Azure门户.
  2. 引导到 Azure Active Directory > 应用程序注册 > 新注册.
  3. 创建新应用程序。
  4. 注意生成的 应用程序(客户端)ID 和 客户端密钥.
  5. 在...之下 API权限,添加 用户。读。全部 (视情况而定)并授予管理员同意。

运行服务器的说明:

  1. 克隆 存储库或设置自己的文件夹和文件结构。

  2. 创建虚拟环境:

python3 -m venv venv
source venv/bin/activate
  1. 安装所需的软件包:
pip install fastapi uvicorn requests requests-oauthlib pydantic
  1. 打开'main.py',将占位符值替换为您的应用程序ID、租户ID和客户端密钥。

  2. 启动服务器

uvicorn main:app --reload

您的服务器将在http://127.0.0.1:8000.


示例请求

使用curl(或任何REST客户端)发送请求以检索用户的配置文件:

curl -X POST http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
        "action":"readUserProfile",
        "contextId":"abc123",
        "data": {"userId":"someUser@yourtenant.onmicrosoft.com"}
      }'

结果应该看起来像:

{"status":"success","action":"readUserProfile","contextId":"abc123","data":{"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('adelev%40M365x17584779.onmicrosoft.com')/profile/$entity","id":"profileId","account@odata.context":"https://graph.microsoft.com/beta/$metadata#users('adelev%40M365x17584779.onmicrosoft.com')/profile/account","account":[{"ageGroup":"","countryCode":"","userPrincipalName":"AdeleV@M365x17584779.OnMicrosoft.com","allowedAudiences":"organization","createdDateTime":"2025-01-30T11:06:01.7661211Z","lastModifiedDateTime":"2025-01-30T11:06:01.9431431Z","id":"c74cb3af-2f62-43fa-9709-5d2cfc4b4042","isSearchable":false,"inference":null,"preferredLanguageTag":{"locale":null,"displayName":null},"createdBy":{"user":null,"device":null,"application":{"displayName":"AAD","id":null}},"lastModifiedBy":{"user":null,"device":null,"application":{"displayName":"MsGraph","id":null}},"source":{"type":["AAD","MsGraph"]},"sources":[{"sourceId":"4ce763dd-9214-4eff-af7c-da491cc3782d","isDefaultSource":true},{"sourceId":"0024a795-114d-4031-95c7-5fb543e00e80","properties":["isSipEnabled"]}]},{"ageGroup":"","countryCode":"","userPrincipalName":"","allowedAudiences":"federatedOrganizations","createdDateTime":"2025-01-30T11:06:01.7661213Z","lastModifiedDateTime":"2025-01-30T11:06:01.9431431Z","id":"750f8cc2-2f72-4b38-88c6-531dfc5ed47f","isSearchable":false,"inference":null,"preferredLanguageTag":{"locale":null,"displayName":null},"createdBy":{"user":null,"device":null,"application":{"displayName":"AAD","id":null}},"lastModifiedBy":{"user":null,"device":null,"application":{"displayName":"MsGraph","id":null}},"source":{"type":["AAD","MsGraph"]},"sources":[{"sourceId":"4ce763dd-9214-4eff-af7c-da491cc3782d","isDefaultSource":true},{"sourceId":"0024a795-114d-4031-95c7-5fb543e00e80","properties":["isSipEnabled"]}]}]}}%