{"record":{"id":"059b815bd56de297","repo":"spring-projects/spring-ai","slug":"currently-only-methods-with-a-single-elicitrequest-059b81","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":140,"sourceCode":"\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();\n\t\tObject[] args = new Object[parameters.length];\n\n\t\tif (parameters.length == 1) {\n\t\t\t// Single parameter (ElicitRequest)\n\t\t\targs[0] = request;\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\");\n\t\t}\n\n\t\treturn args;\n\t}\n\n\t/**\n\t * Checks if a parameter type is compatible with the exchange type. This method should\n\t * be implemented by subclasses to handle specific exchange type checking.\n\t * @param paramType The parameter type to check\n\t * @return true if the parameter type is compatible with the exchange type, false\n\t * otherwise\n\t */\n\tprotected abstract boolean isExchangeType(Class<?> paramType);\n\n\t/**\n\t * Exception thrown when there is an error invoking an elicitation method.\n\t */","sourceCodeStart":122,"sourceCodeEnd":158,"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#L122-L158","documentation":"Thrown by AbstractMcpElicitationMethodCallback.buildArgs while preparing reflective method arguments at invocation time. It mirrors the validateParameters check (errors 120/121) but fires when the method somehow has a parameter count other than one — a defensive invariant guard during callback invocation.","triggerScenarios":"Invoking an elicitation callback whose underlying method's parameter count changed or was constructed bypassing validation (e.g. a builder allowed a method with 0 or 2+ parameters, or validation was skipped via a subclass).","commonSituations":"Rare in normal use because validateMethod runs at registration; appears when custom callback builders bypass the standard builder's validate() path or when reflection metadata is manipulated.","solutions":["Ensure the annotated method has exactly one ElicitRequest parameter","Register callbacks through the standard builder so validate() runs before buildArgs","If you subclass the callback, call validateParameters in your builder's validate() override"],"exampleFix":"// before (custom builder skips validation)\nnew MyCallback(method, bean); // 2-param method slips through\n\n// after\nnew MyCallback.Builder().method(method).bean(bean).build(); // validate() enforced\n// and keep method signature: public ElicitResult handle(ElicitRequest request)\n","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(method, \"method\");\nif (method.getParameterCount() != 1) {\n    throw new IllegalArgumentException(\"Method must take exactly one ElicitRequest: \" + method);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ElicitResult r = callback.apply(request);\n} catch (IllegalArgumentException e) {\n    log.error(\"Callback misconfigured: {}\", e.getMessage());\n}","preventionTips":["Always build callbacks through the standard Builder so validate() runs","Fix method signatures at the source rather than bypassing validation","This signals a programming bug, not a runtime condition — treat it as a registration-time failure"],"tags":["java","mcp","elicitation","internal-invariant","reflection"],"backgroundTag":"internal-invariant-violation","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"}