File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -267,12 +267,18 @@ func NewToolResultStructured(structured any, fallbackText string) *CallToolResul
267
267
}
268
268
}
269
269
270
- // NewToolResultStructuredOnly creates a new CallToolResult with only structured content.
271
- // This is useful when you want to provide structured data without a text fallback.
270
+ // NewToolResultStructuredOnly creates a new CallToolResult with structured
271
+ // content and creates a JSON string fallback for backwards compatibility.
272
+ // This is useful when you want to provide structured data without any specific text fallback.
272
273
func NewToolResultStructuredOnly (structured any ) * CallToolResult {
274
+ var fallbackText string
273
275
// Convert to JSON string for backward compatibility
274
- jsonBytes , _ := json .Marshal (structured )
275
- fallbackText := string (jsonBytes )
276
+ jsonBytes , err := json .Marshal (structured )
277
+ if err != nil {
278
+ fallbackText = fmt .Sprintf ("Error serializing structured content: %v" , err )
279
+ } else {
280
+ fallbackText = string (jsonBytes )
281
+ }
276
282
277
283
return & CallToolResult {
278
284
Content : []Content {
@@ -477,7 +483,6 @@ func FormatNumberResult(value float64) *CallToolResult {
477
483
return NewToolResultText (fmt .Sprintf ("%.2f" , value ))
478
484
}
479
485
480
-
481
486
func ExtractString (data map [string ]any , key string ) string {
482
487
if value , ok := data [key ]; ok {
483
488
if str , ok := value .(string ); ok {
You can’t perform that action at this time.
0 commit comments