alibaba/nacos · error · IllegalStateException
Invalid URL: ${url}
Error message
Invalid URL: ${url} What it means
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.
Source
Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/McpExternalDataAdaptor.java:345
(components.getPort() > 0) ? components.getPort() : (isHttps ? 443 : 80);
String endpointData = components.getHost() + ":" + effectivePort;
FrontEndpointConfig cfg = new FrontEndpointConfig();
cfg.setEndpointData(endpointData);
cfg.setPath(
StringUtils.isNotBlank(components.getPath()) ? components.getPath() : "/");
cfg.setType(remote.getType());
cfg.setProtocol(components.getScheme());
cfg.setEndpointType(AiConstants.Mcp.MCP_FRONT_ENDPOINT_TYPE_TO_BACK);
cfg.setHeaders(remote.getHeaders());
endpoints.add(cfg);
// Use first remote's path as export path
if (remoteConfig.getExportPath() == null) {
remoteConfig
.setExportPath(components.getPath() != null ? components.getPath() : "/");
}
} catch (Exception e) {
throw new IllegalStateException("Invalid URL: " + url, e);
}
}
remoteConfig.setFrontEndpointConfigList(endpoints);
return remoteConfig;
}
/**
* Parse URL into components (scheme, host, port, path).
* Manual parsing without using URI class.
*
* @param url the URL string to parse
* @return UrlComponents containing scheme, host, port, and path
*/
private UrlComponents parseUrlComponents(String url) {
String scheme = null;
String host = null;
int port = -1;View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before
remote.setUrl("localhost:8080/mcp"); // no scheme -> parse fails
// after
remote.setUrl("https://localhost:8080/mcp"); Defensive patterns
Strategy: validation
Validate before calling
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); } Type guard
boolean isAbsoluteRemote(Remote r) { try { URI u = new URI(r.getUrl()); return u.getScheme() != null && u.getHost() != null; } catch (Exception e) { return false; } } Try / catch
try { adaptor.adaptExternalDataToNacosMcpServerFormat(req); }
catch (IllegalStateException e) { if (e.getMessage().startsWith("Invalid URL")) skipMalformedRemote(); } Prevention
- Filter registry entries whose remote URL lacks a scheme or host.
- Pre-validate with java.net.URI before adaptation.
When it happens
Trigger: 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.
Common situations: Upstream registry data has a relative or malformed URL; a remote URL uses an unsupported scheme; a migration left an empty url string.
Related errors
- MCP server not found in registry: ${externalId}
- HTTP ${code} when fetching ${pageUrl}
- Failed to parse response body
- URL is blank
- MCP server external id is blank
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/9d3625de5227d198.
Report an issue: GitHub.