From 3f67b05fabcccc977b245b6d9ad4daf031388ccb Mon Sep 17 00:00:00 2001 From: EricaLiu <30773688+Erica177@users.noreply.github.com> Date: Fri, 9 May 2025 14:03:31 +0800 Subject: [PATCH] fix : fix vs rewrite when mcp protocol is http (#2203) --- registry/nacos/mcpserver/watcher.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/registry/nacos/mcpserver/watcher.go b/registry/nacos/mcpserver/watcher.go index 3b47fd381..73f66eaf4 100644 --- a/registry/nacos/mcpserver/watcher.go +++ b/registry/nacos/mcpserver/watcher.go @@ -689,7 +689,7 @@ func (w *watcher) getServiceCallback(server *provider.McpServer, configGroup, da Meta: config.Meta{ GroupVersionKind: gvk.ServiceEntry, Name: fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedSeName, configGroup, strings.TrimSuffix(dataId, ".json")), - Namespace: w.namespace, + Namespace: "mcp", }, Spec: serviceEntry, } @@ -706,12 +706,12 @@ func (w *watcher) getServiceCallback(server *provider.McpServer, configGroup, da w.cache.UpdateConfigCache(gvk.DestinationRule, configKey, dr, false) } w.cache.UpdateConfigCache(gvk.ServiceEntry, configKey, se, false) - vs := w.buildVirtualServiceForMcpServer(serviceEntry, configGroup, dataId, path, server.Name) + vs := w.buildVirtualServiceForMcpServer(serviceEntry, configGroup, dataId, path, server) w.cache.UpdateConfigCache(gvk.VirtualService, configKey, vs, false) } } -func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.ServiceEntry, group, dataId, path, serverName string) *config.Config { +func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.ServiceEntry, group, dataId, path, server *provider.McpServer) *config.Config { if serviceentry == nil { return nil } @@ -728,7 +728,7 @@ func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.Service common2.CreateConvertedName(constants.IstioIngressGatewayName, cleanHost)) } routeName := fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedHttpRouteName, group, strings.TrimSuffix(dataId, ".json")) - mergePath := "/" + serverName + mergePath := "/" + server.Name if w.McpServerBaseUrl != "/" { mergePath = strings.TrimSuffix(w.McpServerBaseUrl, "/") + mergePath } @@ -762,6 +762,12 @@ func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.Service }}, } + if server.Protocol == provider.McpStreambleProtocol { + vs.Http[0].Rewrite = &v1alpha3.HTTPRewrite{ + Uri: path, + } + } + mcpServerLog.Debugf("construct virtualservice %v", vs) return &config.Config{