spring-projects/spring-ai · error · IllegalArgumentException

Currently only methods with a single ElicitRequest parameter

Error message

Currently only methods with a single ElicitRequest parameter are supported: 

What it means

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.

Source

Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/elicitation/AbstractMcpElicitationMethodCallback.java:111

			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(
					"Currently only methods with a single ElicitRequest parameter are supported: " + method.getName()
							+ " in " + method.getDeclaringClass().getName() + " has " + parameters.length
							+ " parameters");
		}
	}

	/**
	 * Builds the arguments array for invoking the method.
	 * <p>
	 * This method constructs an array of arguments based on the method's parameter types
	 * and the available values (exchange, request).
	 * @param method The method to build arguments for
	 * @param exchange The server exchange
	 * @param request The elicitation request
	 * @return An array of arguments for the method invocation
	 */
	protected Object[] buildArgs(Method method, Object exchange, ElicitRequest request) {
		Parameter[] parameters = method.getParameters();

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Reduce the method to exactly one parameter of type ElicitRequest
  2. Move auxiliary dependencies into the enclosing bean's fields or constructor so they don't appear as method parameters
  3. Wrap any desired typed payload extraction inside the method body using request.params()

Example fix

// before
@McpElicitation
public ElicitResult handle(ElicitRequest request, UserContext ctx) { ... }

// after
@McpElicitation
public ElicitResult handle(ElicitRequest request) {
    UserContext ctx = this.ctx; // bean field instead of parameter
    ...
}
Defensive patterns

Strategy: validation

Validate before calling

if (m.getParameterCount() != 1) {
    throw new IllegalArgumentException("Elicitation handlers must have exactly one ElicitRequest parameter: " + m);
}

Type guard

boolean singleElicitRequestParam(Method m) {
    return m.getParameterCount() == 1;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/6c39a2ca1c4e2fef. Report an issue: GitHub.