{"record":{"id":"e56b1df124e65a39","repo":"spring-projects/spring-ai","slug":"method-cannot-have-more-than-one-mcpmeta-parameter-e56b1d","errorCode":null,"errorMessage":"Method cannot have more than one McpMeta parameter: {method.getName()} in {method.getDeclaringClass().getName()}","messagePattern":"Method cannot have more than one McpMeta parameter: (.+?) in (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/prompt/AbstractMcpPromptMethodCallback.java","lineNumber":140,"sourceCode":"\t\tfor (java.lang.reflect.Parameter param : parameters) {\n\t\t\tClass<?> paramType = param.getType();\n\n\t\t\tthis.validateParamType(paramType);\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\"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}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/prompt/AbstractMcpPromptMethodCallback.java#L122-L158","documentation":"validateParameters() permits at most one parameter assignable from McpMeta per @McpPrompt method; the framework injects the request's metadata into it. A second McpMeta parameter is ambiguous and throws IllegalArgumentException naming the method and declaring class.","triggerScenarios":"An @McpPrompt method declaring two parameters whose types are McpMeta (or subclasses of it), e.g. complete(String value, McpMeta m1, McpMeta m2).","commonSituations":"Accidentally declaring both McpMeta and a custom subclass of McpMeta; copy-paste duplication of a parameter; assuming multiple meta parameters receive different metadata slices.","solutions":["Keep a single McpMeta parameter and read all needed metadata keys from it.","Remove or retype the duplicate parameter to a supported non-McpMeta type.","If using a McpMeta subclass, drop the base-typed parameter so only one assignable parameter remains."],"exampleFix":"// before\n@McpPrompt(name = \"p\")\npublic String complete(String q, McpMeta meta, McpMeta meta2) { ... }\n// after\n@McpPrompt(name = \"p\")\npublic String complete(String q, McpMeta meta) { ... }","handlingStrategy":"validation","validationCode":"long metaParams = Arrays.stream(method.getParameters())\n    .filter(p -> McpMeta.class.isAssignableFrom(p.getType())).count();\nif (metaParams > 1) throw new IllegalStateException(\"Only one McpMeta parameter allowed\");","typeGuard":null,"tryCatchPattern":"try { registry.register(bean); } catch (IllegalArgumentException e) { log.error(\"Invalid @McpPrompt signature: {}\", e.getMessage()); }","preventionTips":["Declare McpMeta once and read all keys from it","Avoid mixing McpMeta with its subclasses in one signature","Review signatures after refactors for duplicated meta parameters"],"tags":["java","mcp","annotation","method-signature"],"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"}