spring-projects/spring-ai · error · IllegalArgumentException

Either prompt or uri must be provided!

Error message

Either prompt or uri must be provided!

What it means

AbstractMcpCompleteMethodCallback's constructor requires that a completion callback provide exactly one completion target: either a prompt name or a resource URI. When both are absent (null or empty), it throws this IllegalArgumentException at registration time because the callback would have nothing to complete against.

Solutions

  1. Set the prompt attribute if the completion is for a prompt: e.g. prompt = "myPrompt".
  2. Set the uri attribute instead if the completion is for a resource template: e.g. uri = "file:///documents/{path}".
  3. Ensure exactly one of the two is populated (see error 84 for the both-set case).

Example fix

// before
new AbstractMcpCompleteMethodCallback(method, bean, null, null, factory); // throws
// after
new AbstractMcpCompleteMethodCallback(method, bean, "myPrompt", null, factory);
Defensive patterns

Strategy: validation

Validate before calling

boolean hasPrompt = prompt != null && !prompt.isEmpty();
boolean hasUri = uri != null && !uri.isEmpty();
if (!hasPrompt && !hasUri) throw new IllegalStateException("set either prompt or uri for @McpComplete");

Try / catch

try {
    registry.registerCompleteCallback(method, bean, prompt, uri);
} catch (IllegalArgumentException e) {
    LOG.error("completion registration failed: {}", e.getMessage());
}

Prevention

When it happens

Trigger: Registering an @McpComplete-annotated completion method without setting either the prompt attribute or the uri attribute (both null/empty) in the specification or annotation.

Common situations: Forgetting the prompt attribute when moving from resource completion to prompt completion; copying a builder call and deleting both attributes; annotation processor not picking up default attribute values.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/bfef19ad6d9ad37b. Report an issue: GitHub.

Appendix: source

Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/AbstractMcpCompleteMethodCallback.java:87

	/**
	 * Constructor for AbstractMcpCompleteMethodCallback.
	 * @param method The method to create a callback for
	 * @param bean The bean instance that contains the method
	 * @param prompt The prompt reference
	 * @param uri The URI reference
	 * @param uriTemplateManagerFactory The URI template manager factory
	 */
	protected AbstractMcpCompleteMethodCallback(Method method, Object bean, String prompt, String uri,
			McpUriTemplateManagerFactory uriTemplateManagerFactory) {

		Assert.notNull(method, "Method can't be null!");
		Assert.notNull(bean, "Bean can't be null!");
		Assert.notNull(uriTemplateManagerFactory, "URI template manager factory can't be null!");

		// Either prompt or uri must be provided, but not both
		if ((prompt == null || prompt.isEmpty()) && (uri == null || uri.isEmpty())) {
			throw new IllegalArgumentException("Either prompt or uri must be provided!");
		}
		if ((prompt != null && !prompt.isEmpty()) && (uri != null && !uri.isEmpty())) {
			throw new IllegalArgumentException("Only one of prompt or uri can be provided!");
		}

		this.method = method;
		this.bean = bean;
		this.prompt = prompt;
		this.uri = uri;

		// Create the CompleteReference based on prompt or uri
		if (prompt != null && !prompt.isEmpty()) {
			this.completeReference = McpSchema.PromptReference.builder(prompt).build();
		}
		else {
			this.completeReference = new McpSchema.ResourceReference(uri);
		}

View on GitHub (pinned to 98a7beda4f)