Back to MCP directory
publicPublicdnsLocal runtime

mcp-msgraph

一个MCP服务器原型,用于从Microsoft Graph读取用户配置文件,展示MCP与Microsoft Graph数据连接的验证概念。

article

README

🚀 MCP-MSGraph

这是一个原型服务器,用于演示如何将 MCP (模型上下文协议) 服务器连接到存储在 Microsoft Graph 中的数据。此项目作为概念验证,展示了如何读取用户的配置文件。

🚀 快速开始

✨ 主要特性

  • 演示如何将 MCP 服务器连接到 Microsoft Graph 中的数据。
  • 作为概念验证,展示读取用户配置文件的功能。

📦 安装指南

创建 Azure AD 应用程序

  1. 登录 Azure 门户
  2. 导航至 Azure Active Directory > 应用程序注册 > 新建注册
  3. 创建一个新的应用程序。
  4. 记录生成的 应用程序(客户端)ID密码
  5. API 权限 下,添加 User.Read.All(作为委托权限或应用权限,具体取决于你的需求),并授予管理员同意。

运行服务器

  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":[{"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"}]}}
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client