Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-admin-mcp-settings-read-whole-section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Admin MCP: `settings_read` returns a Settings section whole. It went through the list tools' row cap, which keeps the first 20 entries of a list by default, although `settings_read` has no `limit` argument to raise it. On a hive with more than 20 agents the governor settings came back with 20 agents (`agents_truncated: true`), and a section that is itself a list, such as `backends`, was cut to 20 entries, with no way to read the rest. A section is now bounded only by the 256 KiB text cap. The list tools (`agents_list`, `runs_list` and the others) keep their cap.
4 changes: 4 additions & 0 deletions src/cmd/hive-admin-mcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (p readProvider) Read(ctx context.Context, tool string, args map[string]any
if err != nil {
return nil, err
}
if tool == adminmcp.ToolSettingsRead {
// A Settings view is not a list to page; see the dashboard provider.
return data, nil
}
if tool == adminmcp.ToolIssuesByBand || tool == adminmcp.ToolPrsByBand {
return adminmcp.BandReadResult(tool, data, args)
}
Expand Down
79 changes: 79 additions & 0 deletions src/cmd/hive-admin-mcp/settings_read_cap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/hivecommons/hive/pkg/adminmcp"
)

// settings_read went through the list tools' row cap (20 by default) although
// it has no limit argument, so the governor settings of a hive with 30 agents
// came back with 20 and no way to read the rest.
func TestStdioSettingsReadReturnsTheWholeSection(t *testing.T) {
agents := make([]any, 30)
for i := range agents {
agents[i] = map[string]any{"name": fmt.Sprintf("agent-%02d", i), "cadence": "15m"}
}
backends := make([]any, 25)
for i := range backends {
backends[i] = map[string]any{"name": fmt.Sprintf("backend-%02d", i)}
}
mux := http.NewServeMux()
mux.HandleFunc("GET /api/config/governor", func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]any{"agents": agents, "cadenceScope": "global"})
})
mux.HandleFunc("GET /api/config/backends", func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(backends)
})
server := httptest.NewServer(mux)
defer server.Close()
r := &roster{hives: []hiveConfig{{Name: "active", Address: server.URL, Token: "token"}}, active: 0, timeout: time.Second}
p := readProvider{roster: r}

data, err := p.Read(context.Background(), adminmcp.ToolSettingsRead, map[string]any{})
if err != nil {
t.Fatal(err)
}
governor, _ := data.(map[string]any)
if kept, _ := governor["agents"].([]any); len(kept) != 30 {
t.Fatalf("governor settings list %d of 30 agents", len(kept))
}
if _, cut := governor["_admin_mcp"]; cut {
t.Fatalf("governor settings are marked truncated: %v", governor["_admin_mcp"])
}

data, err = p.Read(context.Background(), adminmcp.ToolSettingsRead, map[string]any{"section": "backends"})
if err != nil {
t.Fatal(err)
}
if list, _ := data.([]any); len(list) != 25 {
t.Fatalf("backends section = %T with %d entries, want the list of 25", data, len(list))
}
}

// The list tools keep their cap.
func TestStdioListToolsStillCapRows(t *testing.T) {
agents := make([]any, 30)
for i := range agents {
agents[i] = map[string]any{"name": fmt.Sprintf("agent-%02d", i)}
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(agents)
}))
defer server.Close()
r := &roster{hives: []hiveConfig{{Name: "active", Address: server.URL, Token: "token"}}, active: 0, timeout: time.Second}
data, err := (readProvider{roster: r}).Read(context.Background(), adminmcp.ToolAgentsList, map[string]any{})
if err != nil {
t.Fatal(err)
}
capped, _ := data.(map[string]any)
if items, _ := capped["items"].([]any); len(items) != adminmcp.DefaultResultLimit || capped["truncated"] != true {
t.Fatalf("agents_list = %v", capped)
}
}
4 changes: 3 additions & 1 deletion src/docs/admin-mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ section name, never a path. Each section is the endpoint that Settings tab
reads, so the answer matches the page for the same caller: most sections need a
verified owner, as the tabs do. Secret values are never returned. Settings name
the environment variable, file or header that supplies a secret, and the answer
is scrubbed like every other read.
is scrubbed like every other read. `settings_read` takes no `limit`: a section
is returned whole, however many agents or entries it lists, bounded only by the
256 KiB text cap.

- Global settings: `governor` (the default: modes, thresholds, labels, repos,
budget, notifications, health, sensing, logging, security, features, hub,
Expand Down
6 changes: 5 additions & 1 deletion src/pkg/dashboard/admin_mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func (p dashboardAdminMCPProvider) Read(_ context.Context, tool string, args map
if err != nil {
return nil, err
}
return adminmcp.CapResult(data, adminmcp.LimitFromArgs(args)), nil
// A Settings view is not a list to page: settings_read has no limit
// argument, so the row cap would cut a hive's 21st agent out of its
// governor settings with no way to ask for it. The text cap still
// bounds the answer.
return data, nil
}
path, ok := adminMCPReadPath(tool, args)
if !ok {
Expand Down
53 changes: 53 additions & 0 deletions src/pkg/dashboard/admin_mcp_settings_cap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dashboard

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/hivecommons/hive/pkg/adminmcp"
)

// settings_read went through the list tools' row cap (20 by default) although
// it has no limit argument, so the governor settings of a hive with 30 agents
// came back with 20 and no way to read the rest.
func TestDashboardAdminMCPSettingsReadReturnsTheWholeSection(t *testing.T) {
agents := make([]any, 30)
for i := range agents {
agents[i] = map[string]any{"name": fmt.Sprintf("agent-%02d", i), "cadence": "15m"}
}
backends := make([]any, 25)
for i := range backends {
backends[i] = map[string]any{"name": fmt.Sprintf("backend-%02d", i)}
}
s := &Server{mux: http.NewServeMux()}
s.mux.HandleFunc("GET /api/config/governor", func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]any{"agents": agents, "cadenceScope": "global"})
})
s.mux.HandleFunc("GET /api/config/backends", func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(backends)
})
p := dashboardAdminMCPProvider{server: s, role: "owner", ownerVerified: true}

data, err := p.Read(context.Background(), adminmcp.ToolSettingsRead, map[string]any{})
if err != nil {
t.Fatal(err)
}
governor, _ := data.(map[string]any)
if kept, _ := governor["agents"].([]any); len(kept) != 30 {
t.Fatalf("governor settings list %d of 30 agents", len(kept))
}
if _, cut := governor["_admin_mcp"]; cut {
t.Fatalf("governor settings are marked truncated: %v", governor["_admin_mcp"])
}

data, err = p.Read(context.Background(), adminmcp.ToolSettingsRead, map[string]any{"section": "backends"})
if err != nil {
t.Fatal(err)
}
if list, _ := data.([]any); len(list) != 25 {
t.Fatalf("backends section = %T with %d entries, want the list of 25", data, len(list))
}
}
Loading