{"record":{"id":"6c39a2ca1c4e2fef","repo":"spring-projects/spring-ai","slug":"currently-only-methods-with-a-single-elicitrequest","errorCode":null,"errorMessage":"Currently only methods with a single ElicitRequest parameter are supported: ","messagePattern":"Currently only methods with a single ElicitRequest parameter are supported: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/elicitation/AbstractMcpElicitationMethodCallback.java","lineNumber":111,"sourceCode":"\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Method must have at least 1 parameter (ElicitRequest): \" + 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 types\n\t\tif (parameters.length == 1) {\n\t\t\t// Single parameter must be ElicitRequest\n\t\t\tif (!ElicitRequest.class.isAssignableFrom(parameters[0].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Single parameter must be of type ElicitRequest: \" + 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[0].getType().getName());\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// TODO: Support for multiple parameters corresponding to ElicitRequest\n\t\t\t// fields\n\t\t\t// For now, we only support the single parameter version\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Currently only methods with a single ElicitRequest parameter are supported: \" + method.getName()\n\t\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has \" + parameters.length\n\t\t\t\t\t\t\t+ \" parameters\");\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, request).\n\t * @param method The method to build arguments for\n\t * @param exchange The server exchange\n\t * @param request The elicitation request\n\t * @return An array of arguments for the method invocation\n\t */\n\tprotected Object[] buildArgs(Method method, Object exchange, ElicitRequest request) {\n\t\tParameter[] parameters = method.getParameters();","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/elicitation/AbstractMcpElicitationMethodCallback.java#L93-L129","documentation":"Thrown by AbstractMcpElicitationMethodCallback.validateParameters when an @McpElicitation-annotated method declares more than one parameter. Only the single-ElicitRequest-parameter form is implemented; multi-parameter elicitation methods are an explicit TODO in the library.","triggerScenarios":"Registering an elicitation handler like @McpElicitation public ElicitResult handle(ElicitRequest req, SomeContext ctx) or any method with 0 or 2+ parameters — the message includes the actual parameter count.","commonSituations":"Developers add auxiliary parameters (session, context, an injected mapper) to the handler the way tool callbacks or Spring controllers allow, unaware elicitation callbacks only support the one-parameter signature.","solutions":["Reduce the method to exactly one parameter of type ElicitRequest","Move auxiliary dependencies into the enclosing bean's fields or constructor so they don't appear as method parameters","Wrap any desired typed payload extraction inside the method body using request.params()"],"exampleFix":"// before\n@McpElicitation\npublic ElicitResult handle(ElicitRequest request, UserContext ctx) { ... }\n\n// after\n@McpElicitation\npublic ElicitResult handle(ElicitRequest request) {\n    UserContext ctx = this.ctx; // bean field instead of parameter\n    ...\n}","handlingStrategy":"validation","validationCode":"if (m.getParameterCount() != 1) {\n    throw new IllegalArgumentException(\"Elicitation handlers must have exactly one ElicitRequest parameter: \" + m);\n}","typeGuard":"boolean singleElicitRequestParam(Method m) {\n    return m.getParameterCount() == 1;\n}","tryCatchPattern":null,"preventionTips":["Never add context/session parameters to @McpElicitation methods — use bean fields for dependencies","Keep handler signatures to (ElicitRequest) -> ElicitResult or Mono<ElicitResult>","Add an app-startup smoke test that scans and registers all annotated handlers"],"tags":["java","mcp","elicitation","method-signature","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}