@@ -35,8 +35,9 @@ description: MCP 服务器插件配置参考
3535| ` server.name ` | string | 必填 | - | MCP 服务器的名称。如果使用插件内置的 MCP 服务器(如 quark-search),只需配置此字段为对应的名称,无需配置 tools 字段。如果是 REST-to-MCP 场景,此字段可以填写任意值。 |
3636| ` server.type ` | string | 选填 | rest | MCP 服务器类型。可选值:` rest ` (REST-to-MCP 转换)、` mcp-proxy ` (MCP 代理)。如果不指定,默认为 ` rest ` 类型。 |
3737| ` server.config ` | object | 选填 | {} | 服务器配置,如 API 密钥等 |
38- | ` server.mcpServerURL ` | string | 当 ` server.type ` 为 ` mcp-proxy ` 时必填 | - | 后端 MCP 服务器的 URL 地址。仅在 ` mcp-proxy ` 类型时使用。 |
38+ | ` server.mcpServerURL ` | string | 当 ` server.type ` 为 ` mcp-proxy ` 时必填 | - | 后端 MCP 服务器的 URL 地址。仅在 ` mcp-proxy ` 类型时使用。支持完整 URL(如 ` http://example.com/mcp ` )或路径(如 ` /mcp ` ,将使用路由集群的基础 URL)。 |
3939| ` server.timeout ` | integer | 选填 | 5000 | 请求后端服务的超时时间(毫秒)。适用于 ` mcp-proxy ` 类型。 |
40+ | ` server.transport ` | string | 当 ` server.type ` 为 ` mcp-proxy ` 时必填 | - | 传输协议类型。可选值:` http ` (StreamableHTTP)、` sse ` (Server-Sent Events)。 |
4041| ` server.securitySchemes ` | array of object | 选填 | - | 定义可重用的认证方案,供工具引用。详见"认证与安全"章节。 |
4142| ` server.defaultDownstreamSecurity ` | object | 选填 | - | 服务器级别的默认客户端到网关认证配置,用于所有 tools/list 和 tools/call 请求。可被工具级别的 ` security ` 配置覆盖。支持 ` id ` (引用 securitySchemes)和 ` passthrough ` (透传标志)字段。 |
4243| ` server.defaultUpstreamSecurity ` | object | 选填 | - | 服务器级别的默认网关到后端认证配置,用于所有后端请求。可被工具级别的 ` requestTemplate.security ` 配置覆盖。支持 ` id ` (引用 securitySchemes)和 ` credential ` (覆盖默认凭证)字段。 |
@@ -173,6 +174,56 @@ proxywasm.AddHttpRequestHeader("x-envoy-allow-mcp-tools", "tool1,tool2,tool3")
173174| ` tools[].requestTemplate.security.credential ` | string | 选填 | - | 覆盖 ` server.securitySchemes ` 中定义的默认凭证。如果同时启用了 ` tools[].security.passthrough ` ,则此字段将被忽略,优先使用透传的凭证。 |
174175| ` tools[].errorResponseTemplate ` | string | 选填 | - | HTTP响应Status>=300 \\ | \\ | <200 时的错误响应转换模板 |
175176
177+ ## MCP 传输协议
178+
179+ MCP 代理服务器 (` mcp-proxy ` 类型) 支持两种传输协议与后端 MCP 服务器通信:
180+
181+ ### StreamableHTTP 协议 (` transport: http ` )
182+
183+ StreamableHTTP 是 MCP 的默认 HTTP 传输协议,使用标准的 HTTP 请求/响应模型:
184+
185+ - ** 特点** :
186+ - 简单的请求-响应模型
187+ - 使用标准 HTTP POST 请求
188+ - 响应为完整的 JSON 数据
189+ - 适合大多数 MCP 服务器实现
190+
191+ - ** 配置示例** :
192+ ``` yaml
193+ server :
194+ name : my-mcp-proxy
195+ type : mcp-proxy
196+ transport : http
197+ mcpServerURL : " http://backend-mcp.example.com/mcp"
198+ ` ` `
199+
200+ ### SSE 协议 (` transport: sse`)
201+
202+ SSE (Server-Sent Events) 是 MCP 的流式传输协议,支持实时数据推送:
203+
204+ - **特点**:
205+ - 基于 HTTP 的单向流式通信
206+ - 支持长连接和实时消息推送
207+ - 适合需要实时更新的场景
208+ - 协议流程:
209+ 1. **发现阶段**:向后端发送 POST 请求获取 SSE 端点 URL
210+ 2. **初始化阶段**:通过 SSE 端点发送 `initialize` 消息
211+ 3. **通知阶段**:发送 `notifications/initialized` 通知
212+ 4. **工具调用**:根据需要执行 `tools/list` 或 `tools/call` 请求
213+
214+ - **URL 配置**:
215+ - 支持完整 URL:`http://example.com/sse`
216+ - 支持路径:`/sse`(将使用 `mcpServerURL` 的基础 URL)
217+
218+ - **配置示例**:
219+ ` ` ` yaml
220+ server:
221+ name: my-sse-proxy
222+ type: mcp-proxy
223+ transport: sse
224+ mcpServerURL: "http://backend-mcp.example.com"
225+ timeout: 10000 # SSE 可能需要更长的超时时间
226+ ` ` `
176227# # 认证与安全
177228
178229MCP Server 插件支持灵活的认证配置,以确保与后端 REST API 或 MCP 服务器通信的安全性。插件支持两种服务器类型的认证配置:
@@ -582,12 +633,13 @@ server:
582633
583634此配置使用了 Higress 内置的 quark-search MCP 服务器。在这种情况下,只需要指定服务器名称和必要的配置(如 API 密钥),无需配置 tools 字段,因为工具已经在服务器中预定义好了。
584635
585- ### MCP 代理服务器示例:代理到后端 MCP 服务器
636+ ### MCP 代理服务器示例:代理到后端 MCP 服务器(StreamableHTTP)
586637
587638``` yaml
588639server :
589640 name : my-mcpserver-proxy
590641 type : mcp-proxy
642+ transport : http # 使用 StreamableHTTP 协议
591643 mcpServerURL : " http://backend-mcp.example.com/mcp"
592644 timeout : 5000
593645 defaultDownstreamSecurity : # 客户端到网关的默认认证
@@ -620,11 +672,44 @@ tools:
620672` ` `
621673
622674此配置创建了一个 MCP 代理服务器,它:
623- 1. 将客户端的 MCP 请求代理到 ` http://backend-mcp.example.com/mcp`
675+ 1. 使用 StreamableHTTP 协议将客户端的 MCP 请求代理到 ` http://backend-mcp.example.com/mcp`
6246762. 使用服务器级别的默认认证配置处理 `tools/list` 等通用请求
6256773. 工具级别的认证配置可以覆盖默认设置
6266784. 支持透明认证和凭证覆盖
627679
680+ # ## MCP 代理服务器示例:使用 SSE 协议
681+
682+ ` ` ` yaml
683+ server:
684+ name: my-sse-mcpserver-proxy
685+ type: mcp-proxy
686+ transport: sse # 使用 SSE 协议
687+ mcpServerURL: "http://backend-mcp.example.com"
688+ timeout: 10000 # SSE 连接可能需要更长的超时时间
689+ defaultDownstreamSecurity:
690+ id: ClientBearer
691+ defaultUpstreamSecurity:
692+ id: BackendBearer
693+ securitySchemes:
694+ - id: ClientBearer
695+ type: http
696+ scheme: bearer
697+ - id: BackendBearer
698+ type: http
699+ scheme: bearer
700+
701+ allowTools:
702+ - weather-tool
703+ - news-tool
704+ ` ` `
705+
706+ 此配置创建了一个使用 SSE 协议的 MCP 代理服务器:
707+ 1. 使用 SSE 流式协议与后端通信,支持实时消息推送
708+ 2. 自动处理 SSE 连接的生命周期(发现、初始化、通知、工具调用)
709+ 3. 原始请求头会自动复制到后端调用中
710+ 4. 支持 `allowTools` 过滤可用工具列表
711+ 5. 认证头会正确传递到所有 SSE 请求中
712+
628713# ## MCP 代理服务器高级示例:透明认证
629714
630715` ` ` yaml
@@ -1000,10 +1085,13 @@ tools:
10001085
10011086### MCP 代理服务器配置
10021087
1088+ #### StreamableHTTP 协议
1089+
10031090` ` ` yaml
10041091server :
10051092 name : mcp-proxy-server
10061093 type : mcp-proxy
1094+ transport : http # StreamableHTTP 协议
10071095 mcpServerURL : " http://backend-mcp.example.com/mcp" # 后端 MCP 服务器 URL
10081096 timeout : 5000 # 超时时间(毫秒)
10091097 # 服务器级别默认认证(推荐配置)
@@ -1042,6 +1130,35 @@ tools:
10421130 credential : " 特定工具的后端凭证"
10431131` ` `
10441132
1133+ #### SSE 协议
1134+
1135+ ` ` ` yaml
1136+ server :
1137+ name : mcp-sse-proxy-server
1138+ type : mcp-proxy
1139+ transport : sse # SSE 协议
1140+ mcpServerURL : " http://backend-mcp.example.com" # 后端 MCP 服务器基础 URL
1141+ timeout : 10000 # SSE 通常需要更长的超时时间
1142+ # 服务器级别默认认证
1143+ defaultDownstreamSecurity :
1144+ id : ClientBearer
1145+ defaultUpstreamSecurity :
1146+ id : BackendBearer
1147+ securitySchemes :
1148+ - id : ClientBearer
1149+ type : http
1150+ scheme : bearer
1151+ - id : BackendBearer
1152+ type : http
1153+ scheme : bearer
1154+ defaultCredential : " 后端Bearer Token"
1155+
1156+ # 可选:限制允许的工具
1157+ allowTools :
1158+ - tool1
1159+ - tool2
1160+ ` ` `
1161+
10451162## 模板语法
10461163
10471164模板使用 GJSON Template 语法 (https://github.com/higress-group/gjson_template),该语法结合了 Go 模板和 GJSON 路径语法进行 JSON 处理。模板引擎支持:
@@ -1068,8 +1185,10 @@ tools:
10681185### 如果要代理现有的 MCP 服务器
10691186请提供:
10701187- 后端 MCP 服务器的 URL
1188+ - 传输协议类型(StreamableHTTP 或 SSE)
10711189- 认证要求(客户端认证、后端认证)
10721190- 是否需要透明认证(将客户端凭证传递给后端)
1191+ - 是否需要限制可用工具(allowTools)
10731192- 特定工具的配置需求
10741193
10751194[在此描述您的具体需求]
@@ -1087,8 +1206,10 @@ tools:
108712065. 配置适当的认证方案和安全配置
10881207
10891208# ## 对于 MCP 代理服务器:
1090- 1. 配置后端 MCP 服务器 URL 和超时时间
1091- 2. 设置服务器级别的默认认证配置
1092- 3. 根据需要配置透明认证
1093- 4. 如有特殊需求,配置特定工具的认证覆盖
1094- 5. 确保客户端到网关和网关到后端的认证链路完整
1209+ 1. 选择合适的传输协议(`http` 用于 StreamableHTTP,`sse` 用于 SSE)
1210+ 2. 配置后端 MCP 服务器 URL 和超时时间(SSE 建议使用更长的超时时间)
1211+ 3. 设置服务器级别的默认认证配置
1212+ 4. 根据需要配置透明认证
1213+ 5. 配置 `allowTools` 以限制可用工具(可选)
1214+ 6. 如有特殊需求,配置特定工具的认证覆盖
1215+ 7. 确保客户端到网关和网关到后端的认证链路完整
0 commit comments