diff --git a/CHANGELOG.md b/CHANGELOG.md index 341df3b..aeb5672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ Newest first. Each release's section is its GitHub release notes and its OBS changelog entry (packaging/suse/README.md). +## Unreleased + +- The tools say what is documented, for clients that do not pass the + server's instructions to their model (Kit): `find_sections`' + description opens with the collections' titles, and `find_sections`' + and `search`'s `collection` parameter lists the collections' names, so + that a model neither answers from memory nor guesses a name + (docs/architecture.md §17.8). About 220 tokens more per session with + the thirteen SUSE collections. + ## v0.4.1 — 2026-11-17 - New package: `suse-docs-mcp-rancher-ai-1.2`, the documentation of diff --git a/docs/architecture.md b/docs/architecture.md index 27c5f83..5624a17 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1864,6 +1864,41 @@ session (stdin/stdout): a user has few instances (128 by default), a session is over after a few calls, and many run at once. A collection with documents elsewhere (`also`) is walked, not watched. +### 17.8 The tools say what is documented + +Not every client gives its model the server's `instructions`. Kit +(0.143) keeps the `initialize` result only to see whether the server +offers tasks; its model sees the tools, prefixed with the server's key +(`suse-docs__find_sections`), under Kit's own prompt of a coding +assistant. The instructions are where the collections were named, so +such a model saw tools that read "documentation" without knowing which: +it answered questions about SLES from memory or with its shell, and +guessed collection names (`suse-16.1`). + +So the tools name the collections too: + +- **`find_sections`' description opens with what is documented**: "The + documentation on this system: SUSE Linux Enterprise Server 16.1; + SUSE Rancher Prime: RKE2; …", by the collections' titles (their names + where they have none), at most 600 bytes, then "and N more". Without + `find_sections` (`--tools`), `search` says it. +- **`find_sections`' and `search`'s `collection` parameter lists the + names** (`enum`): a model picks one there is. `list_docs` does not + repeat them; called without a collection, it lists them. A name that + is not one is answered, as before, with the names there are. + +It costs every session, cached or not: 101 bytes with one collection, +875 bytes (~220 tokens) with the thirteen SUSE collections, against a +tool list of 5.1 KB. The instructions keep the list as well, with the +descriptions, for clients that pass them. `TestSessionCost`'s budget for +the tool definitions is 5.25 KiB, from 5 KiB. + +A client can steer its model further with its own configuration: in +Kit, a user skill (`~/.config/kit/skills/NAME/SKILL.md`, whose +description is in every prompt), `system-prompt` (which replaces Kit's +prompt), or `AGENTS.md` (read only in the directory Kit starts in). +mcp-docs no longer depends on them to be found. + ## 18. SUSE's cloud-native products: AsciiDoc and Antora SUSE's documentation of Rancher and what belongs to it diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index 3d6ab62..8b6d975 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -394,7 +394,10 @@ func TestSessionCost(t *testing.T) { instructions int tools int }{ - {false, nil, 2 << 10, 5 << 10}, + // The tool definitions name the collections (find_sections' + // description, find_sections' and search's collection enum, + // §17.8): 101 B for this one, more for each further collection. + {false, nil, 2 << 10, 5<<10 + 256}, {true, nil, 2 << 10, 8 << 10}, {false, []string{"find_sections", "read_section", "outline"}, 2 << 10, 5 << 9}, } { diff --git a/internal/server/server.go b/internal/server/server.go index 6f76d3a..4af6a04 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -264,10 +264,73 @@ func allToolNames() []string { return out } +// maxDocumented bounds the list of what the collections document in a +// tool's description (documented): it is sent in every session. +const maxDocumented = 600 + +// documented is what the collections document, by their titles (their +// names where they have none), for the description of the tool a +// question starts with: a client that does not give its model the +// server's instructions (Kit) sends it only the tools, and a model that +// does not know what they cover answers from memory instead. +func (s *Server) documented() string { + var titles []string + for _, k := range s.Cat.Collections { + t := k.Title + if t == "" { + t = k.Name + } + if !slices.Contains(titles, t) { + titles = append(titles, t) + } + } + out := "" + for i, t := range titles { + next := out + if i > 0 { + next += "; " + } + next += t + if len(next) > maxDocumented { + return fmt.Sprintf("%s; and %d more", out, len(titles)-i) + } + out = next + } + return out +} + +// entryTool is the tool a question starts with, whose description says +// what the documentation covers: find_sections, else search. +func (s *Server) entryTool() string { + for _, n := range []string{"find_sections", "search"} { + if s.has(n) { + return n + } + } + return "" +} + func (s *Server) toolList() []map[string]any { var out []map[string]any + entry := s.entryTool() + var names []string + for _, k := range s.Cat.Collections { + names = append(names, k.Name) + } for _, t := range s.tools() { - m := map[string]any{"name": t.name, "title": t.title, "description": t.description, "inputSchema": t.input, + desc := t.description + if t.name == entry && len(s.Cat.Collections) > 0 { + desc = "The documentation on this system: " + s.documented() + ". " + desc + } + // The collections' names, so that a model asks for one there is + // rather than one it guessed ("no such collection"); list_docs + // lists them itself, called without one. + if props, ok := t.input["properties"].(map[string]any); ok && len(names) > 0 && t.name != "list_docs" { + if c, ok := props["collection"].(map[string]any); ok { + c["enum"] = names + } + } + m := map[string]any{"name": t.name, "title": t.title, "description": desc, "inputSchema": t.input, "annotations": map[string]any{"readOnlyHint": true, "destructiveHint": false, "idempotentHint": true, "openWorldHint": false}} if t.output != nil && s.Structured { diff --git a/internal/server/server_test.go b/internal/server/server_test.go index f1ed26a..7217c06 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "regexp" + "slices" "strings" "testing" "time" @@ -764,3 +765,49 @@ func TestFixedTextIsStable(t *testing.T) { } } } + +// TestToolsNameTheCollections: the tool a question starts with says what +// the collections document, and the collection parameters list their +// names, for clients that do not pass the instructions to their model. +func TestToolsNameTheCollections(t *testing.T) { + s, _ := newServer(t, 16<<10, "app", "other") + s.Cat.Collection("app").Title = "The App Manual" + desc := func(s *Server, name string) (string, map[string]any) { + t.Helper() + for _, m := range s.toolList() { + if m["name"] == name { + props := m["inputSchema"].(map[string]any)["properties"].(map[string]any) + c, _ := props["collection"].(map[string]any) + return m["description"].(string), c + } + } + t.Fatalf("no tool %s", name) + return "", nil + } + d, c := desc(s, "find_sections") + if !strings.HasPrefix(d, "The documentation on this system: The App Manual; other. ") { + t.Errorf("find_sections: %q", d) + } + if !slices.Equal(c["enum"].([]string), []string{"app", "other"}) { + t.Errorf("find_sections' collection: %v", c) + } + if d, c := desc(s, "search"); strings.Contains(d, "The App Manual") || c["enum"] == nil { + t.Errorf("search: %q, %v: the list once, the names in each", d, c) + } + if _, c := desc(s, "list_docs"); c["enum"] != nil { + t.Errorf("list_docs' collection: %v: it lists the collections itself", c) + } + // Without find_sections, search says it. + s.Tools = []string{"search", "read_section"} + if d, _ := desc(s, "search"); !strings.HasPrefix(d, "The documentation on this system: ") { + t.Errorf("search without find_sections: %q", d) + } + // Bounded: many long titles end in "and N more". + s.Tools = nil + for _, k := range s.Cat.Collections { + k.Title = strings.Repeat(k.Name+" ", 80) + } + if d, _ := desc(s, "find_sections"); !strings.Contains(d, "; and 1 more. ") || len(d) > maxDocumented+300 { + t.Errorf("unbounded: %d B: %.120q", len(d), d) + } +}