{"record":{"id":"bbb9b6dad932c277","repo":"alibaba/nacos","slug":"server-error-bbb9b6","errorCode":"SERVER_ERROR","errorMessage":"Failed to import tools from MCP server","messagePattern":"Failed to import tools from MCP server","errorType":"error_code","errorClass":"NacosException","httpStatus":null,"severity":"error","filePath":"console/src/main/java/com/alibaba/nacos/console/controller/v3/ai/ConsoleMcpController.java","lineNumber":154,"sourceCode":"                    baseUrl).endpoint(endpoint);\n            if (!StringUtils.isBlank(authToken)) {\n                transportBuilder\n                    .customizeRequest(req -> req.header(\"Authorization\", \"Bearer \" + authToken));\n            }\n            transport = transportBuilder.build();\n        } else {\n            return Result.failure(ErrorCode.SERVER_ERROR.getCode(),\n                \"Unsupported transport type: \" + transportType,\n                null);\n        }\n        try (McpSyncClient client =\n            McpClient.sync(transport).requestTimeout(Duration.ofSeconds(10)).build()) {\n            client.initialize();\n            McpSchema.ListToolsResult tools = client.listTools();\n            return Result.success(tools.tools());\n        } catch (Exception e) {\n            // 可以记录日志或抛出 NacosException\n            throw new NacosException(NacosException.SERVER_ERROR,\n                \"Failed to import tools from MCP server\", e);\n        }\n    }\n    \n    /**\n     * Get specified mcp server detail info.\n     *\n     * @param mcpForm get mcp server request form\n     * @return detail info with {@link McpServerDetailInfo}\n     * @throws NacosException any exception during handling\n     */\n    @Since(\"3.0.0\")\n    @GetMapping\n    @Secured(action = ActionTypes.READ, signType = SignType.AI, apiType = ApiType.CONSOLE_API)\n    public Result<McpServerDetailInfo> getMcpServer(McpForm mcpForm) throws NacosException {\n        mcpForm.validate();\n        return Result.success(mcpProxy.getMcpServer(mcpForm.getNamespaceId(), mcpForm.getMcpName(),\n            mcpForm.getMcpId(),","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console/src/main/java/com/alibaba/nacos/console/controller/v3/ai/ConsoleMcpController.java#L136-L172","documentation":"Thrown by ConsoleMcpController when importing tools from an external MCP server fails at any stage (transport build, client.initialize(), or client.listTools()). The controller builds a McpSyncClient with the configured transport and a 10s request timeout; any caught Exception is wrapped in NacosException(SERVER_ERROR, ..., e), HTTP 500. The original cause is preserved as the exception cause.","triggerScenarios":"Calling the MCP tool-import endpoint when the target MCP server is unreachable, the transport type/endpoint is misconfigured, the 10s timeout is exceeded, TLS/cert verification fails, or the MCP server returns an error during initialize or listTools.","commonSituations":"Wrong MCP server URL/port, firewall or DNS blocking the egress connection, an unsupported or mistyped transportType handled by the 'Unsupported transport type' branch just above, slow MCP server exceeding the 10s request timeout, expired/invalid credentials, or the MCP server process being down.","solutions":["Verify the MCP server is reachable from the Nacos server host (TCP connectivity, DNS, port) with the exact transportType/endpoint you submitted.","Inspect the NacosException cause via getCause() to get the real underlying error (connection refused, timeout, auth 401, etc.) and address that.","Check that the transportType is supported and the endpoint URL/args are correct for that transport.","If the import is timing out, confirm the MCP server responds quickly; the client uses a fixed 10s request timeout, so a slow server will fail.","Confirm credentials/TLS config for the MCP server are valid and not expired."],"exampleFix":"// before: caller ignores root cause\ntry {\n    mcpProxy.importTools(form);\n} catch (NacosException e) {\n    log.error(\"import failed: {}\", e.getMessage());\n}\n\n// after: unwrap and act on the real cause\ntry {\n    mcpProxy.importTools(form);\n} catch (NacosException e) {\n    Throwable root = e.getCause() != null ? e.getCause() : e;\n    log.error(\"MCP import failed (transport={}, endpoint={})\",\n        form.getTransportType(), form.getEndpoint(), root);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm the MCP server endpoint is reachable before importing\nString endpoint = form.getEndpoint();\njava.net.URI uri = java.net.URI.create(endpoint);\ntry (java.net.Socket s = new java.net.Socket(uri.getHost(), uri.getPort() > 0 ? uri.getPort() : 80)) {\n    s.setSoTimeout(2000);\n    // socket connected -> endpoint reachable\n} catch (IOException ex) {\n    throw new IllegalArgumentException(\"MCP endpoint unreachable: \" + endpoint, ex);\n}","typeGuard":"// Java: guard the transportType is supported before calling\nSet<String> supported = Set.of(\"stdio\", \"sse\", \"http\");\nboolean ok = supported.contains(form.getTransportType())\n    && form.getEndpoint() != null && !form.getEndpoint().isBlank();","tryCatchPattern":"try {\n    mcpProxy.importTools(form);\n} catch (NacosException e) {\n    if (e.getErrCode() == NacosException.SERVER_ERROR && e.getCause() != null) {\n        Throwable root = e.getCause();\n        // classify: timeout / connect-refused / auth / protocol\n        log.warn(\"MCP import failed ({}): {}\", root.getClass().getSimpleName(), root.getMessage());\n    }\n    throw e;\n}","preventionTips":["Validate the transportType and endpoint are well-formed before calling import.","Keep the MCP server responsive under the 10s request timeout the controller uses.","Inspect getCause() to distinguish network, auth, and protocol failures.","Whitelist Nacos server egress to the MCP host/port in your firewall."],"tags":["network","mcp","ai","server-error","timeout"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}