File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -253,6 +253,25 @@ func NewToolResultText(text string) *CallToolResult {
253
253
}
254
254
}
255
255
256
+ // NewToolResultJSON creates a new CallToolResult with a JSON content.
257
+ // This function panics if the JSON marshalling fails.
258
+ func NewToolResultJSON [T any ](data T ) * CallToolResult {
259
+ b , err := json .Marshal (data )
260
+ if err != nil {
261
+ panic ("unable to marshal JSON" )
262
+ }
263
+
264
+ return & CallToolResult {
265
+ Content : []Content {
266
+ TextContent {
267
+ Type : ContentTypeText ,
268
+ Text : string (b ),
269
+ },
270
+ },
271
+ StructuredContent : data ,
272
+ }
273
+ }
274
+
256
275
// NewToolResultStructured creates a new CallToolResult with structured content.
257
276
// It includes both the structured content and a text representation for backward compatibility.
258
277
func NewToolResultStructured (structured any , fallbackText string ) * CallToolResult {
You can’t perform that action at this time.
0 commit comments