apache/shardingsphere · error · MCPInvalidRequestException
object_types must be an array.
Error message
object_types must be an array.
What it means
Thrown by MCPToolArguments.getObjectTypes when the object_types argument is present but is not a JSON array/Collection (e.g. a plain string or number). The metadata tool API expects object_types to be an array of strings; a scalar is treated as a malformed request (MCPInvalidRequestException), not coerced.
Source
Thrown at mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/tool/request/MCPToolArguments.java:56
@RequiredArgsConstructor
public final class MCPToolArguments {
private final Map<String, Object> arguments;
/**
* Get object types.
*
* @param supportedObjectTypes supported object types
* @return object types
* @throws MCPInvalidRequestException object types is malformed or unsupported
*/
public Set<SupportedMCPMetadataObjectType> getObjectTypes(final Set<SupportedMCPMetadataObjectType> supportedObjectTypes) {
Object rawValue = arguments.get("object_types");
if (null == rawValue) {
return Collections.emptySet();
}
if (!(rawValue instanceof Collection)) {
throw new MCPInvalidRequestException("object_types must be an array.");
}
Collection<?> objectTypes = (Collection<?>) rawValue;
if (objectTypes.isEmpty()) {
return Collections.emptySet();
}
Set<SupportedMCPMetadataObjectType> result = new LinkedHashSet<>(objectTypes.size(), 1F);
for (Object each : objectTypes) {
result.add(resolveObjectType(each, supportedObjectTypes));
}
return result;
}
private SupportedMCPMetadataObjectType resolveObjectType(final Object objectType, final Set<SupportedMCPMetadataObjectType> supportedObjectTypes) {
String actualValue = Objects.toString(objectType, "").trim();
if (actualValue.isEmpty()) {
throw new MCPInvalidRequestException("object_types cannot contain blank values.");
}
try {View on GitHub (pinned to e952770a21)
Solutions
- Send object_types as a JSON array of strings: {"object_types": ["table", "view"]}
- Split comma-joined values into array elements on the client before sending
- Validate the argument shape in your client schema before invoking the tool
Example fix
// before
list_metadata({"object_types": "table"})
// after
list_metadata({"object_types": ["table"]}) Defensive patterns
Strategy: type-guard
Validate before calling
Object o = arguments.get("object_types");
if (o != null && !(o instanceof Collection)) {
arguments.put("object_types", o instanceof String s && s.contains(",")
? Arrays.asList(s.split(",")) : List.of(o));
} Type guard
// TypeScript — narrow before sending
function isStringArray(v: unknown): v is string[] {
return Array.isArray(v) && v.every(x => typeof x === "string");
}
if (!isStringArray(args.object_types)) args.object_types = [String(args.object_types)]; Try / catch
try {
listMetadata(arguments);
} catch (MCPInvalidRequestException e) {
if (e.getMessage().contains("must be an array")) listMetadata(Map.of("object_types", List.of(String.valueOf(arguments.get("object_types")))));
} Prevention
- Always serialize object_types as a JSON array
- Type-check MCP argument payloads against the tool schema client-side
When it happens
Trigger: arguments.get("object_types") is non-null but not an instanceof Collection — e.g. {"object_types": "table"} instead of {"object_types": ["table"]}, or object_types: 5. JSON arrays arrive as List, scalars do not.
Common situations: LLM agents collapsing a single-value list into a bare string; clients built from loosely typed maps; passing a comma-joined string "table,view" instead of an array.
Related errors
- object_types cannot contain blank values.
- Unsupported object_types value `%s`.
- Statement is not a transaction command.
- %s must be an integer between %d and %d.
- Metadata introspection SQL should use MCP metadata resources
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/5bdbf749f3ae3021.
Report an issue: GitHub.