{"record":{"id":"4de122c94201556f","repo":"apache/shenyu","slug":"import-mcp-server-config-failed","errorCode":null,"errorMessage":"Import mcp server config failed: ","messagePattern":"Import mcp server config failed: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java","lineNumber":146,"sourceCode":"            validateSwaggerUrl(request.getSwaggerUrl());\n\n            String swaggerJson = fetchSwaggerDoc(request.getSwaggerUrl());\n\n            String namespaceId = StringUtils.defaultIfEmpty(request.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID);\n            List<McpToolsRegisterDTO> mcpToolsRegisterDTOList = buildMcpToolRegisterDTO(swaggerJson, namespaceId);\n\n            mcpToolsRegisterDTOList.forEach(mcpToolsRegisterDTO -> {\n                shenyuClientRegisterMcpService.registerMcpTools(mcpToolsRegisterDTO);\n            });\n\n            return \"Import mcp server config successful, supports Swagger 2.0 and OpenAPI 3.0 formats\";\n        } catch (IllegalArgumentException e) {\n            // Keep bad user input unwrapped so the controller can return HTTP 400.\n            LOG.error(\"Failed to import mcp config: {}\", request.getProjectName(), e);\n            throw e;\n        } catch (IOException e) {\n            LOG.error(\"Failed to import mcp config: {}\", request.getProjectName(), e);\n            throw new RuntimeException(\"Import mcp server config failed: \" + e.getMessage(), e);\n        }\n\n    }\n\n    private List<McpToolsRegisterDTO> buildMcpToolRegisterDTO(final String swaggerJson, final String namespaceId) {\n        ArrayList<McpToolsRegisterDTO> mcpToolsRegisterDTOList = new ArrayList<>();\n        OpenAPI openapi = new OpenAPIV3Parser().readContents(swaggerJson, null, null).getOpenAPI();\n        Map<String, List<Map<String, ShenyuMcpTool>>> mcpToolMap = buildShenyuMcpTool(openapi);\n        JsonObject openApiJsonObject = JsonParser.parseString(swaggerJson).getAsJsonObject();\n        mcpToolMap.forEach((selectorName, mcpToolList) -> {\n            mcpToolList.forEach(shenyuMcpToolMap -> {\n                shenyuMcpToolMap.forEach((url, shenyuMcpTool) -> {\n                    McpToolsRegisterDTO mcpToolsRegisterDTO = McpToolsRegisterDTOGenerator.generateRegisterDTO(shenyuMcpTool, openApiJsonObject, url, namespaceId);\n\n                    mcpToolsRegisterDTO.setMetaDataRegisterDTO(buildMetaDataRegisterDTO(openapi, selectorName, shenyuMcpTool, url, namespaceId));\n                    mcpToolsRegisterDTOList.add(mcpToolsRegisterDTO);\n                });\n            });","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java#L128-L164","documentation":"importMcpConfig() wraps IOExceptions from the MCP config import into a RuntimeException with the prefix 'Import mcp server config failed: '. This happens when reading or fetching the swagger document for MCP tool registration fails at the IO level. IllegalArgumentException (validation) is re-thrown unwrapped for HTTP 400 handling.","triggerScenarios":"Calling the MCP config import API (SwaggerImportServiceImpl.importMcpConfig) when fetchSwaggerDoc or body reading throws IOException: the swagger URL host is unreachable, connection reset, or reading the response body fails.","commonSituations":"Target backend service is down or misconfigured URL; DNS failure or firewall blocking the admin server; network timeouts when fetching a large swagger document; proxy misconfiguration in the admin environment.","solutions":["Check the cause chain for the IOException message (Connection refused, UnknownHost, timeout) and fix the network/URL issue.","Verify swaggerUrl points to a live, reachable endpoint from the admin server host.","Retry the import after network connectivity is restored — this error is often transient.","For planned unavailability, pre-validate reachability before invoking the import API."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"InetAddress addr = InetAddress.getByName(URI.create(swaggerUrl).getHost());\nif (!addr.isReachable(3000)) throw new IllegalStateException(\"swagger host unreachable before MCP import\");","typeGuard":null,"tryCatchPattern":"try {\n    service.importMcpConfig(request);\n} catch (IllegalArgumentException e) {\n    return ResponseEntity.badRequest().body(e.getMessage());\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException) { scheduleRetry(request); } // transient network\n    throw e;\n}","preventionTips":["Check network/DNS/firewall from the admin host before imports.","Treat IOException-caused failures as transient and retry with backoff.","Monitor target service health before scheduling bulk MCP imports.","Keep swagger documents under the configured max body size to avoid truncation IO errors."],"tags":["mcp","swagger","ioexception","network"],"backgroundTag":"http-request-failed","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}