[MCP] MCP Milestones #703
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
-
Authorization Flow 授权流程1. 背景(Background)随着模型上下文协议 (Model Context Protocol, MCP) 的应用场景从本地环境扩展到开放的互联网,对服务进行访问控制和身份验证变得至关重要。这直接关系到 MCP Server 的核心安全性。当前,Pixiu 网关已经具备将后端 API 包装为 MCP Server 的能力,下一步的核心任务是利用网关的现有能力,集成一套标准的鉴权机制,以完整实现 MCP 规范中的授权 (Authorization) 要求。 MCP 规范明确指出:
本方案旨在设计一个健壮、可扩展且符合行业最佳实践的授权流程。 2. 核心原则与角色定位 (Core Principles & Role)2.1 Pixiu 的角色抉择:资源服务器
受保护的 MCP 服务器充当 OAuth 2.1 资源服务器,能够使用访问令牌接受和响应受保护的资源请求。 授权服务器负责与用户交互(如有必要)并颁发供 MCP 服务器使用的访问令牌。授权服务器的实现细节超出了本规范的范围。它可以与资源服务器一起托管,也可以作为单独的实体托管。指定 MCP 服务器如何向客户端指示其相应授权服务器的位置。 对于 Pixiu 网关而言,其核心职责是保护后端的 API 服务,因此我觉得包装成 Resource Server 是更好且正确的选择。
2.2. 授权流程概览sequenceDiagram
participant C as Client
participant M as MCP Server (Resource Server)
participant A as Authorization Server
C->>M: MCP request without token
M-->>C: HTTP 401 Unauthorized with WWW-Authenticate header
Note over C: Extract resource_metadata<br />from WWW-Authenticate
C->>M: GET /.well-known/oauth-protected-resource
M-->>C: Resource metadata with authorization server URL
Note over C: Validate RS metadata,<br />build AS metadata URL
C->>A: GET /.well-known/oauth-authorization-server
A-->>C: Authorization server metadata
Note over C,A: OAuth 2.1 authorization flow happens here
C->>A: Token request
A-->>C: Access token
C->>M: MCP request with access token
M-->>C: MCP response
Note over C,M: MCP communication continues with valid token
3. 约束与目标(Constraints & Goals)3.1 功能约束MCP servers MUST implement OAuth 2.0 Protected Resource Metadata (RFC9728). MCP clients MUST use OAuth 2.0 Protected Resource Metadata for authorization server discovery. Pixiu 作为 MCP Server 需要保护资源元数据。 Implementors should note that Protected Resource Metadata documents can define multiple authorization servers. The responsibility for selecting which authorization server to use lies with the MCP client, following the guidelines specified in RFC9728 Section 7.6 “Authorization Servers”. Pixiu 应该支持多个授权服务器的选择,选择权在于 MCP Client。 MCP servers MUST use the HTTP header Pixiu 在返回 401 的时候,需要通过 MCP servers, acting in their role as an OAuth 2.1 resource server, MUST validate access tokens as described in OAuth 2.1 Section 5.2. MCP servers MUST validate that access tokens were issued specifically for them as the intended audience, according to RFC 8707 Section 2. If validation fails, servers MUST respond according to OAuth 2.1 Section 5.3 error handling requirements. Invalid or expired tokens MUST receive a HTTP 401 response. Pixiu 需要验证访问令牌是否专门为其目标用户颁发。无效或过期的令牌必须收到 HTTP 401 响应。
Token Audience Binding and Validation: MCP servers MUST validate that tokens presented to them were specifically issued for their use Pixiu 必须验证提供给它们的令牌是否是专门为其使用的。 3.2 安全约束杜绝硬编码密钥: 严禁在代码或配置中硬编码任何对称密钥或私钥。公钥应通过标准的 核心声明验证: 必须强制验证令牌的 缓存安全: 元数据和公钥的缓存必须有明确的过期策略 (TTL),以响应密钥轮换等安全事件。 3.3 技术选型在对多个 JWT 库进行深入评估后,我们决定采用
综上所述,尽管切换库会带来一定的初期工作量,但选择 4. 设计方案 (Design & Implementation)本方案旨在通过引入 4.1 架构与文件结构为避免过度设计,我们将核心的 JWT 验证逻辑内聚在
4.2 核心验证器 (
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
MCP OverPixiu Milestones
Step 1: 基础能力建设
MCP 基础协议支持:支持 MCP (Model Context Protocol) 的核心功能。 Feat(MCP): Add MCP Server Filter for Model Context Protocol support #702
动态配置更新:集成 Nacos,实现配置的动态更新,提高系统的灵活性和可维护性。
权限认证:增加 MCP Auth 权限认证机制,保障模型的安全访问和合规使用。
核心对象支持:完整支持 MCP 中的
resource
和prompt
对象。Step 2: 兼容与扩展
多后端支持:扩展 MCP Server 的后端能力,除了 OpenAPI,还将支持 gRPC 和 Dubbo,提供更广泛的后端服务接入能力。
多集群模式:引入 MCP Session,支持多集群模式,提升系统的可伸缩性和容灾能力。
Step 3: 完善与增强
多模态数据兼容:探索在 MCP 体系下对语音、图像等多模态数据的兼容方案。
协议新特性对齐:对齐 MCP 协议的最新特性,包括日志(logging)、自动完成(completion)和分页(pagination)。
可观测性:构建完善的可观测性体系,方便对系统进行监控和问题排查。
测试
inspector
工具进行全面的协议兼容性和功能测试。Beta Was this translation helpful? Give feedback.
All reactions