这是一个原型服务器,用于演示如何将 MCP (模型上下文协议) 服务器连接到存储在 Microsoft Graph 中的数据。此项目作为概念验证,展示了如何读取用户的配置文件。
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":[{"id":"a1b2c3d4-e5f6-1234-5678-9abcdeff123","displayName":"John Doe","surname":"Doe","givenName":"John","emailAddress":"john.doe@company.com","phoneNumbers":["+1 234 567 890"],"mobilePhone":"+1 234 567 890","address":{"streetAddress":"123 Main St","city":"New York","state":"NY","postalCode":"10001","country":"USA"},"createdDateTime":"2023-01-01T00:00:00Z","modifiedDateTime":"2023-01-01T00:00:00Z"},{"id":"e5f6g7h8-i9j0-k1l2-m3n4-o5p6q7r8s9t","displayName":"Jane Smith","surname":"Smith","givenName":"Jane","emailAddress":"jane.smith@company.com","phoneNumbers":["+1 543 210 9876"],"mobilePhone":"+1 543 210 9876","address":{"streetAddress":"456 Oak Ave","city":"Los Angeles","state":"CA","postalCode":"90001","country":"USA"},"createdDateTime":"2023-01-01T00:00:00Z","modifiedDateTime":"2023-01-01T00:00:00Z"}]}}