@@ -82,21 +82,32 @@ const (
82
82
ContentTypeText ContentType = "text"
83
83
ContentTypeImage ContentType = "image"
84
84
ContentTypeEmbeddedResource ContentType = "embedded-resource"
85
- ContentTypeError ContentType = "error"
86
85
)
87
86
88
87
// This is a union type of all the different ToolResponse that can be sent back to the client.
89
88
// We allow creation through constructors only to make sure that the ToolResponse is valid.
90
89
type ToolResponse struct {
90
+ Content []ToolResponseContent
91
+ Error error
92
+ }
93
+
94
+ func NewToolReponse (content ... ToolResponseContent ) * ToolResponse {
95
+ return & ToolResponse {
96
+ Content : content ,
97
+ }
98
+ }
99
+
100
+ type ToolResponseContent struct {
91
101
Type ContentType
92
102
TextContent * TextContent
93
103
ImageContent * ImageContent
94
104
EmbeddedResource * EmbeddedResource
95
105
Annotations * ContentAnnotations
96
- Error error
97
106
}
98
107
99
- func (c * ToolResponse ) WithAnnotations (annotations ContentAnnotations ) * ToolResponse {
108
+ // Custom JSON marshaling for ToolResponse.
109
+
110
+ func (c * ToolResponseContent ) WithAnnotations (annotations ContentAnnotations ) * ToolResponseContent {
100
111
c .Annotations = & annotations
101
112
return c
102
113
}
@@ -105,34 +116,33 @@ func (c *ToolResponse) WithAnnotations(annotations ContentAnnotations) *ToolResp
105
116
// This is used to create a result that will be returned to the client as an error for a tool call.
106
117
func NewToolError (err error ) * ToolResponse {
107
118
return & ToolResponse {
108
- Type : ContentTypeError ,
109
119
Error : err ,
110
120
}
111
121
}
112
122
113
- // NewToolImageResponse creates a new ToolResponse that is an image.
123
+ // NewToolImageResponseContent creates a new ToolResponse that is an image.
114
124
// The given data is base64-encoded
115
- func NewToolImageResponse (base64EncodedStringData string , mimeType string ) * ToolResponse {
116
- return & ToolResponse {
125
+ func NewToolImageResponseContent (base64EncodedStringData string , mimeType string ) * ToolResponseContent {
126
+ return & ToolResponseContent {
117
127
Type : ContentTypeImage ,
118
128
ImageContent : & ImageContent {Data : base64EncodedStringData , MimeType : mimeType },
119
129
}
120
130
}
121
131
122
- // NewToolTextResponse creates a new ToolResponse that is a simple text string.
132
+ // NewToolTextResponseContent creates a new ToolResponse that is a simple text string.
123
133
// The client will render this as a single string.
124
- func NewToolTextResponse (content string ) * ToolResponse {
125
- return & ToolResponse {
134
+ func NewToolTextResponseContent (content string ) * ToolResponseContent {
135
+ return & ToolResponseContent {
126
136
Type : ContentTypeText ,
127
137
TextContent : & TextContent {Text : content },
128
138
}
129
139
}
130
140
131
- // NewToolBlobResourceResponse creates a new ToolResponse that is a blob of binary data.
141
+ // NewToolBlobResourceResponseContent creates a new ToolResponse that is a blob of binary data.
132
142
// The given data is base64-encoded; the client will decode it.
133
143
// The client will render this as a blob; it will not be human-readable.
134
- func NewToolBlobResourceResponse (uri string , base64EncodedData string , mimeType string ) * ToolResponse {
135
- return & ToolResponse {
144
+ func NewToolBlobResourceResponseContent (uri string , base64EncodedData string , mimeType string ) * ToolResponseContent {
145
+ return & ToolResponseContent {
136
146
Type : ContentTypeEmbeddedResource ,
137
147
EmbeddedResource : & EmbeddedResource {
138
148
EmbeddedResourceType : EmbeddedResourceTypeBlob ,
@@ -144,11 +154,11 @@ func NewToolBlobResourceResponse(uri string, base64EncodedData string, mimeType
144
154
}
145
155
}
146
156
147
- // NewToolTextResourceResponse creates a new ToolResponse that is an embedded resource of type "text".
157
+ // NewToolTextResourceResponseContent creates a new ToolResponse that is an embedded resource of type "text".
148
158
// The given text is embedded in the response as a TextResourceContents, which
149
159
// contains the given MIME type and URI. The text is not base64-encoded.
150
- func NewToolTextResourceResponse (uri string , text string , mimeType string ) * ToolResponse {
151
- return & ToolResponse {
160
+ func NewToolTextResourceResponseContent (uri string , text string , mimeType string ) * ToolResponseContent {
161
+ return & ToolResponseContent {
152
162
Type : ContentTypeEmbeddedResource ,
153
163
EmbeddedResource : & EmbeddedResource {
154
164
EmbeddedResourceType : EmbeddedResourceTypeText ,
0 commit comments