Skip to content

Commit 785472c

Browse files
committed
fix: cr
1 parent a5fcec0 commit 785472c

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

mcp/utils.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func ExtractString(data map[string]any, key string) string {
492492
return ""
493493
}
494494

495-
func ParseAnnotaions(data map[string]any) *Annotations {
495+
func ParseAnnotations(data map[string]any) *Annotations {
496496
if data == nil {
497497
return nil
498498
}
@@ -504,12 +504,17 @@ func ParseAnnotaions(data map[string]any) *Annotations {
504504
}
505505

506506
if value, ok := data["audience"]; ok {
507-
if audience, ok := value.([]any); ok {
507+
switch audience := value.(type) {
508+
case []any:
508509
for _, a := range audience {
509510
if roleStr, ok := a.(string); ok {
510511
annotations.Audience = append(annotations.Audience, Role(roleStr))
511512
}
512513
}
514+
case []string:
515+
for _, a := range audience {
516+
annotations.Audience = append(annotations.Audience, Role(a))
517+
}
513518
}
514519
}
515520
return annotations
@@ -530,7 +535,7 @@ func ParseContent(contentMap map[string]any) (Content, error) {
530535

531536
var annotations *Annotations
532537
if annotationsMap := ExtractMap(contentMap, "annotations"); annotationsMap != nil {
533-
annotations = ParseAnnotaions(annotationsMap)
538+
annotations = ParseAnnotations(annotationsMap)
534539
}
535540

536541
switch contentType {

mcp/utils_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ func TestParseAnnotations(t *testing.T) {
1313
expected *Annotations
1414
}{
1515
{
16-
name: "nil data",
17-
data: nil,
16+
name: "nil data",
17+
data: nil,
1818
expected: nil,
1919
},
2020
{
21-
name: "empty data",
22-
data: map[string]any{},
21+
name: "empty data",
22+
data: map[string]any{},
2323
expected: &Annotations{},
2424
},
2525
{
@@ -74,11 +74,20 @@ func TestParseAnnotations(t *testing.T) {
7474
Audience: []Role{"user", "assistant"},
7575
},
7676
},
77+
{
78+
name: "audience as []string",
79+
data: map[string]any{
80+
"audience": []string{"assistant", "user"},
81+
},
82+
expected: &Annotations{
83+
Audience: []Role{"assistant", "user"},
84+
},
85+
},
7786
}
7887

7988
for _, tt := range tests {
8089
t.Run(tt.name, func(t *testing.T) {
81-
result := ParseAnnotaions(tt.data)
90+
result := ParseAnnotations(tt.data)
8291
assert.Equal(t, tt.expected, result)
8392
})
8493
}
@@ -296,13 +305,13 @@ func TestParseContent(t *testing.T) {
296305
for _, tt := range tests {
297306
t.Run(tt.name, func(t *testing.T) {
298307
result, err := ParseContent(tt.contentMap)
299-
308+
300309
if tt.expectError {
301310
assert.Error(t, err)
302311
assert.Nil(t, result)
303312
} else {
304313
assert.NoError(t, err)
305-
314+
306315
// Compare the actual content values
307316
switch exp := tt.expected.(type) {
308317
case TextContent:
@@ -346,4 +355,5 @@ func TestParseContent(t *testing.T) {
346355
}
347356
})
348357
}
349-
}
358+
}
359+

0 commit comments

Comments
 (0)