alibaba/nacos · error · NacosException

SERVER_ERROR

SERVER_ERROR

Error message

Failed to import tools from MCP server

What it means

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.

Source

Thrown at console/src/main/java/com/alibaba/nacos/console/controller/v3/ai/ConsoleMcpController.java:154

                    baseUrl).endpoint(endpoint);
            if (!StringUtils.isBlank(authToken)) {
                transportBuilder
                    .customizeRequest(req -> req.header("Authorization", "Bearer " + authToken));
            }
            transport = transportBuilder.build();
        } else {
            return Result.failure(ErrorCode.SERVER_ERROR.getCode(),
                "Unsupported transport type: " + transportType,
                null);
        }
        try (McpSyncClient client =
            McpClient.sync(transport).requestTimeout(Duration.ofSeconds(10)).build()) {
            client.initialize();
            McpSchema.ListToolsResult tools = client.listTools();
            return Result.success(tools.tools());
        } catch (Exception e) {
            // 可以记录日志或抛出 NacosException
            throw new NacosException(NacosException.SERVER_ERROR,
                "Failed to import tools from MCP server", e);
        }
    }
    
    /**
     * Get specified mcp server detail info.
     *
     * @param mcpForm get mcp server request form
     * @return detail info with {@link McpServerDetailInfo}
     * @throws NacosException any exception during handling
     */
    @Since("3.0.0")
    @GetMapping
    @Secured(action = ActionTypes.READ, signType = SignType.AI, apiType = ApiType.CONSOLE_API)
    public Result<McpServerDetailInfo> getMcpServer(McpForm mcpForm) throws NacosException {
        mcpForm.validate();
        return Result.success(mcpProxy.getMcpServer(mcpForm.getNamespaceId(), mcpForm.getMcpName(),
            mcpForm.getMcpId(),

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Verify the MCP server is reachable from the Nacos server host (TCP connectivity, DNS, port) with the exact transportType/endpoint you submitted.
  2. Inspect the NacosException cause via getCause() to get the real underlying error (connection refused, timeout, auth 401, etc.) and address that.
  3. Check that the transportType is supported and the endpoint URL/args are correct for that transport.
  4. 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.
  5. Confirm credentials/TLS config for the MCP server are valid and not expired.

Example fix

// before: caller ignores root cause
try {
    mcpProxy.importTools(form);
} catch (NacosException e) {
    log.error("import failed: {}", e.getMessage());
}

// after: unwrap and act on the real cause
try {
    mcpProxy.importTools(form);
} catch (NacosException e) {
    Throwable root = e.getCause() != null ? e.getCause() : e;
    log.error("MCP import failed (transport={}, endpoint={})",
        form.getTransportType(), form.getEndpoint(), root);
    throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: confirm the MCP server endpoint is reachable before importing
String endpoint = form.getEndpoint();
java.net.URI uri = java.net.URI.create(endpoint);
try (java.net.Socket s = new java.net.Socket(uri.getHost(), uri.getPort() > 0 ? uri.getPort() : 80)) {
    s.setSoTimeout(2000);
    // socket connected -> endpoint reachable
} catch (IOException ex) {
    throw new IllegalArgumentException("MCP endpoint unreachable: " + endpoint, ex);
}

Type guard

// Java: guard the transportType is supported before calling
Set<String> supported = Set.of("stdio", "sse", "http");
boolean ok = supported.contains(form.getTransportType())
    && form.getEndpoint() != null && !form.getEndpoint().isBlank();

Try / catch

try {
    mcpProxy.importTools(form);
} catch (NacosException e) {
    if (e.getErrCode() == NacosException.SERVER_ERROR && e.getCause() != null) {
        Throwable root = e.getCause();
        // classify: timeout / connect-refused / auth / protocol
        log.warn("MCP import failed ({}): {}", root.getClass().getSimpleName(), root.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/bbb9b6dad932c277. Report an issue: GitHub.