From 2ea1bd24322e3bdd731ef52d28f5a0e89e5ea36e Mon Sep 17 00:00:00 2001 From: weibaohui Date: Mon, 23 Mar 2026 19:44:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20MCP=20=E4=BB=85=E4=BF=9D=E7=95=99=20Str?= =?UTF-8?q?eamable=20HTTP=EF=BC=8C=E7=A7=BB=E9=99=A4=20SSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端移除 SSE 端点(/mcp/sse, /mcp/message) - 前端移除 SSE 配置选项,仅保留 Streamable HTTP - 更新协议版本显示为 MCP 2025-11-25 --- backend/cmd/server/main.go | 17 +------- frontend/src/pages/MCPPage.tsx | 74 +++------------------------------- 2 files changed, 7 insertions(+), 84 deletions(-) diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index 6bcec50..057466b 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -214,12 +214,8 @@ func main() { mcpServer := mcp.NewMCPServer(repoService, docService) klog.V(6).Info("MCP Server 已初始化") - // 创建 SSE Server 实例并复用(避免每次请求创建新实例) - // 配置 basePath 为 /mcp,使 SSE Server 正确处理 /mcp/sse 和 /mcp/message 路径 - sseServer := server.NewSSEServer(mcpServer.GetServer(), server.WithStaticBasePath("/mcp")) - // 创建 Streamable HTTP Server 实例 - // Streamable HTTP 是 MCP 协议的另一种传输层实现,支持同步 HTTP 响应和流式事件 + // Streamable HTTP 是 MCP 协议的传输层实现,支持同步 HTTP 响应和流式事件 streamableServer := server.NewStreamableHTTPServer(mcpServer.GetServer()) // 启动时清理卡住的任务(超过 10 分钟的运行中任务) @@ -229,21 +225,12 @@ func main() { // 设置路由 r := router.Setup(cfg, repoHandler, taskHandler, docHandler, apiKeyHandler, syncHandler, userRequestHandler, openAPIHandler, activityHandler, agentHandler, chatHandler) - // 添加 MCP SSE 端点 - // 提供 /mcp/sse 端点,供 Cursor、Claude Code 等 AI 编程工具使用 - r.GET("/mcp/sse", func(c *gin.Context) { - sseServer.ServeHTTP(c.Writer, c.Request) - }) - // 添加 /mcp/message 端点,支持客户端发送 JSON-RPC 消息 - r.POST("/mcp/message", func(c *gin.Context) { - sseServer.ServeHTTP(c.Writer, c.Request) - }) // 添加 MCP Streamable HTTP 端点 // Streamable HTTP 使用单个端点处理 GET(流式事件)和 POST(JSON-RPC 请求) r.Any("/mcp/streamable", func(c *gin.Context) { streamableServer.ServeHTTP(c.Writer, c.Request) }) - klog.V(6).Info("MCP 端点已注册: /mcp/sse, /mcp/message, /mcp/streamable") + klog.V(6).Info("MCP 端点已注册: /mcp/streamable") //eino callbacks注册 callbacks := adkagents.NewEinoCallbacks(true, 8) diff --git a/frontend/src/pages/MCPPage.tsx b/frontend/src/pages/MCPPage.tsx index 99efc1d..c473f45 100644 --- a/frontend/src/pages/MCPPage.tsx +++ b/frontend/src/pages/MCPPage.tsx @@ -60,17 +60,6 @@ const mcpTools = [ }, ]; -// MCP 配置文件模板 - SSE 传输 -const getMCPConfigSSE = (baseUrl: string) => ({ - "mcpServers": { - "openDeepWiki": { - "type": "sse", - "url": `${baseUrl}/mcp/sse`, - "timeout": 30000 - } - } -}); - // MCP 配置文件模板 - Streamable HTTP 传输 const getMCPConfigStreamable = (baseUrl: string) => ({ "mcpServers": { @@ -93,9 +82,7 @@ export default function MCPPage() { setBaseUrl(currentUrl); }, []); - const mcpConfigSSE = getMCPConfigSSE(baseUrl || 'http://localhost:8080'); const mcpConfigStreamable = getMCPConfigStreamable(baseUrl || 'http://localhost:8080'); - const configJsonSSE = JSON.stringify(mcpConfigSSE, null, 2); const configJsonStreamable = JSON.stringify(mcpConfigStreamable, null, 2); const handleCopy = async (config: string, type: string) => { @@ -166,18 +153,6 @@ export default function MCPPage() { - SSE - {baseUrl}/mcp/sse - • GET 建立流 - - - - SSE - {baseUrl}/mcp/message - • POST 发送消息 - - - Streamable HTTP {baseUrl}/mcp/streamable • GET 流式 + POST 同步 @@ -205,10 +180,8 @@ export default function MCPPage() { ( @@ -216,7 +189,7 @@ export default function MCPPage() { {item.value} {item.transport && ( - {item.transport} + {item.transport} )} )} @@ -277,43 +250,6 @@ export default function MCPPage() { ), children: ( - - - SSE 配置文件 - - } - extra={ - - } - > - -
-                                            {configJsonSSE}
-                                        
- - @@ -334,7 +270,7 @@ export default function MCPPage() { > 1. Cursor 配置 打开 Cursor Settings → MCP,点击 "Add New MCP Server", - 选择 SSE 类型,填入 URL: {baseUrl}/mcp/sse + 选择 Streamable HTTP 类型,填入 URL: {baseUrl}/mcp/streamable @@ -384,7 +320,7 @@ export default function MCPPage() { 3. Windsurf 配置 打开 Windsurf Settings → AI → MCP, - 添加新的 MCP Server,填入 SSE URL: {baseUrl}/mcp/sse + 添加新的 MCP Server,填入 URL: {baseUrl}/mcp/streamable