ferock (Discord) asked to see calls to magpie's MCP tools, such as magpie-image's generate_image, generate_video and generation_result, in Routing > Requests. Each tools/call to magpie's own MCP servers (image, vision, web search, tools and the Library hub) is now a row of the request log. The row has Source and Kind "mcp", the tool as its model, the server as its host, how long the call took, and its error if it failed. The provider and model it shows are those of the model requests the call made, collected through the request's context in appendUsage. generation_result names the model of the job it answers. The stdio Magpie Image server reports each call it answered to the gateway as "magpie/toolCalled". That report carries the tool, ms, model and error, never the prompt. The arguments are never stored at all, so there is nothing to mask. The rows go down the probe lane: they are listed, but no total, host list, budget or key limit counts them. The model requests a call made are rows of their own. In the GUI the row reuses the Requests list. It gets a muted "MCP" badge with a tooltip, the server beside the provider, and a Succeeded/Failed status. The Purpose filter gains "MCP tool" in every language. There is no new page, no <select> and no left border. The core scripts went over their budget with the new purpose. genpurposes now writes purposes.js as compact JSON, which makes the core 448 bytes smaller than main in all, and coreScriptBudget is lowered to the new total, 1,538,975. No room is added. Run on mote, at the rebased head: - gofmt -l: clean. go vet -tags nogui ./... with GOOS darwin, linux and windows: ok. - go test -tags nogui -timeout 45m: ./internal/usage, ./internal/imagemcp, ./internal/usageapi and ./internal/gui ok. internal/budget has no test files. ./internal/gateway (805s): every test ok except five Antigravity and Codex/Grok tests. They fail the same on a clean origin/main3bebc3839and are filed as #4362. - GUI, the usage-ledger*, routing-request*, purpose*, i18n* and gui-zh/ja/de files (25). On mote, Chromium: 32 of 32 ok; WebKit could not launch (10 other sessions' suites on mote). On Linux (wsl-run), both engines: 335 of 355 ok. The 20 reds are routing-request-model, usage-ledger, -ttft, -chart and -open-settled, which fail the same at the parent1534474c8(#4120). usage-ledger-mcp, purpose-filter and i18n-keys are ok in both. The whole GUI suite runs after the push, and each red it finds gets an issue. - At the pushed head, rebased on0804f2d97: ./internal/gui (the budget and purpose asset tests among them), ./internal/usage, ./internal/imagemcp and ./internal/usageapi ok, and ./internal/gateway -run "MCP|Purpose|Probe" ok. - usage-ledger-mcp.test.cjs covers 5 languages, widths 1180 and 420, light and dark, with no sideways scroll. Broken by hand. Each break went red: - sawHost's MCP skip removed: TestMCPCallRowsListedNotCounted (the hosts list had magpie-image). - Row/Record.IsProbe's MCP case removed: the same test (3 calls counted), and TestMCPCallCountsInNoKeyLimit (Calls: 1). - The callMCPTool hook removed: TestMCPToolCallIsARequestRow and its siblings (no rows). - The appendUsage hook removed: the row had no provider or model. - imagemcp's report removed: TestToolCallsAreReported. - The gateway's magpie/toolCalled case removed: TestMCPCalledFromStdioIsARow. budget's in-memory counts() now skips these rows too. Breaking only that stays green, because budget.Of reads the file through usage.Visit, which already skips probes, and limits count tokens and cost. Not tried: - no real agent calling a real vendor's drawing; - no test run on Windows or Linux; - the page not checked in the real app or in WebKitGTK. A generate call that answers while its drawing still runs has no model on its row. The generation_result row that follows names it.
70 lines
3.3 KiB
Go
70 lines
3.3 KiB
Go
package usage
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// ferock on Discord: an agent's call to a tool of magpie's MCP servers
|
|
// (generate_image) is a row of the request log of its own, apart from
|
|
// the model requests, picked by the MCP tool purpose, naming the tool,
|
|
// its server, the provider and model it used, how long it took and how it
|
|
// ended, and counted in nothing: its image request is the call that is.
|
|
func TestMCPCallRowsListedNotCounted(t *testing.T) {
|
|
reportedHome(t)
|
|
spy := &ledgerSpy{}
|
|
t.Cleanup(Observe(spy))
|
|
now := time.Now().Add(-time.Hour)
|
|
Append(Record{Time: now, Agent: "claude", Provider: "openai", Host: "api.openai.com", Model: "gpt-image-2", Requested: "gpt-image-2", Operation: "generate_content", Endpoint: "/v1/images/generations", Status: 200, Millis: 9000})
|
|
Append(Record{Time: now.Add(time.Second), Agent: "claude", Operation: "execute_tool", Provider: "openai", Model: "gpt-image-2", Requested: "generate_image",
|
|
Host: "magpie-image", Millis: 9100, Endpoint: "/mcp/magpie/image", Kind: KindMCP, Source: SourceMCP})
|
|
Append(Record{Time: now.Add(2 * time.Second), Agent: "claude", Operation: "execute_tool", Requested: "github__create_issue",
|
|
Host: "github", Millis: 40, Error: "it didn't answer", Endpoint: "/mcp/magpie/hub/claude", Kind: KindMCP, Source: SourceMCP})
|
|
|
|
page := QueryPage(All, Filter{}, 0, 50)
|
|
if page.Total != 3 || len(page.Rows) != 3 {
|
|
t.Fatalf("total %d, %d rows: %+v", page.Total, len(page.Rows), page.Rows)
|
|
}
|
|
hub, image := page.Rows[0], page.Rows[1] // newest first
|
|
if hub.Source != SourceMCP || !hub.IsProbe() || hub.Requested != "github__create_issue" || hub.Host != "github" || !hub.Failed() || hub.Provider != "" {
|
|
t.Fatalf("hub row %+v", hub)
|
|
}
|
|
if image.Source != SourceMCP || image.Requested != "generate_image" || image.Provider != "openai" || image.Model != "gpt-image-2" ||
|
|
image.Host != "magpie-image" || image.Millis != 9100 || image.Failed() || image.Endpoint != "/mcp/magpie/image" {
|
|
t.Fatalf("image row %+v", image)
|
|
}
|
|
if page.Sum.Calls != 1 || page.Sum.Errors != 0 || page.Through.Calls != 1 {
|
|
t.Fatalf("sum %+v through %+v", page.Sum, page.Through)
|
|
}
|
|
if !slices.Contains(page.Purposes, "kind:mcp") || PurposeOf(KindMCP) != "kind:mcp" || PurposeKinds()[KindMCP].Name != "MCP tool" {
|
|
t.Fatalf("purposes %v", page.Purposes)
|
|
}
|
|
for dim, shares := range page.By {
|
|
for _, s := range shares {
|
|
if s.ID == "generate_image" || s.ID == "github__create_issue" || (dim == "provider" && s.Calls != 1) {
|
|
t.Fatalf("%s counts a tool call: %+v", dim, shares)
|
|
}
|
|
}
|
|
}
|
|
if s := Summarize(All); s.Calls != 1 || s.Errors != 0 {
|
|
t.Fatalf("summary %+v", s.Totals)
|
|
}
|
|
if rs := Load(time.Time{}); len(rs) != 1 {
|
|
t.Fatalf("Load %+v", rs)
|
|
}
|
|
if len(spy.rows) != 1 || spy.rows[0].IsProbe() {
|
|
t.Fatalf("observer saw %+v", spy.rows)
|
|
}
|
|
// the purpose picks the tool calls alone, and counts nothing still
|
|
p := QueryPage(All, Filter{Purpose: "kind:mcp"}, 0, 50)
|
|
if p.Total != 2 || p.Sum.Calls != 0 || p.Rows[0].Source != SourceMCP || p.Rows[1].Source != SourceMCP {
|
|
t.Fatalf("purpose filter: total %d sum %+v rows %+v", p.Total, p.Sum, p.Rows)
|
|
}
|
|
// a tool call's server is no provider's host: a probe on the host is
|
|
// not listed under the provider the tool used
|
|
if hosts := readLogSnapshot().hosts; hosts["magpie-image"] != "" || hosts["github"] != "" {
|
|
t.Fatalf("hosts %v", hosts)
|
|
}
|
|
}
|