{"record":{"id":"595f6e78f18912e1","repo":"spring-projects/spring-ai","slug":"third-parameter-must-be-of-type-string-method-ge","errorCode":null,"errorMessage":"Third parameter must be of type String: {method.getName()} in {method.getDeclaringClass().getName()} has parameter of type {parameters[2].getType().getName()}","messagePattern":"Third parameter must be of type String: (.+?) in (.+?) has parameter of type (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/progress/AbstractMcpProgressMethodCallback.java","lineNumber":122,"sourceCode":"\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[0].getType().getName());\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// Three parameters must be Double, String, String\n\t\t\tif (!Double.class.isAssignableFrom(parameters[0].getType())\n\t\t\t\t\t&& !double.class.isAssignableFrom(parameters[0].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"First parameter must be of type Double or double: \"\n\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[0].getType().getName());\n\t\t\t}\n\t\t\tif (!String.class.isAssignableFrom(parameters[1].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Second parameter must be of type String: \" + method.getName()\n\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[1].getType().getName());\n\t\t\t}\n\t\t\tif (!String.class.isAssignableFrom(parameters[2].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Third parameter must be of type String: \" + method.getName()\n\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[2].getType().getName());\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Builds the arguments array for invoking the method.\n\t * <p>\n\t * This method constructs an array of arguments based on the method's parameter types\n\t * and the available values (exchange, notification).\n\t * @param method The method to build arguments for\n\t * @param exchange The server exchange\n\t * @param notification The progress notification\n\t * @return An array of arguments for the method invocation\n\t */\n\tprotected Object[] buildArgs(Method method, Object exchange, ProgressNotification notification) {\n\t\tParameter[] parameters = method.getParameters();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/progress/AbstractMcpProgressMethodCallback.java#L104-L140","documentation":"For three-parameter progress methods, the third parameter must be a String (the human-readable progress message). validateParameters throws this IllegalArgumentException when parameters[2] is not String-assignable. The message lets clients display progress detail text.","triggerScenarios":"Registering a progress callback with a third parameter of a non-String type, e.g. (Double progress, String token, Integer total) or (Double, String, Object detail).","commonSituations":"Trying to receive structured progress data (counts, totals, JSON payloads) in the third slot instead of a String message; mismatched signature after adding a parameter to an existing two-arg handler.","solutions":["Change the third parameter to java.lang.String.","If structured data is needed, encode it into the String message (e.g. JSON) and parse inside the method.","Drop the third parameter and use the two-parameter (Double, String) signature if no message is needed."],"exampleFix":"// before\npublic void onProgress(Double progress, String token, int percent) { ... }\n// after\npublic void onProgress(Double progress, String token, String message) { ... }","handlingStrategy":"validation","validationCode":"if (method.getParameterCount() == 3\n        && !String.class.equals(method.getParameterTypes()[2])) {\n    throw new IllegalStateException(method + \" third param must be String (message)\");\n}","typeGuard":"boolean hasStringMessage(Method m) {\n    return m.getParameterCount() != 3\n        || String.class.isAssignableFrom(m.getParameterTypes()[2]);\n}","tryCatchPattern":"try {\n    builder.method(method).bean(bean).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Third parameter must be\")) {\n        throw new ConfigurationException(\"Third param of progress method must be String\", e);\n    }\n    throw e;\n}","preventionTips":["Use the two-parameter signature if no message is required.","Encode structured progress data as a JSON string in the message parameter.","Cover all @McpProgress methods with a signature-asserting unit test."],"tags":["mcp","progress-notification","method-signature","illegal-argument"],"backgroundTag":"invalid-argument-type-mismatch","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}