diff --git a/internal/gui/assets/library.js b/internal/gui/assets/library.js index a6f1350d7..33a21aa3b 100644 --- a/internal/gui/assets/library.js +++ b/internal/gui/assets/library.js @@ -82,6 +82,7 @@ // Agent chips for a server or a skill: each agent that could have it, lit // when it does. A chip whose agent couldn't be given it says why. function agentChips(all, on, onChange, opts = {}) { + on ||= []; const box = el("div", "lib-agents"); for (const a of all) { const has = on.includes(a.id); diff --git a/internal/library/library_test.go b/internal/library/library_test.go index edaec9c0a..df067d4bd 100644 --- a/internal/library/library_test.go +++ b/internal/library/library_test.go @@ -500,3 +500,18 @@ func TestGitHubSource(t *testing.T) { } } } + +// A server or skill on no agent is listed with none, not null: the page +// looks in the list, and a null blanked the whole Library. +func TestReadNoAgents(t *testing.T) { + sandbox(t) + ok(t)(SaveServer("", Server{Name: "lone", Transport: "stdio", Command: "lone-mcp"})) + v, err := Read(nil) + if err != nil { + t.Fatal(err) + } + b, _ := json.Marshal(v.Servers) + if !strings.Contains(string(b), `"agents":[]`) { + t.Errorf("servers: %s", b) + } +} diff --git a/internal/library/sync.go b/internal/library/sync.go index 4d1fc5848..51e6d6296 100644 --- a/internal/library/sync.go +++ b/internal/library/sync.go @@ -196,6 +196,12 @@ func Read(problems []Problem) (*View, error) { return m } for _, s := range l.MCP { + // one on no agent yet has none, not null, for the page to look in + if s.Agents == nil { + c := *s + c.Agents = []string{} + s = &c + } sv := ServerView{Server: s, Icon: serverIcon(l, s), Problems: of("mcp:" + s.Name)} for _, t := range targets { if t.MCP != nil && slices.Contains(s.Agents, t.Agent.ID) { @@ -210,7 +216,7 @@ func Read(problems []Problem) (*View, error) { v.Servers = append(v.Servers, sv) } for _, s := range l.Skills { - sv := SkillView{Name: s.Name, Agents: s.Agents, Icon: skillIcon(s), Problems: of("skill:" + s.Name)} + sv := SkillView{Name: s.Name, Agents: append([]string{}, s.Agents...), Icon: skillIcon(s), Problems: of("skill:" + s.Name)} if s.Source != nil { sv.Source, sv.Kind = s.Source.String(), s.Source.Kind }