alibaba/nacos · error · IllegalArgumentException

Unknown mimeType: {value}

Error message

Unknown mimeType: {value}

What it means

Icon.MimeType.fromValue (a Jackson @JsonCreator) iterates all enum constants and throws IllegalArgumentException when the input string does not case-insensitively match any of: image/png, image/jpeg, image/jpg, image/svg+xml, image/webp. This fires during JSON deserialization of an Icon object with an unsupported mime type.

Source

Thrown at api/src/main/java/com/alibaba/nacos/api/ai/model/mcp/registry/Icon.java:184

        @JsonValue
        public String getValue() {
            return value;
        }
        
        /**
         * Create from value.
         *
         * @param value value
         * @return MimeType
         */
        @JsonCreator
        public static MimeType fromValue(String value) {
            for (MimeType t : MimeType.values()) {
                if (t.value.equalsIgnoreCase(value)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Unknown mimeType: " + value);
        }
    }
    
    /**
     * Theme enum: light or dark.
     * Serialized/deserialized as the lowercase string value.
     */
    public static enum Theme {
        
        /**
         * Light theme.
         */
        LIGHT("light"),
        /**
         * Dark theme.
         */
        DARK("dark");
        

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Map or filter the incoming mime type to one of the five supported values before serialization.
  2. If you control the icon source, convert images to PNG, JPEG, or WebP.
  3. Trim whitespace from the value before deserialization.
  4. Configure Jackson with a coercionConfig or custom deserializer to handle unknown mime types gracefully.

Example fix

// before
{ "src": "icon.gif", "mimeType": "image/gif" } // throws on parse

// after
{ "src": "icon.png", "mimeType": "image/png" } // ok

// Or pre-process:
String mt = rawMimeType != null ? rawMimeType.trim() : "image/png";
if (!Set.of("image/png","image/jpeg","image/jpg","image/svg+xml","image/webp")
        .contains(mt.toLowerCase())) {
    mt = "image/png";
}
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> VALID_MIME_TYPES = Set.of(
    "image/png", "image/jpeg", "image/jpg", "image/svg+xml", "image/webp");

String normalized = rawMimeType == null ? null : rawMimeType.trim().toLowerCase();
if (!VALID_MIME_TYPES.contains(normalized)) {
    normalized = "image/png"; // or reject
}

Type guard

public static boolean isValidMimeType(String value) {
    if (value == null) return false;
    String v = value.trim().toLowerCase();
    return Set.of("image/png","image/jpeg","image/jpg","image/svg+xml","image/webp").contains(v);
}

Try / catch

try {
    Icon icon = objectMapper.readValue(json, Icon.class);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Unknown mimeType")) {
        // normalize mimeType and retry, or return 400
    }
    throw e;
}

Prevention

When it happens

Trigger: Deserializing a JSON payload containing an icon with a mimeType like 'image/gif', 'image/x-icon', 'application/octet-stream', or a typo like 'image/png '. The match is case-insensitive but exact otherwise.

Common situations: A third-party MCP registry or external system sends an icon with a mime type not in the allowed set. A user uploads a .gif or .ico file and the client sends its mime type verbatim. Whitespace or encoding artifacts in the JSON value.

Related errors


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