@@ -239,3 +239,30 @@ def create_endpoint(name, nsref, transport='SSE', extra=None):
239239 if not (name and nsref ): continue
240240 extra = {k : ep [k ] for k in ('enableApiKeyAuth' ,'enableOauth' ,'useQueryParamAuth' ) if k in ep }
241241 create_endpoint (name , nsref , ep .get ('transport' ), extra )
242+
243+ # Post-fix auto-generated endpoint servers URLs when APP_URL pointed to 12008 at creation time.
244+ # Newer MetaMCP creates a server named '<namespace>-endpoint' per endpoint and derives its URL from APP_URL.
245+ # If APP_URL used the frontend port (12008), the server URL points to the wrong port.
246+ # We normalize such servers to backend port 12009 so connections succeed in-cluster.
247+ try :
248+ def list_servers ():
249+ r = trpc_get ('/trpc/frontend/frontend.mcpServers.list?input=%7B%7D' )
250+ return r .json ().get ('result' ,{}).get ('data' ,{}).get ('data' ,[]) if r .ok else []
251+ svcs = list_servers ()
252+ # Build namespace->server endpoint name mapping ("<ns>-endpoint")
253+ ns_names = [ns .get ('name' ) for ns in namespaces if ns .get ('name' )]
254+ desired = []
255+ for ns in ns_names :
256+ sname = f"{ ns } -endpoint"
257+ for s in svcs :
258+ if s .get ('name' ) == sname and s .get ('type' ) == 'STREAMABLE_HTTP' :
259+ desired .append ((s , ns ))
260+ for s , ns in desired :
261+ url = s .get ('url' ) or ''
262+ if ':12008/metamcp/' in url :
263+ # rewrite to backend port
264+ fixed = url .replace (':12008/metamcp/' , ':12009/metamcp/' )
265+ payload = {'uuid' : s ['uuid' ], 'name' : s ['name' ], 'type' : s ['type' ], 'url' : fixed }
266+ trpc_post ('/trpc/frontend/frontend.mcpServers.update' , payload )
267+ except Exception :
268+ pass
0 commit comments