{"record":{"id":"adfe7235609ffcc0","repo":"alibaba/nacos","slug":"failed-to-convert-to-endpoint-spec","errorCode":null,"errorMessage":"Failed to convert to endpoint spec","messagePattern":"Failed to convert to endpoint spec","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/McpServerImportService.java","lineNumber":320,"sourceCode":"    private McpEndpointSpec generateEndpointSpec(McpServerDetailInfo server) {\n        if (AiConstants.Mcp.MCP_PROTOCOL_STDIO.equals(server.getProtocol())) {\n            return null;\n        }\n        \n        if (server.getRemoteServerConfig() == null\n            || CollectionUtils\n                .isEmpty(server.getRemoteServerConfig().getFrontEndpointConfigList())) {\n            return null;\n        }\n        \n        try {\n            FrontEndpointConfig first = server.getRemoteServerConfig()\n                .getFrontEndpointConfigList()\n                .get(0);\n            return McpConfigUtils.convertFrontEndpointConfig(first);\n        } catch (Exception e) {\n            LOG.error(\"Failed to convert to endpoint spec\", e);\n            throw new RuntimeException(\"Failed to convert to endpoint spec\", e);\n        }\n    }\n}\n","sourceCodeStart":302,"sourceCodeEnd":324,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/McpServerImportService.java#L302-L324","documentation":"Thrown by McpServerImportService.generateEndpointSpec when converting the first FrontEndpointConfig of an imported MCP server into an McpEndpointSpec fails for any reason. The original exception is logged and rethrown as a RuntimeException, aborting the import of that server.","triggerScenarios":"During import, a non-stdio server has a remoteServerConfig with a frontEndpointConfigList, but McpConfigUtils.convertFrontEndpointConfig(first) throws (e.g. malformed endpoint data, missing address/port, unsupported endpoint type).","commonSituations":"Imported registry server has an endpoint whose endpointData is not host:port; a front endpoint type the converter does not handle; address field blank or non-numeric port.","solutions":["Inspect the imported server's frontEndpointConfigList[0] for a valid host:port endpointData and type.","Pre-validate endpoint fields (address, port, type) before triggering the import.","Catch the RuntimeException per-server in the import loop and report the item as failed rather than aborting the whole batch."],"exampleFix":"// before\n// imported server endpoint has endpointData = \"not-a-valid-endpoint\"\n\n// after\nFrontEndpointConfig cfg = server.getRemoteServerConfig().getFrontEndpointConfigList().get(0);\nif (!cfg.getEndpointData().matches(\".+:[0-9]+\")) {\n    reportInvalid(server, \"endpointData must be host:port\");\n}","handlingStrategy":"try-catch","validationCode":"FrontEndpointConfig cfg = server.getRemoteServerConfig().getFrontEndpointConfigList().get(0);\nif (cfg.getEndpointData() == null || !cfg.getEndpointData().matches(\".+:[0-9]+\")) {\n    throw new IllegalArgumentException(\"invalid endpointData: \" + cfg.getEndpointData());\n}","typeGuard":"boolean validFirstEndpoint(McpServerDetailInfo s) {\n    if (s.getRemoteServerConfig() == null) return true;\n    List<FrontEndpointConfig> l = s.getRemoteServerConfig().getFrontEndpointConfigList();\n    if (l == null || l.isEmpty()) return true;\n    String d = l.get(0).getEndpointData();\n    return d != null && d.matches(\".+:[0-9]+\");\n}","tryCatchPattern":"try { service.importValidatedServer(ns, item, override); }\ncatch (RuntimeException e) { if (e.getMessage().contains(\"endpoint spec\")) markItemFailed(item, e); }","preventionTips":["Pre-validate endpoint address/port of imported servers before conversion.","Wrap per-server import in try/catch so one bad endpoint does not abort the batch."],"tags":["mcp","import","conversion","runtime-exception"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}