McpSchema类
·
1 基本信息
1.1 来源:
这个类是 下面的依赖中的

依赖关系
+- org.springframework.ai:spring-ai-mcp:jar:1.0.0-SNAPSHOT:compile
[INFO] | +- io.modelcontextprotocol.sdk:mcp:jar:0.10.0:compile
可以看出这个是官方的.
1.2 内容
这个类主要是对mcp中的数据结构进行定义的类,包含请求 ,响应以及工具调用的参数说明.
简单来说uiu是rpcschema和inputschema
2 具体内容举例
例如:CallToolResult
public static record CallToolResult(List<Content> content, Boolean isError) {
public CallToolResult(String content, Boolean isError) {
this(List.of(new TextContent(content)), isError);
}
public CallToolResult(@JsonProperty("content") List<Content> content, @JsonProperty("isError") Boolean isError) {
this.content = content;
this.isError = isError;
}
public static Builder builder() {
return new Builder();
}
@JsonProperty("content")
public List<Content> content() {
return this.content;
}
@JsonProperty("isError")
public Boolean isError() {
return this.isError;
}
public static class Builder {
private List<Content> content = new ArrayList();
private Boolean isError;
public Builder() {
}
public Builder content(List<Content> content) {
Assert.notNull(content, "content must not be null");
this.content = content;
return this;
}
public Builder textContent(List<String> textContent) {
Assert.notNull(textContent, "textContent must not be null");
Stream var10000 = textContent.stream().map(TextContent::new);
List var10001 = this.content;
Objects.requireNonNull(var10001);
var10000.forEach(var10001::add);
return this;
}
public Builder addContent(Content contentItem) {
Assert.notNull(contentItem, "contentItem must not be null");
if (this.content == null) {
this.content = new ArrayList();
}
this.content.add(contentItem);
return this;
}
public Builder addTextContent(String text) {
Assert.notNull(text, "text must not be null");
return this.addContent(new TextContent(text));
}
public Builder isError(Boolean isError) {
Assert.notNull(isError, "isError must not be null");
this.isError = isError;
return this;
}
public CallToolResult build() {
return new CallToolResult(this.content, this.isError);
}
}
}
这个类是call工具结果的类,这种builder初始化的类在框架中经常出现,就是一个静态builder方法,然后里面初始化内部类Builder,拿到这个builder之后,再调用它的build方法就完成了真正的初始化
比如:
CallToolResult.Builder builder = CallToolResult.builder();
然后设置内容
builder.content
最后调用build方法构建返回对象
CallToolResult result = builder.build();更多推荐


所有评论(0)