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 {
253253 }
254254}
255255
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+
256275// NewToolResultStructured creates a new CallToolResult with structured content.
257276// It includes both the structured content and a text representation for backward compatibility.
258277func NewToolResultStructured (structured any , fallbackText string ) * CallToolResult {
You can’t perform that action at this time.
0 commit comments