apache/shenyu · error · IllegalArgumentException
OpenAPI methodType cannot be null or empty
Error message
OpenAPI methodType cannot be null or empty
What it means
McpServiceEventListener.validateClientConfig also requires the ShenyuMcpTool's method (HTTP methodType, e.g. GET/POST) to be non-blank. When blank it logs a hint about OpenApiConfig and throws IllegalArgumentException, preventing registration of a tool with no HTTP method.
Solutions
- Set methodType (GET/POST/etc.) on the OpenApiConfig of each @ShenyuMcpTool
- Validate tool DTOs before registration to catch blanks early
- Check logs for 'OpenAPI methodType is null or empty' to find the offending tool
- Regenerate tool definitions from the OpenAPI spec preserving operation methods
Example fix
// before @OpenApiConfig(pathKey = "/weather") // after @OpenApiConfig(pathKey = "/weather", methodType = "GET")
Defensive patterns
Strategy: validation
Validate before calling
if (tool.getOpenApiConfig() == null || StringUtils.isBlank(tool.getOpenApiConfig().getMethodType())) {
throw new IllegalStateException("@ShenyuMcpTool " + tool.getName() + " missing OpenApiConfig methodType");
} Try / catch
try { listener.buildMcpToolsRegisterDTO(tool); }
catch (IllegalArgumentException e) {
log.error("MCP tool config invalid: {}", e.getMessage());
} Prevention
- Always set methodType on OpenApiConfig
- Validate tool definitions against the OpenAPI spec before registration
- Keep generated tool configs in sync with spec operation methods
When it happens
Trigger: Building MCP tools register DTOs when the @ShenyuMcpTool's OpenApiConfig methodType is null or empty while pathKey is valid.
Common situations: Tool configs hand-written without methodType; spec conversion dropping the http method; annotation attributes left at defaults that resolve to empty.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- OpenAPI pathKey cannot be null or empty
- OpenAPI document is missing the top-level 'servers' field…
- Unsupported Swagger version, only Swagger 2.0 and OpenAPI…
- client register param must config the appName or contextPath
- The configuration shenyu.discovery.serverList in xml/yml…
AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12).
Data as JSON: /api/errors/1b852c11d2dada4e.
Report an issue: GitHub.
Appendix: source
Thrown at shenyu-client/shenyu-client-mcp/shenyu-client-mcp-register/src/main/java/org/apache/shenyu/client/mcp/McpServiceEventListener.java:383
final String url, final String namespaceId) {
validateClientConfig(shenyuMcpTool, url);
JsonObject openApiJson = McpOpenApiGenerator.generateOpenApiJson(classShenyuClient, shenyuMcpTool, url);
McpToolsRegisterDTO mcpToolsRegisterDTO = McpToolsRegisterDTOGenerator.generateRegisterDTO(shenyuMcpTool, openApiJson, url, namespaceId);
MetaDataRegisterDTO metaDataRegisterDTO = buildMetaDataDTO(bean, classShenyuClient, url, clazz, method, namespaceId);
metaDataRegisterDTO.setEnabled(shenyuMcpTool.getEnable());
mcpToolsRegisterDTO.setMetaDataRegisterDTO(metaDataRegisterDTO);
return mcpToolsRegisterDTO;
}
private void validateClientConfig(final org.apache.shenyu.client.mcp.common.dto.ShenyuMcpTool methodShenyuClient, final String url) {
if (StringUtils.isBlank(url)) {
log.error("OpenAPI pathKey is null or empty, please check OpenApiConfig");
throw new IllegalArgumentException("OpenAPI pathKey cannot be null or empty");
}
if (StringUtils.isBlank(methodShenyuClient.getMethod())) {
log.error("OpenAPI methodType is null or empty, please check OpenApiConfig");
throw new IllegalArgumentException("OpenAPI methodType cannot be null or empty");
}
}
}
View on GitHub (pinned to 567142e072)