alibaba/nacos · error · IllegalArgumentException
Agent Version mediaType must be {AGENT_VERSION_MEDIA_TYPE}
Error message
Agent Version mediaType must be {AGENT_VERSION_MEDIA_TYPE} What it means
The mediaType field must equal exactly 'application/vnd.nacos.agent-version+json' (AgentVersionStorageDescriptor.MEDIA_TYPE). Any other value, including null or generic 'application/json', is rejected. The media type pins the descriptor payload format.
Source
Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/agent/storage/AgentVersionStorageDescriptorSerializer.java:169
*/
public static void validate(AgentVersionStorageDescriptor descriptor) {
if (descriptor == null) {
throw new IllegalArgumentException("Agent Version storage descriptor must not be null");
}
String provider = descriptor.getProvider();
if (provider == null || provider.length() > MAX_PROVIDER_LENGTH
|| !PROVIDER_PATTERN.matcher(provider).matches()) {
throw new IllegalArgumentException("Invalid Agent Version storage provider");
}
validateRequiredText("key", descriptor.getKey(), MAX_KEY_LENGTH);
validateOptionalText("keyFormat", descriptor.getKeyFormat(), MAX_FORMAT_LENGTH);
validateOptionalText("agentNameCodec", descriptor.getAgentNameCodec(), MAX_FORMAT_LENGTH);
if (descriptor.getContentDigest() == null
|| !DIGEST_PATTERN.matcher(descriptor.getContentDigest()).matches()) {
throw new IllegalArgumentException("Invalid Agent Version contentDigest");
}
if (!AGENT_VERSION_MEDIA_TYPE.equals(descriptor.getMediaType())) {
throw new IllegalArgumentException("Agent Version mediaType must be "
+ AGENT_VERSION_MEDIA_TYPE);
}
if (!Integer.valueOf(SCHEMA_VERSION).equals(descriptor.getSchemaVersion())) {
throw new IllegalArgumentException("Agent Version storage schemaVersion must be "
+ SCHEMA_VERSION);
}
Long size = descriptor.getSize();
if (size == null || size < 0 || size > MAX_CONTENT_SIZE) {
throw new IllegalArgumentException(
"Agent Version storage size must be between 0 and " + MAX_CONTENT_SIZE);
}
if (NACOS_CONFIG_PROVIDER.equals(provider)) {
if (!NACOS_CONFIG_KEY_FORMAT.equals(descriptor.getKeyFormat())) {
throw new IllegalArgumentException("nacos_config keyFormat must be "
+ NACOS_CONFIG_KEY_FORMAT);
}
if (!RAD_ASCII_AGENT_NAME_CODEC.equals(descriptor.getAgentNameCodec())) {
throw new IllegalArgumentException("nacos_config agentNameCodec must be "View on GitHub (pinned to 9b989acdf1)
Solutions
- Set mediaType to AgentVersionStorageDescriptor.MEDIA_TYPE
- Use AgentVersionStorageService.buildDescriptor/buildReplacementDescriptor, which set it correctly
- Re-publish the version to regenerate the descriptor
Example fix
// before
descriptor.setMediaType("application/json");
// after
descriptor.setMediaType(AgentVersionStorageDescriptor.MEDIA_TYPE); Defensive patterns
Strategy: validation
Validate before calling
if (!AgentVersionStorageDescriptor.MEDIA_TYPE.equals(descriptor.getMediaType())) {
descriptor.setMediaType(AgentVersionStorageDescriptor.MEDIA_TYPE);
} Prevention
- Use AgentVersionStorageService.buildDescriptor, which sets mediaType correctly
- Reference the MEDIA_TYPE constant, never a hardcoded string
When it happens
Trigger: validate()/serialize() on a descriptor whose mediaType is null, "application/json", or any other string. Fires on a stale/corrupted row too.
Common situations: Hardcoding 'application/json'; leaving mediaType unset; a descriptor from an older Nacos version that used a different media type.
Related errors
- Agent Version storage descriptor JSON must not be empty
- Agent Version storage descriptor must be a JSON object
- Unknown Agent Version storage descriptor field: {fieldName}
- Agent Version storage descriptor must not be null
- Invalid Agent Version storage provider
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/cfadc0cea3ef21bd.
Report an issue: GitHub.