Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,8 @@ private McpRequestHandler<McpSchema.CompleteResult> completionCompleteRequestHan
.message("Prompt not found: " + promptReference.name())
.build());
}
if (!promptSpec.prompt()
.arguments()
.stream()
List<McpSchema.PromptArgument> promptArgs = promptSpec.prompt().arguments();
if (promptArgs != null && !promptArgs.stream()
.filter(arg -> arg.name().equals(argumentName))
.findFirst()
.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,8 @@ private McpStatelessRequestHandler<McpSchema.CompleteResult> completionCompleteR
.message("Prompt not found: " + promptReference.name())
.build());
}
if (!promptSpec.prompt()
.arguments()
.stream()
List<McpSchema.PromptArgument> promptArgs = promptSpec.prompt().arguments();
if (promptArgs != null && !promptArgs.stream()
.filter(arg -> arg.name().equals(argumentName))
.findFirst()
.isPresent()) {
Expand Down
19 changes: 17 additions & 2 deletions mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.TypeRef;
import io.modelcontextprotocol.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Based on the <a href="http://www.jsonrpc.org/specification">JSON-RPC 2.0
Expand Down Expand Up @@ -1177,6 +1179,19 @@ public Prompt(String name, String description, List<PromptArgument> arguments) {
public Prompt(String name, String title, String description, List<PromptArgument> arguments) {
this(name, title, description, arguments, null);
}

/**
* Creates a Prompt that coerces {@code null} arguments to an empty list,
* preserving the 1.x behaviour. Use this factory when callers expect
* {@code prompt.arguments()} to never return {@code null}.
* @param name the prompt name
* @param description an optional description
* @param arguments the argument list, or {@code null} to default to an empty list
* @return a new Prompt with non-null arguments
*/
public static Prompt withDefaults(String name, String description, List<PromptArgument> arguments) {
return new Prompt(name, null, description, arguments != null ? arguments : new ArrayList<>(), null);
}
}

/**
Expand Down