{"record":{"id":"9d3625de5227d198","repo":"alibaba/nacos","slug":"invalid-url-url","errorCode":null,"errorMessage":"Invalid URL: ${url}","messagePattern":"Invalid URL: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/McpExternalDataAdaptor.java","lineNumber":345,"sourceCode":"                    (components.getPort() > 0) ? components.getPort() : (isHttps ? 443 : 80);\n                String endpointData = components.getHost() + \":\" + effectivePort;\n                FrontEndpointConfig cfg = new FrontEndpointConfig();\n                cfg.setEndpointData(endpointData);\n                cfg.setPath(\n                    StringUtils.isNotBlank(components.getPath()) ? components.getPath() : \"/\");\n                cfg.setType(remote.getType());\n                cfg.setProtocol(components.getScheme());\n                cfg.setEndpointType(AiConstants.Mcp.MCP_FRONT_ENDPOINT_TYPE_TO_BACK);\n                cfg.setHeaders(remote.getHeaders());\n                endpoints.add(cfg);\n                \n                // Use first remote's path as export path\n                if (remoteConfig.getExportPath() == null) {\n                    remoteConfig\n                        .setExportPath(components.getPath() != null ? components.getPath() : \"/\");\n                }\n            } catch (Exception e) {\n                throw new IllegalStateException(\"Invalid URL: \" + url, e);\n            }\n        }\n        \n        remoteConfig.setFrontEndpointConfigList(endpoints);\n        return remoteConfig;\n    }\n    \n    /**\n     * Parse URL into components (scheme, host, port, path).\n     * Manual parsing without using URI class.\n     *\n     * @param url the URL string to parse\n     * @return UrlComponents containing scheme, host, port, and path\n     */\n    private UrlComponents parseUrlComponents(String url) {\n        String scheme = null;\n        String host = null;\n        int port = -1;","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/McpExternalDataAdaptor.java#L327-L363","documentation":"Thrown by McpExternalDataAdaptor.generateRemoteServiceConfig when a remote's URL cannot be parsed into components (scheme/host/port/path). Any exception during parsing is wrapped as IllegalStateException with the offending URL. This happens while adapting registry remotes into Nacos front-endpoint configs.","triggerScenarios":"A registry server detail carries a remote whose url field is malformed (missing scheme, unparseable host, etc.); the URL string is null or lacks '://'; the manual parseUrlComponents logic cannot split it.","commonSituations":"Upstream registry data has a relative or malformed URL; a remote URL uses an unsupported scheme; a migration left an empty url string.","solutions":["Validate each remote URL is absolute with a scheme (http/https) before adapting.","Sanitize/filter registry entries whose url is blank or missing '://'.","Pre-check with new URI(url) client-side and skip or report malformed entries."],"exampleFix":"// before\nremote.setUrl(\"localhost:8080/mcp\"); // no scheme -> parse fails\n\n// after\nremote.setUrl(\"https://localhost:8080/mcp\");","handlingStrategy":"validation","validationCode":"try { URI u = new URI(remote.getUrl()); if (u.getScheme() == null || u.getHost() == null) throw new IllegalArgumentException(\"malformed remote url\"); } catch (URISyntaxException ex) { throw new IllegalArgumentException(ex); }","typeGuard":"boolean isAbsoluteRemote(Remote r) { try { URI u = new URI(r.getUrl()); return u.getScheme() != null && u.getHost() != null; } catch (Exception e) { return false; } }","tryCatchPattern":"try { adaptor.adaptExternalDataToNacosMcpServerFormat(req); }\ncatch (IllegalStateException e) { if (e.getMessage().startsWith(\"Invalid URL\")) skipMalformedRemote(); }","preventionTips":["Filter registry entries whose remote URL lacks a scheme or host.","Pre-validate with java.net.URI before adaptation."],"tags":["mcp","registry","url-parsing","illegal-state"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}