内容
<!--
---
name: Remote Microsoft Graph MCP using Azure API Management (Experimental)
description: Use Azure API Management as the AI Gateway for MCP Servers, providing tools that calls Microsoft Graph API
page_type: sample
languages:
- dotnet
- bicep
- azdeveloper
products:
- azure-api-management
- microsoft-graph
- azure
urlFragment: remote-mcp-apim-msgraph
---
-->
# 使用 Azure API Management 保护远程 Microsoft Graph MCP 服务器 (实验性)

Azure API Management 作为 MCP 服务器的 [AI Gateway](https://github.com/Azure-Samples/AI-Gateway)。
此示例实现了最新的 [MCP 授权规范](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization#2-10-third-party-authorization-flow)。然后在 MCP 工具中调用 Microsoft Graph API。
这是一个 [时序图](infra/app/apim-oauth/diagrams/diagrams.md),用于理解流程。
## 部署远程 MCP 服务器到 Azure
运行此 [azd](https://aka.ms/azd) 命令以配置 API 管理服务、Web 应用(带代码)及所有其他所需的 Azure 资源
```shell
azd up
```
### MCP Inspector
1. 在 **新终端窗口** 中,安装并运行 MCP Inspector
```shell
npx @modelcontextprotocol/inspector
```
2. CTRL 点击从应用显示的 URL 加载 MCP Inspector Web 应用(例如 http://127.0.0.1:6274/#resources)
3. 将传输类型设置为 `Streamable HTTP`
4. 将 URL 设置为您运行的 API 管理 Streamable HTTP 端点,该端点在 `azd up` 后显示,并 **连接** 
5. **列出工具**。
6. 点击 `ShowUserProfile` 工具并 **运行工具**。该工具将返回您的用户资料。
### VS Code
1. 安装最新的 [VS Code Insider](https://code.visualstudio.com/insiders/)
2. 打开命令面板并触发 `MCP: Add Server` 命令
3. 选择 `HTTP` 作为 MCP 服务器类型
4. 将 URL 设置为您运行的 API 管理 Streamable HTTP 端点,该端点在 `azd up` 后显示,并 **连接** 
5. 等待一会儿,VS Code Insider 会要求您登录
6. 打开 GitHub Copilot,并在代理模式下询问 "Who am I?"。GitHub Copilot 将返回从此 MCP 服务器获取的您的用户资料。