|
| 1 | +package tools |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/modelcontextprotocol/go-sdk/mcp" |
| 7 | +) |
| 8 | + |
| 9 | +func TestDefaultIcons(t *testing.T) { |
| 10 | + icons := DefaultIcons() |
| 11 | + if len(icons) != 1 { |
| 12 | + t.Fatalf("expected 1 default icon, got %d", len(icons)) |
| 13 | + } |
| 14 | + if icons[0].Source == "" { |
| 15 | + t.Error("default icon source should not be empty") |
| 16 | + } |
| 17 | + if icons[0].MIMEType != "image/svg+xml" { |
| 18 | + t.Errorf("expected MIME type image/svg+xml, got %s", icons[0].MIMEType) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +func TestGetIcons_DefaultPriority(t *testing.T) { |
| 23 | + tk := NewToolkit(nil) |
| 24 | + icons := tk.getIcons(ToolListBuckets, nil) |
| 25 | + if len(icons) != 1 { |
| 26 | + t.Fatalf("expected 1 icon, got %d", len(icons)) |
| 27 | + } |
| 28 | + if icons[0].Source != defaultIcons[0].Source { |
| 29 | + t.Errorf("expected default icon source, got %s", icons[0].Source) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func TestGetIcons_ToolkitOverride(t *testing.T) { |
| 34 | + customIcons := []mcp.Icon{{Source: "https://example.com/custom.svg", MIMEType: "image/svg+xml"}} |
| 35 | + tk := NewToolkit(nil, WithIcons(map[ToolName][]mcp.Icon{ |
| 36 | + ToolListBuckets: customIcons, |
| 37 | + })) |
| 38 | + |
| 39 | + // ToolListBuckets should get the override |
| 40 | + icons := tk.getIcons(ToolListBuckets, nil) |
| 41 | + if len(icons) != 1 { |
| 42 | + t.Fatalf("expected 1 icon, got %d", len(icons)) |
| 43 | + } |
| 44 | + if icons[0].Source != "https://example.com/custom.svg" { |
| 45 | + t.Errorf("expected custom icon source, got %s", icons[0].Source) |
| 46 | + } |
| 47 | + |
| 48 | + // ToolGetObject should get the default |
| 49 | + icons = tk.getIcons(ToolGetObject, nil) |
| 50 | + if icons[0].Source != defaultIcons[0].Source { |
| 51 | + t.Errorf("expected default icon source for ToolGetObject, got %s", icons[0].Source) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func TestGetIcons_PerRegistrationOverride(t *testing.T) { |
| 56 | + tk := NewToolkit(nil, WithIcons(map[ToolName][]mcp.Icon{ |
| 57 | + ToolListBuckets: {{Source: "https://example.com/toolkit.svg"}}, |
| 58 | + })) |
| 59 | + |
| 60 | + // Per-registration should take highest priority |
| 61 | + cfg := &toolConfig{ |
| 62 | + icons: []mcp.Icon{{Source: "https://example.com/registration.svg"}}, |
| 63 | + } |
| 64 | + icons := tk.getIcons(ToolListBuckets, cfg) |
| 65 | + if len(icons) != 1 { |
| 66 | + t.Fatalf("expected 1 icon, got %d", len(icons)) |
| 67 | + } |
| 68 | + if icons[0].Source != "https://example.com/registration.svg" { |
| 69 | + t.Errorf("expected per-registration icon source, got %s", icons[0].Source) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func TestGetIcons_NilConfig(t *testing.T) { |
| 74 | + tk := NewToolkit(nil) |
| 75 | + icons := tk.getIcons(ToolListBuckets, nil) |
| 76 | + if len(icons) == 0 { |
| 77 | + t.Fatal("expected default icons, got empty") |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +func TestGetIcons_EmptyToolConfig(t *testing.T) { |
| 82 | + tk := NewToolkit(nil) |
| 83 | + cfg := &toolConfig{} |
| 84 | + icons := tk.getIcons(ToolListBuckets, cfg) |
| 85 | + if len(icons) == 0 { |
| 86 | + t.Fatal("expected default icons, got empty") |
| 87 | + } |
| 88 | + if icons[0].Source != defaultIcons[0].Source { |
| 89 | + t.Errorf("expected default icon, got %s", icons[0].Source) |
| 90 | + } |
| 91 | +} |
0 commit comments