{"record":{"id":"8116463a7ad5d6f5","repo":"spring-projects/spring-ai","slug":"only-one-of-prompt-or-uri-can-be-provided","errorCode":null,"errorMessage":"Only one of prompt or uri can be provided!","messagePattern":"Only one of prompt or uri can be provided!","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":90,"sourceCode":"\t * @param method The method to create a callback for\n\t * @param bean The bean instance that contains the method\n\t * @param prompt The prompt reference\n\t * @param uri The URI reference\n\t * @param uriTemplateManagerFactory The URI template manager factory\n\t */\n\tprotected AbstractMcpCompleteMethodCallback(Method method, Object bean, String prompt, String uri,\n\t\t\tMcpUriTemplateManagerFactory uriTemplateManagerFactory) {\n\n\t\tAssert.notNull(method, \"Method can't be null!\");\n\t\tAssert.notNull(bean, \"Bean can't be null!\");\n\t\tAssert.notNull(uriTemplateManagerFactory, \"URI template manager factory can't be null!\");\n\n\t\t// Either prompt or uri must be provided, but not both\n\t\tif ((prompt == null || prompt.isEmpty()) && (uri == null || uri.isEmpty())) {\n\t\t\tthrow new IllegalArgumentException(\"Either prompt or uri must be provided!\");\n\t\t}\n\t\tif ((prompt != null && !prompt.isEmpty()) && (uri != null && !uri.isEmpty())) {\n\t\t\tthrow new IllegalArgumentException(\"Only one of prompt or uri can be provided!\");\n\t\t}\n\n\t\tthis.method = method;\n\t\tthis.bean = bean;\n\t\tthis.prompt = prompt;\n\t\tthis.uri = uri;\n\n\t\t// Create the CompleteReference based on prompt or uri\n\t\tif (prompt != null && !prompt.isEmpty()) {\n\t\t\tthis.completeReference = McpSchema.PromptReference.builder(prompt).build();\n\t\t}\n\t\telse {\n\t\t\tthis.completeReference = new McpSchema.ResourceReference(uri);\n\t\t}\n\n\t\tif (uri != null && !uri.isEmpty()) {\n\t\t\tthis.uriTemplateManager = uriTemplateManagerFactory.create(this.uri);\n\t\t\tthis.uriVariables = this.uriTemplateManager.getVariableNames();","sourceCodeStart":72,"sourceCodeEnd":108,"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#L72-L108","documentation":"AbstractMcpCompleteMethodCallback enforces mutual exclusivity: a completion callback may target a prompt OR a resource URI, but never both. Providing both non-empty values throws this IllegalArgumentException at construction, since the library could not determine which completion target the method serves.","triggerScenarios":"Constructing the callback (or annotating with @McpComplete) with both prompt and uri set to non-empty values simultaneously.","commonSituations":"Copy-pasting a builder/annotation configuration and forgetting to clear the other attribute; combining a prompt-completion example with a resource-completion example; templating code that fills both placeholders.","solutions":["Remove either the prompt or the uri value so exactly one remains.","If you need completions for both a prompt and a resource, register two separate callback methods/specifications.","Audit the @McpComplete annotation attributes to ensure only one target is declared."],"exampleFix":"// before\n@McpComplete(prompt = \"myPrompt\", uri = \"file:///{path}\") // throws\n// after\n@McpComplete(prompt = \"myPrompt\")","handlingStrategy":"validation","validationCode":"boolean hasPrompt = prompt != null && !prompt.isEmpty();\nboolean hasUri = uri != null && !uri.isEmpty();\nif (hasPrompt && hasUri) throw new IllegalStateException(\"choose either prompt or uri, not both\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set only one of prompt/uri per completion method.","Create separate methods for prompt completion and resource completion.","Code-review @McpComplete attributes for accidental dual targets."],"tags":["mcp","validation","mutually-exclusive","completion"],"backgroundTag":"mutually-exclusive-options","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"}