alibaba/nacos · error · NacosApiException
20002
20002
Error message
importType must be one of: json, url, file
What it means
Thrown by McpImportForm.validate() when importType is non-empty but does not match any ExternalDataTypeEnum (json/url/file). The match is case-SENSITIVE exact (parseType uses equals, not equalsIgnoreCase), unlike the scope checks. Maps to code 20002 (PARAMETER_VALIDATE_ERROR), HTTP 400. Part of the @Deprecated legacy MCP import flow (removal planned 3.4.0).
Source
Thrown at ai/src/main/java/com/alibaba/nacos/ai/form/mcp/admin/McpImportForm.java:83
/**
* Optional fuzzy search keyword for registry import listing.
* Only used when importType is 'url'.
*/
private String search;
@Override
public void validate() throws NacosApiException {
fillDefaultValue();
if (StringUtils.isEmpty(importType)) {
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
"Required parameter 'importType' is not present");
}
if (StringUtils.isEmpty(data)) {
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
"Required parameter 'data' is not present");
}
if (ExternalDataTypeEnum.parseType(importType) == null) {
throw new NacosApiException(NacosException.INVALID_PARAM,
ErrorCode.PARAMETER_VALIDATE_ERROR,
"importType must be one of: json, url, file");
}
}
public String getImportType() {
return importType;
}
public void setImportType(String importType) {
this.importType = importType;
}
public String getData() {
return data;
}
public void setData(String data) {View on GitHub (pinned to 9b989acdf1)
Solutions
- Set importType to exactly one lowercase value: json, url, or file (case-sensitive).
- If accepting user input, validate against the enum before sending.
- Migrate to /v3/admin/ai/import.
Example fix
// before (fails — case sensitive) importType=JSON // after importType=json
Defensive patterns
Strategy: validation
Validate before calling
if (!Set.of("json","url","file").contains(importType)) {
throw new IllegalArgumentException("importType must be json, url, or file (case-sensitive)");
} Type guard
static boolean isKnownImportType(String t) {
return "json".equals(t) || "url".equals(t) || "file".equals(t);
} Try / catch
catch (NacosApiException e) {
if (e.getErrCode() == 20002 && e.getMessage().contains("importType")) { /* use lowercase enum */ }
} Prevention
- Remember importType is case-SENSITIVE (lowercase only).
- Map any user-facing choice to the exact enum string.
When it happens
Trigger: Calling the MCP import endpoint with importType=JSON, importType=csv, importType=http, or any value other than the lowercase json/url/file.
Common situations: Client uppercases the enum; uses 'http' instead of 'url'; passes a free-form string from user input.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/e1293d3469fcd1b3.
Report an issue: GitHub.