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

Source

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

	 * 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();
		Object[] args = new Object[parameters.length];

		if (parameters.length == 1) {
			// Single parameter (ElicitRequest)
			args[0] = request;
		}
		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");
		}

		return args;
	}

	/**
	 * Checks if a parameter type is compatible with the exchange type. This method should
	 * be implemented by subclasses to handle specific exchange type checking.
	 * @param paramType The parameter type to check
	 * @return true if the parameter type is compatible with the exchange type, false
	 * otherwise
	 */
	protected abstract boolean isExchangeType(Class<?> paramType);

	/**
	 * Exception thrown when there is an error invoking an elicitation method.
	 */

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Ensure the annotated method has exactly one ElicitRequest parameter
  2. Register callbacks through the standard builder so validate() runs before buildArgs
  3. If you subclass the callback, call validateParameters in your builder's validate() override

Example fix

// before (custom builder skips validation)
new MyCallback(method, bean); // 2-param method slips through

// after
new MyCallback.Builder().method(method).bean(bean).build(); // validate() enforced
// and keep method signature: public ElicitResult handle(ElicitRequest request)
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(method, "method");
if (method.getParameterCount() != 1) {
    throw new IllegalArgumentException("Method must take exactly one ElicitRequest: " + method);
}

Try / catch

try {
    ElicitResult r = callback.apply(request);
} catch (IllegalArgumentException e) {
    log.error("Callback misconfigured: {}", e.getMessage());
}

Prevention

When it happens

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

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

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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