{"record":{"id":"7945705504222327","repo":"spring-projects/spring-ai","slug":"either-prompt-or-uri-must-be-provided-in-mcpcomple","errorCode":null,"errorMessage":"Either prompt or uri must be provided in McpComplete annotation","messagePattern":"Either prompt or uri must be provided in McpComplete annotation","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/adapter/CompleteAdapter.java","lineNumber":52,"sourceCode":"\tprivate CompleteAdapter() {\n\t}\n\n\t/**\n\t * Convert a McpComplete annotation to a McpSchema.CompleteReference object.\n\t * @param mcpComplete The McpComplete annotation\n\t * @return The corresponding McpSchema.CompleteReference object\n\t * @throws IllegalArgumentException if neither prompt nor uri is provided, or if both\n\t * are provided\n\t */\n\tpublic static McpSchema.CompleteReference asCompleteReference(McpComplete mcpComplete) {\n\t\tAssert.notNull(mcpComplete, \"mcpComplete cannot be null\");\n\n\t\tString prompt = mcpComplete.prompt();\n\t\tString uri = mcpComplete.uri();\n\n\t\t// Validate that either prompt or uri is 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 in McpComplete annotation\");\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 in McpComplete annotation\");\n\t\t}\n\n\t\t// Create the appropriate reference type based on what's provided\n\t\tif (prompt != null && !prompt.isEmpty()) {\n\t\t\treturn McpSchema.PromptReference.builder(prompt).build();\n\t\t}\n\t\telse {\n\t\t\treturn new McpSchema.ResourceReference(uri);\n\t\t}\n\t}\n\n\t/**\n\t * Convert a McpComplete annotation and Method to a McpSchema.CompleteReference\n\t * object.\n\t * @param mcpComplete The McpComplete annotation","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/adapter/CompleteAdapter.java#L34-L70","documentation":"CompleteAdapter.asCompleteReference converts an @McpComplete annotation into an MCP completion reference. The MCP spec requires a completion request to target exactly one of a prompt name or a resource URI. This error is thrown when the McpComplete annotation specifies neither a prompt nor a uri.","triggerScenarios":"Annotating a method with @McpComplete but leaving both prompt() and uri() at their defaults (null or empty string), then the adapter calls asCompleteReference during annotation processing.","commonSituations":"Developer adds @McpComplete for autocompletion support but forgets to fill in the prompt attribute; refactoring moves the prompt name out and leaves the annotation empty; copying an annotation template without editing its fields.","solutions":["Set either the prompt or uri attribute on the @McpComplete annotation, e.g. @McpComplete(prompt = \"my-prompt\")","If the completion targets a resource, set uri instead: @McpComplete(uri = \"file:///logs/{path}\")","Remove the @McpComplete annotation entirely if no completion is intended"],"exampleFix":"// before\n@McpComplete\npublic List<String> complete(String argument) { ... }\n\n// after\n@McpComplete(prompt = \"code-review\")\npublic List<String> complete(String argument) { ... }","handlingStrategy":"validation","validationCode":"McpComplete ann = ...;\nboolean promptSet = ann.prompt() != null && !ann.prompt().isEmpty();\nboolean uriSet = ann.uri() != null && !ann.uri().isEmpty();\nif (!promptSet && !uriSet) {\n    throw new IllegalStateException(\"@McpComplete requires prompt or uri\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass exactly one of prompt or uri when writing @McpComplete","Add a unit test that builds the reference for every annotated method","Rely on compile-time constants for the attribute values"],"tags":["mcp","annotation-validation","completion"],"backgroundTag":"missing-required-argument","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"}