spring-projects/spring-ai · error · IllegalArgumentException
Method must have at least 1 parameter (ElicitRequest):
Error message
Method must have at least 1 parameter (ElicitRequest):
What it means
AbstractMcpElicitationMethodCallback.validateParameters throws this IllegalArgumentException when a method registered for MCP elicitation has zero parameters. An elicitation handler must accept at least an ElicitRequest parameter so the framework can pass the client's response data.
Solutions
- Add an ElicitRequest parameter as the first (or only) argument of the method
- If extra parameters are needed, follow the supported signatures: (ElicitRequest) or (ElicitRequest, McpTransportContext/McpSyncServerExchange) per the library's parameter rules
- Check validateParameters' type checks so the first parameter is exactly ElicitRequest, not Object or a subclass wrapper
Example fix
// before
@McpElicitation(elicitId = "confirm")
public void onConfirm() { }
// after
@McpElicitation(elicitId = "confirm")
public CompleteResult onConfirm(ElicitRequest request) { return ...; } Defensive patterns
Strategy: validation
Validate before calling
for (Method m : bean.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(McpElicitation.class) && m.getParameterCount() < 1)
throw new IllegalStateException("@McpElicitation method " + m.getName() + " needs an ElicitRequest parameter");
} Type guard
static boolean hasElicitRequest(Method m) {
return m.getParameterCount() > 0 && ElicitRequest.class.isAssignableFrom(m.getParameterTypes()[0]);
} Try / catch
try { new SyncMcpElicitationMethodCallback(bean, method, elicitId); }
catch (IllegalArgumentException e) { log.error("invalid elicitation signature: {}", e.getMessage()); throw new BeanInitializationException(e.getMessage(), e); } Prevention
- Always declare at least an ElicitRequest parameter on @McpElicitation methods
- Put ElicitRequest first if combining with context/exchange parameters
- Add a startup test scanning @McpElicitation methods for the required signature
When it happens
Trigger: Annotating a no-argument method with @McpElicitation; validateParameters is invoked from validateMethod during callback construction.
Common situations: Adding the annotation to an empty callback-style method (e.g. run() or handle()) assuming the framework injects state via fields rather than parameters.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Bean must not be null
- clients must not be empty
- clients must not be empty
- Currently only methods with a single ElicitRequest…
- Currently only methods with a single ElicitRequest…
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/589194c99e5535a3.
Report an issue: GitHub.
Appendix: source
Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/elicitation/AbstractMcpElicitationMethodCallback.java:93
* This method should be implemented by subclasses to handle specific return type
* validation.
* @param method The method to validate
* @throws IllegalArgumentException if the return type is not compatible
*/
protected abstract void validateReturnType(Method method);
/**
* Validates method parameters. This method provides common validation logic and
* delegates exchange type checking to subclasses.
* @param method The method to validate
* @throws IllegalArgumentException if the parameters are not compatible
*/
protected void validateParameters(Method method) {
Parameter[] parameters = method.getParameters();
// Check parameter count - must have at least 1 parameter
if (parameters.length < 1) {
throw new IllegalArgumentException(
"Method must have at least 1 parameter (ElicitRequest): " + method.getName() + " in "
+ method.getDeclaringClass().getName() + " has " + parameters.length + " parameters");
}
// Check parameter types
if (parameters.length == 1) {
// Single parameter must be ElicitRequest
if (!ElicitRequest.class.isAssignableFrom(parameters[0].getType())) {
throw new IllegalArgumentException("Single parameter must be of type ElicitRequest: " + method.getName()
+ " in " + method.getDeclaringClass().getName() + " has parameter of type "
+ parameters[0].getType().getName());
}
}
else {
// TODO: Support for multiple parameters corresponding to ElicitRequest
// fields
// For now, we only support the single parameter version
throw new IllegalArgumentException(View on GitHub (pinned to 98a7beda4f)