MCP MSGraph
原型 MCP(模型上下文协议) 从中读取用户配置文件的服务器 微软图形.\ 该项目演示了如何将MCP连接到存储在Microsoft Graph中的数据,作为概念验证。
______________________________________________________________________
创建Azure AD应用程序
- 登录到 Azure门户.
- 引导到 Azure Active Directory > 应用程序注册 > 新注册.
- 创建新应用程序。
- 注意生成的 应用程序(客户端)ID 和 客户端密钥.
- 在...之下 API权限,添加 用户。读。全部 (视情况而定)并授予管理员同意。
______________________________________________________________________
运行服务器的说明:
- 克隆 存储库或设置自己的文件夹和文件结构。
- 创建虚拟环境:
python3 -m venv venv
source venv/bin/activate- 安装所需的软件包:
pip install fastapi uvicorn requests requests-oauthlib pydantic- 打开'main.py',将占位符值替换为您的应用程序ID、租户ID和客户端密钥。
- 启动服务器
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"]}]}]}}% 
