@@ -4234,12 +4234,12 @@ static SetLevelRequest fromJson(@JsonProperty("level") LoggingLevel level) {
42344234 * requests. Implementations are identified by a {@code "type"} discriminator field
42354235 * whose value maps to a concrete subtype via {@code @JsonSubTypes}.
42364236 */
4237- @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , include = JsonTypeInfo .As .PROPERTY , property = "type" )
4237+ @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , include = JsonTypeInfo .As .EXISTING_PROPERTY , property = "type" ,
4238+ visible = true )
42384239 @ JsonSubTypes ({ @ JsonSubTypes .Type (value = PromptReference .class , name = PromptReference .TYPE ),
42394240 @ JsonSubTypes .Type (value = ResourceReference .class , name = ResourceReference .TYPE ) })
42404241 public interface CompleteReference {
42414242
4242- @ JsonIgnore
42434243 default String type () {
42444244 if (this instanceof PromptReference ) {
42454245 return PromptReference .TYPE ;
@@ -4262,21 +4262,46 @@ default String identifier() {
42624262 *
42634263 * @param name The name of the prompt
42644264 * @param title An optional title for the prompt
4265+ * @param type Always {@value #TYPE}; present for compatibility and read by the parent
4266+ * {@code @JsonTypeInfo} as the polymorphic discriminator
42654267 */
42664268 @ JsonInclude (JsonInclude .Include .NON_ABSENT )
42674269 @ JsonIgnoreProperties (ignoreUnknown = true )
42684270 public record PromptReference ( // @formatter:off
42694271 @ JsonProperty ("name" ) String name ,
4270- @ JsonProperty ("title" ) String title ) implements McpSchema .CompleteReference , Identifier { // @formatter:on
4272+ @ JsonProperty ("title" ) String title ,
4273+ @ JsonProperty ("type" ) String type ) implements McpSchema .CompleteReference , Identifier { // @formatter:on
42714274
42724275 public static final String TYPE = "ref/prompt" ;
42734276
42744277 public PromptReference {
42754278 Assert .hasText (name , "name must not be null or empty" );
4279+ type = TYPE ;
4280+ }
4281+
4282+ @ JsonCreator
4283+ static PromptReference fromJson (@ JsonProperty ("name" ) String name , @ JsonProperty ("title" ) String title ,
4284+ @ JsonProperty ("type" ) String type ) {
4285+ return new PromptReference (name , title , type );
4286+ }
4287+
4288+ /**
4289+ * @deprecated The {@code type} argument is ignored — the type discriminator is
4290+ * always {@value #TYPE}. Use {@link #PromptReference(String)} or the
4291+ * {@link #builder(String)} instead. In the future the builder might be removed
4292+ * and the two-arg {@code (String, String)} constructor would mean {@link #name()}
4293+ * and {@link #title()}.
4294+ */
4295+ @ Deprecated
4296+ public PromptReference (String type , String name ) {
4297+ this (name , null , null );
4298+ logger .warn (
4299+ "PromptReference(String, String): the 'type' argument '{}' is ignored, type is always '{}'. Use PromptReference(String) or the builder." ,
4300+ type , TYPE );
42764301 }
42774302
42784303 public PromptReference (String name ) {
4279- this (name , null );
4304+ this (name , null , null );
42804305 }
42814306
42824307 @ Override
@@ -4298,6 +4323,32 @@ public boolean equals(Object obj) {
42984323 public int hashCode () {
42994324 return java .util .Objects .hash (name );
43004325 }
4326+
4327+ public static Builder builder (String name ) {
4328+ return new Builder (name );
4329+ }
4330+
4331+ public static final class Builder {
4332+
4333+ private final String name ;
4334+
4335+ private String title ;
4336+
4337+ private Builder (String name ) {
4338+ this .name = name ;
4339+ }
4340+
4341+ public Builder title (String title ) {
4342+ this .title = title ;
4343+ return this ;
4344+ }
4345+
4346+ public PromptReference build () {
4347+ return new PromptReference (name , title , null );
4348+ }
4349+
4350+ }
4351+
43014352 }
43024353
43034354 // TODO: this should actually be a ResourceTemplateReference
@@ -4317,6 +4368,17 @@ public record ResourceReference( // @formatter:off
43174368 Assert .notNull (uri , "uri must not be null" );
43184369 }
43194370
4371+ @ JsonProperty ("type" )
4372+ @ Override
4373+ public String type () {
4374+ return CompleteReference .super .type ();
4375+ }
4376+
4377+ @ JsonCreator
4378+ static ResourceReference fromJson (@ JsonProperty ("uri" ) String uri , @ JsonProperty ("type" ) String type ) {
4379+ return new ResourceReference (uri );
4380+ }
4381+
43204382 @ Deprecated
43214383 public ResourceReference (String type , String uri ) {
43224384 this (uri );
0 commit comments