{"record":{"id":"2c1b67e063016946","repo":"spring-projects/spring-ai","slug":"method-cannot-have-more-than-one-mcpmeta-parameter","errorCode":null,"errorMessage":"Method cannot have more than one McpMeta parameter: {method} in {class}","messagePattern":"Method cannot have more than one McpMeta 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":193,"sourceCode":"\t\tboolean hasRequestContextParam = false;\n\n\t\tfor (Parameter param : parameters) {\n\t\t\tClass<?> paramType = param.getType();\n\n\t\t\t// Skip @McpProgressToken annotated parameters from validation\n\t\t\tif (param.isAnnotationPresent(McpProgressToken.class)) {\n\t\t\t\tif (hasProgressTokenParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one @McpProgressToken parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasProgressTokenParam = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip McpMeta parameters from validation\n\t\t\tif (McpMeta.class.isAssignableFrom(paramType)) {\n\t\t\t\tif (hasMetaParam) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Method cannot have more than one McpMeta parameter: \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\t\t\t\thasMetaParam = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (McpSyncRequestContext.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.isReactiveReturnType.test(method)) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Async complete methods should use McpAsyncRequestContext instead of McpSyncRequestContext parameter: \"\n\t\t\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName());\n\t\t\t\t}\n\n\t\t\t\thasRequestContextParam = true;","sourceCodeStart":175,"sourceCodeEnd":211,"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#L175-L211","documentation":"At most one McpMeta-typed parameter is allowed per completion method; the framework injects request metadata once. validateParameters() throws this IllegalArgumentException if a second McpMeta (or subclass) parameter is found, listing the method and declaring class.","triggerScenarios":"Declaring two parameters assignable to McpMeta on one @McpComplete-annotated method.","commonSituations":"Adding McpMeta twice while extending an existing handler signature; auto-generated stubs that already include McpMeta being augmented; merge artifacts.","solutions":["Remove the redundant McpMeta parameter, keeping at most one.","If different metadata views are needed, extract fields from the single McpMeta instance in the method body."],"exampleFix":"// before\npublic void complete(String value, McpMeta meta, McpMeta meta2) { }\n// after\npublic void complete(String value, McpMeta meta) { }","handlingStrategy":"validation","validationCode":"long metas = Arrays.stream(method.getParameters())\n    .filter(p -> McpMeta.class.isAssignableFrom(p.getType())).count();\nif (metas > 1) throw new IllegalStateException(\"duplicate McpMeta parameter in \" + method.getName());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare McpMeta at most once per handler.","Extract needed metadata fields inside the method body."],"tags":["mcp","validation","duplicate-parameter","completion"],"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-14T11:17:12.474Z"}