spring-projects/spring-ai · error · IllegalArgumentException

Method cannot have more than one ReadResourceRequest paramet

Error message

Method cannot have more than one ReadResourceRequest parameter: ${method} in ${declaringClass}

What it means

Thrown when an @McpResource method with URI variables declares more than one ReadResourceRequest parameter. Only a single request parameter can be bound, so the framework rejects the method at registration time.

Source

Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/resource/AbstractMcpResourceMethodCallback.java:347

					if (McpPredicates.isNotReactiveReturnType.test(method)) {
						throw new IllegalArgumentException(
								"Async complete methods should use McpAsyncRequestContext instead of McpSyncRequestContext parameter: "
										+ method.getName() + " in " + method.getDeclaringClass().getName());
					}
					hasRequestContextParam = true;
				}
			}
		}

		// Check if we have more than one exchange parameter
		if (exchangeParamCount > 1) {
			throw new IllegalArgumentException("Method cannot have more than one exchange parameter: "
					+ method.getName() + " in " + method.getDeclaringClass().getName());
		}

		// Check if we have more than one request parameter
		if (requestParamCount > 1) {
			throw new IllegalArgumentException("Method cannot have more than one ReadResourceRequest parameter: "
					+ method.getName() + " in " + method.getDeclaringClass().getName());
		}

		// Check if we have more than one meta parameter
		if (metaParamCount > 1) {
			throw new IllegalArgumentException("Method cannot have more than one McpMeta parameter: " + method.getName()
					+ " in " + method.getDeclaringClass().getName());
		}

		// Calculate how many parameters should be for URI variables
		int requestContextParamCount = hasRequestContextParam ? 1 : 0;
		int specialParamCount = exchangeParamCount + requestParamCount + progressTokenParamCount + metaParamCount
				+ requestContextParamCount;
		int uriVarParamCount = parameters.length - specialParamCount;

		// Check if we have the right number of parameters for URI variables
		if (uriVarParamCount != this.uriVariables.size()) {
			throw new IllegalArgumentException(

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Remove the duplicate ReadResourceRequest parameter and keep exactly one
  2. Bind each URI variable with its own String parameter instead of extra request parameters
  3. Access additional data through the single request object (e.g. request.meta())

Example fix

// before
public String read(ReadResourceRequest req, ReadResourceRequest req2) { ... }
// after
public String read(ReadResourceRequest req) { ... }
Defensive patterns

Strategy: validation

Validate before calling

long reqParams = Arrays.stream(m.getParameters()).filter(p -> ReadResourceRequest.class.isAssignableFrom(p.getType())).count();
if (reqParams > 1) throw new IllegalStateException(m + " declares multiple ReadResourceRequest parameters");

Prevention

When it happens

Trigger: Declaring two ReadResourceRequest parameters (e.g. ReadResourceRequest request, ReadResourceRequest req2) on an @McpResource method whose URI has variables; validateParametersWithUriVariables throws when requestParamCount > 1.

Common situations: Copy-paste of the request parameter; thinking an extra request param is needed for each URI variable; refactoring residue from merging handlers.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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