{"record":{"id":"3db5644e1fa685c8","repo":"spring-projects/spring-ai","slug":"method-must-have-exactly-1-parameter-list-mcpsche","errorCode":null,"errorMessage":"Method must have exactly 1 parameter (List<McpSchema.Prompt>): ","messagePattern":"Method must have exactly 1 parameter \\(List<McpSchema\\.Prompt>\\): ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/changed/prompt/AbstractMcpPromptListChangedMethodCallback.java","lineNumber":94,"sourceCode":"\t * Validates that the method return type is compatible with the prompt list changed\n\t * consumer callback. This method should be implemented by subclasses to handle\n\t * specific return type validation.\n\t * @param method The method to validate\n\t * @throws IllegalArgumentException if the return type is not compatible\n\t */\n\tprotected abstract void validateReturnType(Method method);\n\n\t/**\n\t * Validates method parameters. This method provides common validation logic.\n\t * @param method The method to validate\n\t * @throws IllegalArgumentException if the parameters are not compatible\n\t */\n\tprotected void validateParameters(Method method) {\n\t\tParameter[] parameters = method.getParameters();\n\n\t\t// Check parameter count - must have exactly 1 parameter\n\t\tif (parameters.length != 1) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Method must have exactly 1 parameter (List<McpSchema.Prompt>): \" + method.getName() + \" in \"\n\t\t\t\t\t\t\t+ method.getDeclaringClass().getName() + \" has \" + parameters.length + \" parameters\");\n\t\t}\n\n\t\t// Check parameter type - must be List<McpSchema.Prompt>\n\t\tClass<?> paramType = parameters[0].getType();\n\t\tif (!List.class.isAssignableFrom(paramType)) {\n\t\t\tthrow new IllegalArgumentException(\"Parameter must be of type List<McpSchema.Prompt>: \" + method.getName()\n\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \" + paramType.getName());\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.\n\t * @param method The method to build arguments for","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/changed/prompt/AbstractMcpPromptListChangedMethodCallback.java#L76-L112","documentation":"validateParameters enforces that a prompt-list-changed handler method takes exactly one parameter of type List<McpSchema.Prompt>. A method with any other parameter count cannot receive the changed prompt list and is rejected at registration time with this IllegalArgumentException.","triggerScenarios":"Registering a prompt-list-changed callback whose method has 0 parameters or more than 1 parameter (e.g. no-arg handlers or handlers taking extra context arguments).","commonSituations":"Developers write no-argument notification handlers assuming notifications carry no data, or add extra parameters (server exchange, session) by analogy with tool callbacks.","solutions":["Change the handler signature to exactly one parameter: void handler(List<McpSchema.Prompt> prompts)","Remove extra parameters and obtain needed services via injection/fields instead of method parameters","Read the callback API docs: only the List<Prompt> is passed to the handler"],"exampleFix":"// before\npublic void onPromptListChanged() { ... }\n// after\npublic void onPromptListChanged(List<McpSchema.Prompt> prompts) { ... }","handlingStrategy":"validation","validationCode":"if (method.getParameterCount() != 1 || !List.class.isAssignableFrom(method.getParameterTypes()[0])) { throw new IllegalArgumentException(\"Handler must take exactly one List<McpSchema.Prompt>\"); }","typeGuard":"boolean isValidHandler = m.getParameterCount() == 1 && List.class.isAssignableFrom(m.getParameterTypes()[0]);","tryCatchPattern":"try { server.addListChangedHandler(callback); } catch (IllegalArgumentException e) { throw new ConfigurationException(\"Invalid prompt list changed handler: \" + e.getMessage(), e); }","preventionTips":["Copy the documented handler signature exactly: (List<McpSchema.Prompt> prompts)","Do not add extra parameters such as exchange or session to notification handlers","Write a startup-time test that registers all handlers to fail fast on signature drift"],"tags":["mcp","reflection","method-signature","validation"],"backgroundTag":"invalid-argument-value","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"}