{"record":{"id":"a629c1bc72e96c03","repo":"apache/shenyu","slug":"openapi-pathkey-cannot-be-null-or-empty","errorCode":null,"errorMessage":"OpenAPI pathKey cannot be null or empty","messagePattern":"OpenAPI pathKey cannot be null or empty","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-client/shenyu-client-mcp/shenyu-client-mcp-register/src/main/java/org/apache/shenyu/client/mcp/McpServiceEventListener.java","lineNumber":378,"sourceCode":"\n    private McpToolsRegisterDTO buildMcpToolsRegisterDTO(final Object bean, final Class<?> clazz,\n                                                         final ShenyuMcpTool classShenyuClient,\n                                                         final org.apache.shenyu.client.mcp.common.dto.ShenyuMcpTool shenyuMcpTool,\n                                                         final String superPath, final Method method,\n                                                         final String url, final String namespaceId) {\n        validateClientConfig(shenyuMcpTool, url);\n        JsonObject openApiJson = McpOpenApiGenerator.generateOpenApiJson(classShenyuClient, shenyuMcpTool, url);\n        McpToolsRegisterDTO mcpToolsRegisterDTO = McpToolsRegisterDTOGenerator.generateRegisterDTO(shenyuMcpTool, openApiJson, url, namespaceId);\n        MetaDataRegisterDTO metaDataRegisterDTO = buildMetaDataDTO(bean, classShenyuClient, url, clazz, method, namespaceId);\n        metaDataRegisterDTO.setEnabled(shenyuMcpTool.getEnable());\n        mcpToolsRegisterDTO.setMetaDataRegisterDTO(metaDataRegisterDTO);\n        return mcpToolsRegisterDTO;\n    }\n\n    private void validateClientConfig(final org.apache.shenyu.client.mcp.common.dto.ShenyuMcpTool methodShenyuClient, final String url) {\n        if (StringUtils.isBlank(url)) {\n            log.error(\"OpenAPI pathKey is null or empty, please check OpenApiConfig\");\n            throw new IllegalArgumentException(\"OpenAPI pathKey cannot be null or empty\");\n        }\n\n        if (StringUtils.isBlank(methodShenyuClient.getMethod())) {\n            log.error(\"OpenAPI methodType is null or empty, please check OpenApiConfig\");\n            throw new IllegalArgumentException(\"OpenAPI methodType cannot be null or empty\");\n        }\n    }\n\n}\n","sourceCodeStart":360,"sourceCodeEnd":388,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-client/shenyu-client-mcp/shenyu-client-mcp-register/src/main/java/org/apache/shenyu/client/mcp/McpServiceEventListener.java#L360-L388","documentation":"McpServiceEventListener.validateClientConfig checks each MCP tool registration: the OpenAPI url (pathKey) must be non-blank. If blank, it logs that OpenApiConfig is misconfigured and throws IllegalArgumentException, aborting the tool's registration DTO build.","triggerScenarios":"Building MCP tools register DTOs when the ShenyuMcpTool's associated OpenAPI url/pathKey is null or empty — i.e. the OpenApiConfig did not supply a pathKey for the tool.","commonSituations":"OpenApiConfig annotation/property omitted; pathKey property misspelled; tool definitions generated from OpenAPI specs missing the path mapping.","solutions":["Set pathKey on the OpenApiConfig for each @ShenyuMcpTool","Verify the tool definition's url field is populated before registration","Check logs for 'OpenAPI pathKey is null or empty' to locate the offending tool","Regenerate tool configs from the OpenAPI spec ensuring path fields are present"],"exampleFix":"// before\n@ShenyuMcpTool(name = \"weather\")\n// after\n@ShenyuMcpTool(name = \"weather\", openApiConfig = @OpenApiConfig(pathKey = \"/weather\", methodType = \"GET\"))","handlingStrategy":"validation","validationCode":"if (tool.getOpenApiConfig() == null || StringUtils.isBlank(tool.getOpenApiConfig().getPathKey())) {\n    throw new IllegalStateException(\"@ShenyuMcpTool \" + tool.getName() + \" missing OpenApiConfig pathKey\");\n}","typeGuard":null,"tryCatchPattern":"try { listener.buildMcpToolsRegisterDTO(tool); }\ncatch (IllegalArgumentException e) {\n    log.error(\"MCP tool config invalid: {}\", e.getMessage());\n}","preventionTips":["Annotate every @ShenyuMcpTool with a complete OpenApiConfig","Run an annotation scan at startup to verify pathKey presence","Regenerate tool configs from the OpenAPI spec"],"tags":["mcp","openapi","configuration","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}