From 7742e3da389f665a635537cae85df4a4aedd18ae Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:06:51 +0800 Subject: [PATCH] fix: Fixed issue with mcp externalUrl config failed (#10331) Refs https://github.com/1Panel-dev/1Panel/issues/10323 --- agent/app/service/mcp_server.go | 55 +++++++++++++++------- frontend/src/views/ai/mcp/server/index.vue | 17 +++++-- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/agent/app/service/mcp_server.go b/agent/app/service/mcp_server.go index ddc0c1257..96d724cc7 100644 --- a/agent/app/service/mcp_server.go +++ b/agent/app/service/mcp_server.go @@ -111,11 +111,14 @@ func (m McpServerService) Update(req request.McpServerUpdate) error { mcpServer.Port = req.Port mcpServer.Command = req.Command mcpServer.BaseURL = req.BaseURL - mcpServer.SsePath = req.SsePath mcpServer.HostIP = req.HostIP - mcpServer.StreamableHttpPath = req.StreamableHttpPath mcpServer.OutputTransport = req.OutputTransport mcpServer.Type = req.Type + if req.OutputTransport == "sse" { + mcpServer.SsePath = req.SsePath + } else { + mcpServer.StreamableHttpPath = req.StreamableHttpPath + } if err := handleCreateParams(mcpServer, req.Environments, req.Volumes); err != nil { return err } @@ -163,19 +166,23 @@ func (m McpServerService) Create(create request.McpServerCreate) error { } mcpDir := path.Join(global.Dir.McpDir, create.Name) mcpServer := &model.McpServer{ - Name: create.Name, - ContainerName: create.ContainerName, - Port: create.Port, - Command: create.Command, - Status: constant.StatusStarting, - BaseURL: create.BaseURL, - SsePath: create.SsePath, - Dir: mcpDir, - HostIP: create.HostIP, - StreamableHttpPath: create.StreamableHttpPath, - OutputTransport: create.OutputTransport, - Type: create.Type, + Name: create.Name, + ContainerName: create.ContainerName, + Port: create.Port, + Command: create.Command, + Status: constant.StatusStarting, + BaseURL: create.BaseURL, + Dir: mcpDir, + HostIP: create.HostIP, + OutputTransport: create.OutputTransport, + Type: create.Type, } + if create.OutputTransport == "sse" { + mcpServer.SsePath = create.SsePath + } else { + mcpServer.StreamableHttpPath = create.StreamableHttpPath + } + if err := handleCreateParams(mcpServer, create.Environments, create.Volumes); err != nil { return err } @@ -445,8 +452,14 @@ func addProxy(server *model.McpServer) { if !ok { return } - location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)}) - location.ChangePath("^~", server.SsePath) + var proxyPath string + if server.OutputTransport == "sse" { + proxyPath = server.SsePath + } else { + proxyPath = server.StreamableHttpPath + } + location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, proxyPath)}) + location.ChangePath("^~", proxyPath) if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil { global.LOG.Errorf("write config failed, err: %v", buserr.WithErr("ErrUpdateBuWebsite", err)) return @@ -497,8 +510,14 @@ func addMCPProxy(websiteID uint) error { err = errors.New("error") return err } - location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)}) - location.ChangePath("^~", server.SsePath) + var proxyPath string + if server.OutputTransport == "sse" { + proxyPath = server.SsePath + } else { + proxyPath = server.StreamableHttpPath + } + location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, proxyPath)}) + location.ChangePath("^~", proxyPath) if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil { return buserr.WithErr("ErrUpdateBuWebsite", err) } diff --git a/frontend/src/views/ai/mcp/server/index.vue b/frontend/src/views/ai/mcp/server/index.vue index 623a8ab36..b5da16fa7 100644 --- a/frontend/src/views/ai/mcp/server/index.vue +++ b/frontend/src/views/ai/mcp/server/index.vue @@ -2,7 +2,7 @@
-