{"record":{"id":"f690945524f2b29b","repo":"apache/shenyu","slug":"invalid-input-json-format","errorCode":null,"errorMessage":"Invalid input JSON format","messagePattern":"Invalid input JSON format","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java","lineNumber":343,"sourceCode":"        configureShenyuContext(finalExchange, sessionId, requestConfig.getPath(), configStr);\n        return finalExchange;\n    }\n\n    /**\n     * Parses the input JSON string into a JsonObject.\n     *\n     * @param input the input JSON string\n     * @return the parsed JsonObject\n     * @throws IllegalArgumentException if input is not valid JSON\n     */\n    private JsonObject parseInput(final String input) {\n        try {\n            if (org.apache.commons.lang3.StringUtils.isBlank(input)) {\n                return new JsonObject();\n            }\n            final JsonObject inputJson = GsonUtils.getInstance().fromJson(input, JsonObject.class);\n            if (Objects.isNull(inputJson)) {\n                throw new IllegalArgumentException(\"Invalid input JSON format\");\n            }\n            return inputJson;\n        } catch (Exception e) {\n            LOG.error(\"Failed to parse input JSON: {}\", e.getMessage());\n            throw new IllegalArgumentException(\"Invalid JSON format: \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * Builds request configuration from configuration string and input parameters.\n     *\n     * @param configStr the configuration string\n     * @param inputJson the input parameters\n     * @return the built request configuration\n     */\n    private RequestConfig buildRequestConfig(final String configStr, final JsonObject inputJson) {\n        final RequestConfigHelper configHelper = new RequestConfigHelper(configStr);\n        final JsonObject requestTemplate = configHelper.getRequestTemplate();","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java#L325-L361","documentation":"parseInput parses the tool-call arguments string into a Gson JsonObject. If the parsed result is null (Gson can return null for certain inputs like the literal 'null'), it throws IllegalArgumentException('Invalid input JSON format'). Note the catch block then rethrows a different message ('Invalid JSON format: ...'), so this exact message only appears for the null-parse case (or is wrapped by it if Gson threw).","triggerScenarios":"An MCP client sends arguments whose parsed JSON yields null — most commonly the JSON string \"null\", or Gson throwing during fromJson (which lands in the catch and produces error 177's message instead).","commonSituations":"MCP client sending literal null or empty-semantic arguments; client-side serialization bug emitting 'null' instead of '{}'; mismatch between tool input schema and what the LLM emits.","solutions":["Make the MCP client send a valid JSON object for arguments; blank input is fine (treated as {}) but 'null' is not.","Fix client serialization to emit {} when there are no arguments.","Validate arguments against the tool's input schema before invoking."],"exampleFix":"// before (client)\ntoolCall(toolName, \"null\");\n// after\ntoolCall(toolName, \"{}\");","handlingStrategy":"validation","validationCode":"boolean safeArgs(String input) {\n    if (input == null || input.isBlank() || \"null\".equalsIgnoreCase(input.trim())) {\n        return true; // will be treated as empty JsonObject or should be replaced with \"{}\"\n    }\n    try { new com.google.gson.JsonParser().parseString(input); return true; }\n    catch (Exception e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return callback.call(args, ctx);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"JSON\")) {\n        return \"Invalid arguments: expected a JSON object\";\n    }\n    throw e;\n}","preventionTips":["Send \"{}\" for tools with no arguments; never send the literal string null.","Serialize tool arguments with a JSON library, never string concatenation.","Validate LLM output against the tool input schema before invoking.","Blank input is acceptable (treated as empty object) — normalize it client-side."],"tags":["mcp","json","validation","ai"],"backgroundTag":"json-parse-error","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"}