{"record":{"id":"b9853e17aaf78fae","repo":"spring-projects/spring-ai","slug":"method-cannot-have-more-than-one-transport-context","errorCode":null,"errorMessage":"Method cannot have more than one transport context parameter: {method} in {class}","messagePattern":"Method cannot have more than one transport context 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":227,"sourceCode":"\t\t\t\t}\n\n\t\t\t\thasRequestContextParam = true;\n\t\t\t}\n\t\t\telse if (McpAsyncRequestContext.class.isAssignableFrom(paramType)) {\n\t\t\t\tif (hasRequestContextParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one request 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\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}","sourceCodeStart":209,"sourceCodeEnd":245,"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#L209-L245","documentation":"Duplicate-parameter validation in AbstractMcpCompleteMethodCallback.validateParameters: an @McpComplete-annotated method declares more than one McpTransportContext parameter, which is ambiguous for argument binding; only one transport context parameter is allowed.","triggerScenarios":"A method signature includes two parameters assignable to McpTransportContext.","commonSituations":"Adding a transport context to access transport-level info while an existing one is already present; copy-paste of method signatures.","solutions":["Remove the duplicate McpTransportContext parameter from the annotated method","Keep only one transport context parameter per completion method"],"exampleFix":"// before\npublic String complete(McpTransportContext t1, McpTransportContext t2, CompleteRequest req) { ... }\n// after\npublic String complete(McpTransportContext transportContext, CompleteRequest req) { ... }","handlingStrategy":"validation","validationCode":"long t = Arrays.stream(m.getParameterTypes()).filter(McpTransportContext.class::isAssignableFrom).count();\nif (t > 1) throw new IllegalStateException(\"Only one McpTransportContext parameter allowed: \" + m);","typeGuard":null,"tryCatchPattern":"try {\n    callbackBuilder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"more than one transport context\")) { /* drop duplicate param */ }\n    throw e;\n}","preventionTips":["Declare at most one McpTransportContext per completion method","Search codebase for methods with two McpTransportContext params before upgrading the library"],"tags":["mcp","method-validation","duplicate-parameter","transport-context"],"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"}