{"record":{"id":"12526dfd34deef67","repo":"spring-projects/spring-ai","slug":"method-cannot-have-more-than-one-exchange-paramete","errorCode":null,"errorMessage":"Method cannot have more than one exchange parameter: {method} in {class}","messagePattern":"Method cannot have more than one exchange parameter: (.+?) in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/AbstractMcpCompleteMethodCallback.java","lineNumber":234,"sourceCode":"\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\tif (McpPredicates.isNotReactiveReturnType.test(method)) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Sync complete methods should use McpSyncRequestContext instead of McpAsyncRequestContext parameter: \"\n\t\t\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasRequestContextParam = true;\n\t\t\t}\n\t\t\telse if (McpTransportContext.class.isAssignableFrom(paramType)) {\n\t\t\t\tif (hasTransportContext) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one transport context parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasTransportContext = true;\n\t\t\t}\n\t\t\telse if (isExchangeType(paramType)) {\n\t\t\t\tif (hasExchangeParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one exchange parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasExchangeParam = true;\n\t\t\t}\n\t\t\telse if (CompleteRequest.class.isAssignableFrom(paramType)) {\n\t\t\t\tif (hasRequestParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one CompleteRequest parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasRequestParam = true;\n\t\t\t}\n\t\t\telse if (CompleteRequest.CompleteArgument.class.isAssignableFrom(paramType)) {\n\t\t\t\tif (hasArgumentParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one CompleteArgument parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasArgumentParam = true;\n\t\t\t}","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/AbstractMcpCompleteMethodCallback.java#L216-L252","documentation":"Thrown when a @McpComplete method declares more than one MCP exchange parameter (a type recognized by isExchangeType, e.g. McpSyncServerExchange/McpAsyncServerExchange). At most one exchange parameter is allowed.","triggerScenarios":"A method signature includes two exchange-typed parameters.","commonSituations":"Mixing sync and async exchange parameters in one signature; incremental refactors leaving the old exchange in place.","solutions":["Remove the extra exchange parameter, keeping a single exchange whose type matches the method's sync/async style","Rebuild the callback"],"exampleFix":"// before\npublic String complete(McpSyncServerExchange e1, McpAsyncServerExchange e2, CompleteRequest req) { ... }\n// after\npublic String complete(McpSyncServerExchange exchange, CompleteRequest req) { ... }","handlingStrategy":"validation","validationCode":"long ex = Arrays.stream(m.getParameterTypes()).filter(this::isExchangeType).count();\nif (ex > 1) throw new IllegalStateException(\"Only one exchange parameter allowed: \" + m);","typeGuard":null,"tryCatchPattern":"try {\n    callbackBuilder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"more than one exchange\")) { /* remove duplicate exchange param */ }\n    throw e;\n}","preventionTips":["Keep exactly one exchange parameter, matching sync/async style","Don't mix McpSyncServerExchange and McpAsyncServerExchange in one signature"],"tags":["mcp","method-validation","duplicate-parameter","exchange"],"backgroundTag":"invalid-argument-value","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"}