Skip to content

Commit c50d3b3

Browse files
committed
Add ModelPreferences builder and ModelHint helper
Signed-off-by: Christian Tzolov <[email protected]>
1 parent 4a213ec commit c50d3b3

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package io.modelcontextprotocol.spec;
66

77
import java.io.IOException;
8+
import java.util.ArrayList;
89
import java.util.HashMap;
910
import java.util.List;
1011
import java.util.Map;
@@ -763,15 +764,61 @@ public record CallToolResult( // @formatter:off
763764
@JsonInclude(JsonInclude.Include.NON_ABSENT)
764765
@JsonIgnoreProperties(ignoreUnknown = true)
765766
public record ModelPreferences(// @formatter:off
766-
@JsonProperty("hints") List<ModelHint> hints,
767-
@JsonProperty("costPriority") Double costPriority,
768-
@JsonProperty("speedPriority") Double speedPriority,
769-
@JsonProperty("intelligencePriority") Double intelligencePriority) {
770-
} // @formatter:on
767+
@JsonProperty("hints") List<ModelHint> hints,
768+
@JsonProperty("costPriority") Double costPriority,
769+
@JsonProperty("speedPriority") Double speedPriority,
770+
@JsonProperty("intelligencePriority") Double intelligencePriority) {
771+
772+
public static Builder builder() {
773+
return new Builder();
774+
}
775+
776+
public static class Builder {
777+
private List<ModelHint> hints;
778+
private Double costPriority;
779+
private Double speedPriority;
780+
private Double intelligencePriority;
781+
782+
public Builder hints(List<ModelHint> hints) {
783+
this.hints = hints;
784+
return this;
785+
}
786+
787+
public Builder addHint(String name) {
788+
if (this.hints == null) {
789+
this.hints = new ArrayList<>();
790+
}
791+
this.hints.add(new ModelHint(name));
792+
return this;
793+
}
794+
795+
public Builder costPriority(Double costPriority) {
796+
this.costPriority = costPriority;
797+
return this;
798+
}
799+
800+
public Builder speedPriority(Double speedPriority) {
801+
this.speedPriority = speedPriority;
802+
return this;
803+
}
804+
805+
public Builder intelligencePriority(Double intelligencePriority) {
806+
this.intelligencePriority = intelligencePriority;
807+
return this;
808+
}
809+
810+
public ModelPreferences build() {
811+
return new ModelPreferences(hints, costPriority, speedPriority, intelligencePriority);
812+
}
813+
}
814+
} // @formatter:on
771815

772816
@JsonInclude(JsonInclude.Include.NON_ABSENT)
773817
@JsonIgnoreProperties(ignoreUnknown = true)
774818
public record ModelHint(@JsonProperty("name") String name) {
819+
public static ModelHint of(String name) {
820+
return new ModelHint(name);
821+
}
775822
}
776823

777824
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@@ -855,7 +902,7 @@ public Builder metadata(Map<String, Object> metadata) {
855902
}
856903

857904
public CreateMessageRequest build() {
858-
return new CreateMessageRequest(messages, modelPreferences, systemPrompt,
905+
return new CreateMessageRequest(messages, modelPreferences, systemPrompt,
859906
includeContext, temperature, maxTokens, stopSequences, metadata);
860907
}
861908
}

0 commit comments

Comments
 (0)