ArvinCharl on X: the MCP router's tools fill the context. An agent that
doesn't search its MCP tools itself (all but Claude Code, Claude
Desktop, Codex and Pi) sends every tool's whole schema on every
request. Given more than 10 router tools, such an agent now lists two in
their place: find_tools (matches by name and description, the first 5
with their inputSchema, 15 more by name) and call_tool (runs one by
<server>__<tool>, its bare name, or arguments sent as a string; an
unknown name is told the close ones). The instructions still name every
server and its tools, and a tool called by its own name still runs. The
request log names the tool call_tool ran. The address for any other app
lists every tool, since which app connects isn't known.
Library → MCP gains a "Tools on demand" toggle (settings
routerAllTools, kept by KeepOwn and the settings API); turned off,
every agent gets every tool whole as before.
Run on mote (after the rebase onto 083821dc9: gateway vet, -run
'Hub|MCP|Settings|Search' and the four GUI files again, ok, 70 of 70):
- gofmt -l: empty. go vet, GOOS=linux go vet -tags nogui, GOOS=windows
go vet of gateway, settings, settingsapi, gui, library: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/settings
./internal/settingsapi ./internal/gui ./internal/library: ok;
./internal/gateway -run 'Hub|MCP|Settings': ok.
- GUI (Chromium + WebKit, every language): library-mcp-router-tools,
library-mcp-router-note, library-mcp-hub, i18n-keys: 70 of 70.
Broken by hand: hubOnDemand forced false turns TestHubMCPToolsOnDemand
red.
Not tried: a real OpenCode or Gemini CLI session against the router;
the full gateway package and full GUI suite.
79 lines
2.8 KiB
Go
79 lines
2.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// The name the Library gives this computer's MCP router (packinggoodsllc_07668 on Discord) is saved
|
|
// to this computer's settings and comes back in the page's view, with
|
|
// this computer's name for the field's placeholder; a save from the
|
|
// Settings page, which doesn't send it, leaves it as it is.
|
|
func TestHubNoteSaved(t *testing.T) {
|
|
sandboxHome(t)
|
|
h := Handler(nil, nil)
|
|
post := func(path, body string) *httptest.ResponseRecorder {
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
return rec
|
|
}
|
|
rec := post("/api/library/servers/hub-note", `{"note":" Los Angeles "}`)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body)
|
|
}
|
|
var v struct{ HubNote, HubName string }
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v.HubNote != "Los Angeles" || settings.Load().RouterNote != "Los Angeles" {
|
|
t.Fatalf("view %+v, saved %q", v, settings.Load().RouterNote)
|
|
}
|
|
if rec := post("/api/settings", `{"theme":"dark","lang":"en"}`); rec.Code != http.StatusOK {
|
|
t.Fatalf("settings: %d %s", rec.Code, rec.Body)
|
|
}
|
|
if got := settings.Load().RouterNote; got != "Los Angeles" {
|
|
t.Fatalf("the Settings page's save left %q", got)
|
|
}
|
|
if rec := post("/api/library/servers/hub-note", `{"note":""}`); rec.Code != http.StatusOK || settings.Load().RouterNote != "" {
|
|
t.Fatalf("cleared: %d %q", rec.Code, settings.Load().RouterNote)
|
|
}
|
|
}
|
|
|
|
// The router's switch for giving every agent its tools whole, not on
|
|
// demand (ArvinCharl on X), is this computer's setting, comes back in the
|
|
// page's view, and a save from the Settings page leaves it as it is.
|
|
func TestHubAllToolsSaved(t *testing.T) {
|
|
sandboxHome(t)
|
|
h := Handler(nil, nil)
|
|
post := func(path, body string) *httptest.ResponseRecorder {
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
return rec
|
|
}
|
|
rec := post("/api/library/servers/hub-tools", `{"on":true}`)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body)
|
|
}
|
|
var v struct{ HubAllTools bool }
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !v.HubAllTools || !settings.Load().RouterAllTools {
|
|
t.Fatalf("view %+v, saved %v", v, settings.Load().RouterAllTools)
|
|
}
|
|
if rec := post("/api/settings", `{"theme":"dark","lang":"en"}`); rec.Code != http.StatusOK {
|
|
t.Fatalf("settings: %d %s", rec.Code, rec.Body)
|
|
}
|
|
if !settings.Load().RouterAllTools {
|
|
t.Fatal("the Settings page's save turned it off")
|
|
}
|
|
if rec := post("/api/library/servers/hub-tools", `{"on":false}`); rec.Code != http.StatusOK || settings.Load().RouterAllTools {
|
|
t.Fatalf("off: %d %v", rec.Code, settings.Load().RouterAllTools)
|
|
}
|
|
}
|