@@ -1194,3 +1194,60 @@ func TestContentUnmarshal(t *testing.T) {
11941194 var gotpm PromptMessage
11951195 roundtrip (pm , & gotpm )
11961196}
1197+
1198+ func TestToolAnnotations_MarshalJSON (t * testing.T ) {
1199+ boolPtr := func (b bool ) * bool { return & b }
1200+
1201+ tests := []struct {
1202+ name string
1203+ in ToolAnnotations
1204+ want string
1205+ }{
1206+ {
1207+ name : "ZeroValue" ,
1208+ in : ToolAnnotations {},
1209+ want : `{"idempotentHint":false,"readOnlyHint":false}` ,
1210+ },
1211+ {
1212+ name : "AllFalse" ,
1213+ in : ToolAnnotations {
1214+ DestructiveHint : boolPtr (false ),
1215+ IdempotentHint : false ,
1216+ OpenWorldHint : boolPtr (false ),
1217+ ReadOnlyHint : false ,
1218+ },
1219+ want : `{"destructiveHint":false,"idempotentHint":false,"openWorldHint":false,"readOnlyHint":false}` ,
1220+ },
1221+ {
1222+ name : "AllTrue" ,
1223+ in : ToolAnnotations {
1224+ DestructiveHint : boolPtr (true ),
1225+ IdempotentHint : true ,
1226+ OpenWorldHint : boolPtr (true ),
1227+ ReadOnlyHint : true ,
1228+ Title : "my tool" ,
1229+ },
1230+ want : `{"destructiveHint":true,"idempotentHint":true,"openWorldHint":true,"readOnlyHint":true,"title":"my tool"}` ,
1231+ },
1232+ {
1233+ name : "MixedValues" ,
1234+ in : ToolAnnotations {
1235+ ReadOnlyHint : true ,
1236+ Title : "read tool" ,
1237+ },
1238+ want : `{"idempotentHint":false,"readOnlyHint":true,"title":"read tool"}` ,
1239+ },
1240+ }
1241+
1242+ for _ , tt := range tests {
1243+ t .Run (tt .name , func (t * testing.T ) {
1244+ got , err := json .Marshal (tt .in )
1245+ if err != nil {
1246+ t .Fatalf ("json.Marshal(%v) failed: %v" , tt .in , err )
1247+ }
1248+ if diff := cmp .Diff (tt .want , string (got )); diff != "" {
1249+ t .Errorf ("json.Marshal() mismatch (-want +got):\n %s" , diff )
1250+ }
1251+ })
1252+ }
1253+ }
0 commit comments