使用说明
带Internet身份验证的MCP服务器模板
该项目演示了一个具有互联网身份验证流程的模型上下文协议(MCP)服务器。
身份验证流程
┌────────────────┐ (1) Use authenticate tool ┌────────────────┐
│ │ ────────────────────────────────> │ │
│ │ │ │
│ AI Client │ │ MCP Server │
│ with MCP │ │ │
│ Support │ │ │
│ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │
└────────────────┘ (6) Authentication result └────────────────┘
│ │
│ │ (2) Open authentication URL
│ │ with pubkey & expiration
│ ▼
│ ┌────────────────┐
│ │ │
│ │ React Web App │
│ │ (Auth UI) │
│ │ │
│ └────────────────┘
│ │
│ │ (3) User authenticates
│ │ with Internet Identity
│ ▼
│ ┌────────────────┐
│ │ │
│ │ Internet │
│ │ Identity │
│ │ │
│ └────────────────┘
│ │
│ │ (4) Return delegation
│ ▼
│ ┌────────────────┐
│ │ │
│ │ React Web App │
│ │ (Auth UI) │
│ │ │
│ └────────────────┘
│ │
│ │ (5) Send delegation
│ │ to MCP Server
▼ ▼
┌────────────────┐ (7) Call other MCP tools ┌────────────────┐
│ │ ────────────────────────────────> │ │
│ │ │ │
│ AI Client │ │ MCP Server │
│ with MCP │ │ (Authenticated)│
│ Support │ │ │
│ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │
└────────────────┘ (8) Tool responses └────────────────┘
运作原理
-
请求身份验证:AI客户端使用
authenticate工具。 -
打开身份验证URL:MCP服务器打开一个带有身份验证URL的浏览器窗口,其中包括:
pubkey:代表团的公钥expiration:委派的过期时间(毫秒)
-
用户认证React web应用程序(Auth UI)为用户提供了一个使用Internet Identity或其他支持的身份提供者进行身份验证的界面。
-
委派创建:成功身份验证后,web应用程序使用提供的公钥和过期时间为MCP服务器创建委托链。
-
将委派发送到服务器:web应用程序将委托链发送到配置端点处的MCP服务器。
-
身份验证结果MCP服务器向AI客户端返回身份验证结果。
-
访问受保护的工具:如果身份验证成功,AI客户端现在可以调用需要身份验证的其他MCP工具。
-
受保护的响应:经过身份验证的MCP服务器用请求的数据响应工具调用。
项目结构
-
mcp-server/:MCP服务器实现- 处理MCP工具注册和请求
- 管理身份验证状态
- 处理来自web应用程序的委托
-
mcp-server-wallet-connect/:用于身份验证的React web应用程序- 连接到Internet身份
- 为MCP服务器创建委派
- 将代表团发送回服务器
安装说明
- 为两个项目配置环境变量
- 启动MCP服务器
- 启动React web应用程序
- 将您的AI客户端连接到MCP服务器
有关详细的设置说明,请参阅每个项目目录中的README文件。