Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(omp): stop recording xd:// and URI targets as files; take MCP server from results

Kyle Elliott08e76bac4f06
diff --git a/cli/beacon-hooks/cmd/omp_approval_test.go b/cli/beacon-hooks/cmd/omp_approval_test.go
index b6cb71fa..3fd1c40e 100644
--- a/cli/beacon-hooks/cmd/omp_approval_test.go
+++ b/cli/beacon-hooks/cmd/omp_approval_test.go
@@ -243,72 +243,84 @@ func TestOmpEmptyUserPythonProducesNothing(t *testing.T) {
}
// MCP attribution. Without it an MCP call lands in the log as a tool named
-// `mcp__github_create_issue` and nothing else, so the two questions actually asked about MCP
-// activity -- which server did this agent reach, and what did it call there -- have no field to
-// answer them.
-func TestOmpMCPToolIsAttributedToItsServer(t *testing.T) {
- logPath := ompTestLog(t)
-
- runHookWithInput(t, runOmpEvent, map[string]interface{}{
- "type": "tool_result", "toolName": "mcp__github_create_issue", "toolCallId": "call-1",
- "input": map[string]interface{}{"title": "bug"}, "sessionId": "sess-1",
- })
+// `mcp__beacon_managed_beacon_lookup` and nothing else, so the two questions actually asked about
+// MCP activity -- which server did this agent reach, and what did it call there -- have no field to
+// answer them. The server is the one the runtime names in the result's details: a split of the
+// minted name reads this one as server `beacon`, which is Beacon's local stdio server, not the
+// hosted `beacon-managed` one the call actually reached.
+func TestOmpMCPToolIsAttributedToTheServerTheRuntimeNames(t *testing.T) {
+ for _, isError := range []bool{false, true} {
+ logPath := ompTestLog(t)
+
+ runHookWithInput(t, runOmpEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "mcp__beacon_managed_beacon_lookup", "toolCallId": "call-1",
+ "input": map[string]interface{}{"kind": "harness"}, "sessionId": "sess-1", "isError": isError,
+ "details": map[string]interface{}{"serverName": "beacon-managed", "mcpToolName": "beacon_lookup"},
+ })
- event := ompEventWithAction(t, logPath, "mcp.tool_invoked")
- mcp := nested(t, event, "mcp")
- if mcp["server"] != "github" || mcp["tool"] != "create_issue" {
- t.Fatalf("mcp = %v, want the github server and its create_issue tool", mcp)
- }
- if meta := nested(t, event, "event"); meta["category"] != "mcp" {
- t.Fatalf("category = %v, want mcp", meta["category"])
+ action, category := "mcp.tool_invoked", "mcp"
+ if isError {
+ action, category = "tool.failed", "tool"
+ }
+ event := ompEventWithAction(t, logPath, action)
+ if mcp := nested(t, event, "mcp"); mcp["server"] != "beacon-managed" || mcp["tool"] != "beacon_lookup" {
+ t.Fatalf("isError=%v: mcp = %v, want the beacon-managed server and its beacon_lookup tool", isError, mcp)
+ }
+ if meta := nested(t, event, "event"); meta["category"] != category {
+ t.Fatalf("isError=%v: category = %v, want %s", isError, meta["category"], category)
+ }
}
}
-// Both spellings must resolve. `mcp__<server>__<tool>` is the widely used double-underscore form;
-// Oh My Pi mints `mcp__<server>_<tool>` with a single underscore. The single-underscore split
-// deliberately reproduces Oh My Pi's own parseMCPToolName, ambiguity included -- a server named
-// `my_server` reads as `my` in both, so Beacon's mcp.server always says what the runtime would say.
-func TestPiMCPServerToolReadsBothSpellings(t *testing.T) {
+func TestPiMCPServerToolReadsOnlyWhatIsStated(t *testing.T) {
+ runtime := map[string]interface{}{"serverName": "beacon-managed", "mcpToolName": "beacon_lookup"}
for _, tc := range []struct {
name string
+ call piToolCall
server, tool string
+ isMCP bool
}{
- {"mcp__github_create_issue", "github", "create_issue"},
- {"mcp__github__create_issue", "github", "create_issue"},
- {"mcp__puppeteer_screenshot", "puppeteer", "screenshot"},
- {"mcp__my_server_run", "my", "server_run"},
- // Not MCP names, and must not be forced into one.
- {"bash", "", ""},
- {"read", "", ""},
- {"my_custom_tool", "", ""},
- {"", "", ""},
- // Prefixed but with no tool half to speak of.
- {"mcp__github", "", ""},
- {"mcp__", "", ""},
+ {"runtime details", piToolCall{name: "mcp__beacon_managed_beacon_lookup", details: runtime}, "beacon-managed", "beacon_lookup", true},
+ {"double-underscore spelling", piToolCall{name: "mcp__github__create_issue"}, "github", "create_issue", true},
+ // Oh My Pi's minted spelling cannot be split back into its halves, so it names no server --
+ // but it is still MCP activity, which is what the `mcp__` namespace means to the runtime.
+ {"minted spelling alone", piToolCall{name: "mcp__beacon_managed_beacon_lookup"}, "", "", true},
+ {"minted spelling, simple server", piToolCall{name: "mcp__github_create_issue"}, "", "", true},
+ {"bare prefix", piToolCall{name: "mcp__"}, "", "", false},
+ {"bash", piToolCall{name: "bash"}, "", "", false},
+ {"custom tool", piToolCall{name: "my_custom_tool"}, "", "", false},
} {
t.Run(tc.name, func(t *testing.T) {
- server, tool := piMCPServerTool(tc.name)
- if server != tc.server || tool != tc.tool {
- t.Fatalf("piMCPServerTool(%q) = (%q, %q), want (%q, %q)",
- tc.name, server, tool, tc.server, tc.tool)
+ if server, tool := piMCPServerTool(tc.call); server != tc.server || tool != tc.tool {
+ t.Fatalf("piMCPServerTool = (%q, %q), want (%q, %q)", server, tool, tc.server, tc.tool)
+ }
+ if got := piIsMCPTool(tc.call); got != tc.isMCP {
+ t.Fatalf("piIsMCPTool = %v, want %v", got, tc.isMCP)
}
})
}
}
-// An approval for an MCP tool is attributed too. "Who approved a call to which server" is the
-// question an approval-abuse investigation asks, and it cannot be answered from a tool name alone.
-func TestOmpApprovalForAnMCPToolCarriesTheServer(t *testing.T) {
- logPath := ompTestLog(t)
-
- runHookWithInput(t, runOmpEvent, map[string]interface{}{
- "type": "tool_approval_resolved", "sessionId": "sess-1",
- "toolName": "mcp__github_create_issue", "toolCallId": "call-1", "approved": true,
- })
-
- event := ompEventWithAction(t, logPath, "approval.allowed")
- if mcp := nested(t, event, "mcp"); mcp["server"] != "github" || mcp["tool"] != "create_issue" {
- t.Fatalf("mcp = %v, want the github server and its create_issue tool", mcp)
+// The tool_call and the approval for an MCP call carry the minted name and nothing else. They must
+// not guess a server from it: a wrong mcp.server files the call under a server it never reached,
+// where an absent one leaves the call's result -- joined by gen_ai.tool.call.id -- to say.
+func TestOmpMCPNameAloneNamesNoServer(t *testing.T) {
+ for _, payload := range []map[string]interface{}{
+ {"type": "tool_call", "toolName": "mcp__beacon_managed_beacon_lookup", "toolCallId": "call-1",
+ "input": map[string]interface{}{"kind": "harness"}},
+ {"type": "tool_approval_resolved", "toolName": "mcp__beacon_managed_beacon_lookup", "toolCallId": "call-1",
+ "approved": true},
+ } {
+ events := ompRuntime.endpointEvents(payload, "sess-1")
+ if len(events) != 1 {
+ t.Fatalf("%s produced %d events, want 1", payload["type"], len(events))
+ }
+ if mcp, ok := events[0].fields["mcp"]; ok {
+ t.Fatalf("%s guessed an mcp block from the tool name: %v", payload["type"], mcp)
+ }
+ if tool, _ := events[0].fields["tool"].(map[string]interface{}); tool["name"] != "mcp__beacon_managed_beacon_lookup" {
+ t.Fatalf("%s tool = %v, want the tool name kept", payload["type"], tool)
+ }
}
}
diff --git a/cli/beacon-hooks/cmd/omp_device_test.go b/cli/beacon-hooks/cmd/omp_device_test.go
new file mode 100644
index 00000000..a85145fb
--- /dev/null
+++ b/cli/beacon-hooks/cmd/omp_device_test.go
@@ -0,0 +1,152 @@
+package cmd
+
+import (
+ "reflect"
+ "testing"
+)
+
+// ompDeviceCallPayloads is the four-event sequence Oh My Pi sends when the model calls an MCP tool
+// through its device transport, as captured from a live session: the write that carries the call,
+// the device's own tool_call and tool_result reported from inside the dispatch, and the write's
+// result. All four share one toolCallId.
+func ompDeviceCallPayloads() []map[string]interface{} {
+ common := func(payload map[string]interface{}) map[string]interface{} {
+ payload["sessionId"] = "sess-1"
+ payload["cwd"] = "/repo"
+ payload["toolCallId"] = "toolu_013mHwV28HzK9k41kDjbq2HB"
+ return payload
+ }
+ inner := map[string]interface{}{
+ "serverName": "beacon-managed", "mcpToolName": "beacon_lookup",
+ "provider": "native", "providerName": "OMP",
+ }
+ args := map[string]interface{}{"kind": "harness", "limit": float64(5)}
+ write := map[string]interface{}{
+ "path": "xd://mcp__beacon_managed_beacon_lookup", "content": `{"kind": "harness", "limit": 5}`,
+ }
+ return []map[string]interface{}{
+ common(map[string]interface{}{"type": "tool_call", "toolName": "write", "input": write}),
+ common(map[string]interface{}{"type": "tool_call", "toolName": "mcp__beacon_managed_beacon_lookup", "input": args}),
+ common(map[string]interface{}{
+ "type": "tool_result", "toolName": "mcp__beacon_managed_beacon_lookup", "input": args,
+ "isError": false, "details": inner,
+ }),
+ common(map[string]interface{}{
+ "type": "tool_result", "toolName": "write", "input": write, "isError": false,
+ "details": map[string]interface{}{"xdev": map[string]interface{}{
+ "tool": "mcp__beacon_managed_beacon_lookup", "mode": "execute", "tier": "write",
+ "args": args, "inner": inner,
+ }},
+ }),
+ }
+}
+
+// An MCP call made through a device is recorded the way every other runtime records an MCP call:
+// one tool.invoked and one mcp.tool_invoked, attributed to the server that served it -- not a
+// file.created for an `xd://` path, and not a second copy of the call under the name `write`.
+func TestOmpDeviceCallIsRecordedOnceAsTheDevice(t *testing.T) {
+ logPath := ompTestLog(t)
+ for _, payload := range ompDeviceCallPayloads() {
+ runHookWithInput(t, runOmpEvent, payload)
+ }
+
+ if got, want := ompEventActions(t, logPath), []string{"tool.invoked", "mcp.tool_invoked"}; !reflect.DeepEqual(got, want) {
+ t.Fatalf("actions = %v, want %v", got, want)
+ }
+ for _, event := range endpointEvents(t, logPath) {
+ if tool := nested(t, event, "tool"); tool["name"] != "mcp__beacon_managed_beacon_lookup" {
+ t.Fatalf("tool = %v, want the device that ran", tool)
+ }
+ if file, ok := event["file"]; ok {
+ t.Fatalf("a device call grew a file block: %v", file)
+ }
+ }
+ invoked := ompEventWithAction(t, logPath, "mcp.tool_invoked")
+ if mcp := nested(t, invoked, "mcp"); mcp["server"] != "beacon-managed" || mcp["tool"] != "beacon_lookup" {
+ t.Fatalf("mcp = %v, want the beacon-managed server and its beacon_lookup tool", mcp)
+ }
+}
+
+// Devices Oh My Pi handles in-process send no report of their own, so the write is the only record
+// of the call -- and it is still recorded as the device rather than as a file write.
+func TestOmpInProcessDeviceIsRecordedAsTheDevice(t *testing.T) {
+ logPath := ompTestLog(t)
+ write := map[string]interface{}{"path": "xd://report_issue", "content": `{"report": "grep: bad path list"}`}
+ runHookWithInput(t, runOmpEvent, map[string]interface{}{
+ "type": "tool_call", "toolName": "write", "toolCallId": "call-1", "sessionId": "sess-1", "input": write,
+ })
+ runHookWithInput(t, runOmpEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "write", "toolCallId": "call-1", "sessionId": "sess-1", "input": write,
+ "details": map[string]interface{}{"xdev": map[string]interface{}{
+ "tool": "report_issue", "mode": "execute", "args": map[string]interface{}{"report": "grep: bad path list"},
+ }},
+ })
+
+ if got, want := ompEventActions(t, logPath), []string{"tool.invoked", "tool.completed"}; !reflect.DeepEqual(got, want) {
+ t.Fatalf("actions = %v, want %v", got, want)
+ }
+ for _, event := range endpointEvents(t, logPath) {
+ if tool := nested(t, event, "tool"); tool["name"] != "report_issue" {
+ t.Fatalf("tool = %v, want report_issue", tool)
+ }
+ if file, ok := event["file"]; ok {
+ t.Fatalf("a device call grew a file block: %v", file)
+ }
+ }
+}
+
+// Oh My Pi's read and write tools also take URIs: web pages, the runtime's own resources, and a
+// device's documentation. None of those is a file, so none produces a file block or a file action.
+// The target stays on tool.path, so the row still says what was read.
+func TestOmpResourceTargetsAreNotFileActivity(t *testing.T) {
+ for _, tc := range []struct {
+ tool, target, content string
+ }{
+ // A URL whose path matches the secret-file pattern: as a file.read it would satisfy the first
+ // step of secret-read-then-egress.
+ {"read", "https://example.com/config/secrets", ""},
+ {"read", "artifact://13", ""},
+ {"read", "skill://self-verify-beacon-in-sandbox", ""},
+ {"read", "omp://mcp-config.md", ""},
+ {"read", "xd://mcp__beacon_managed_beacon_lookup", ""},
+ {"write", "proc://bg_3/kill", ""},
+ {"write", "local://notes.md", "draft"},
+ // A device write asking for help is a documentation lookup, not a call of the device.
+ {"write", "xd://lsp", "?"},
+ } {
+ t.Run(tc.tool+" "+tc.target, func(t *testing.T) {
+ args := map[string]interface{}{"path": tc.target, "content": tc.content}
+ for typ, action := range map[string]string{"tool_call": "tool.invoked", "tool_result": "tool.completed"} {
+ events := ompRuntime.endpointEvents(map[string]interface{}{
+ "type": typ, "toolName": tc.tool, "toolCallId": "call-1", "input": args,
+ }, "sess-1")
+ if len(events) != 1 {
+ t.Fatalf("%s produced %d events, want 1", typ, len(events))
+ }
+ if events[0].action != action {
+ t.Fatalf("%s action = %q, want %q", typ, events[0].action, action)
+ }
+ if file, ok := events[0].fields["file"]; ok {
+ t.Fatalf("%s grew a file block: %v", typ, file)
+ }
+ tool, _ := events[0].fields["tool"].(map[string]interface{})
+ if tool["name"] != tc.tool || tool["path"] != tc.target {
+ t.Fatalf("%s tool = %v, want %s on %s", typ, tool, tc.tool, tc.target)
+ }
+ }
+ })
+ }
+}
+
+// A `file://` URI is a filesystem path spelled as a URI, and is recorded as the path.
+func TestOmpFileURIIsRecordedAsItsPath(t *testing.T) {
+ events := ompRuntime.endpointEvents(map[string]interface{}{
+ "type": "tool_result", "toolName": "read", "input": map[string]interface{}{"path": "file:///repo/main.go"},
+ }, "sess-1")
+ if len(events) != 1 || events[0].action != "file.read" {
+ t.Fatalf("events = %+v, want one file.read", events)
+ }
+ if file, _ := events[0].fields["file"].(map[string]interface{}); file["path"] != "/repo/main.go" {
+ t.Fatalf("file = %v, want /repo/main.go", file)
+ }
+}
diff --git a/cli/beacon-hooks/cmd/pi_family.go b/cli/beacon-hooks/cmd/pi_family.go
index 7410449d..620e82d3 100644
--- a/cli/beacon-hooks/cmd/pi_family.go
+++ b/cli/beacon-hooks/cmd/pi_family.go
@@ -1,7 +1,10 @@
package cmd
import (
+ "encoding/json"
+ "net/url"
"path/filepath"
+ "regexp"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon-hooks/internal/diff"
@@ -120,8 +123,9 @@ func (f piFamily) endpointEvents(input map[string]interface{}, sessionID string)
// mapper's tool_before stage, and deliberately not as an approval -- a tool_call handler
// can block, but that is an extension deciding rather than an operator being asked. Oh My
// Pi's real approval decisions arrive as their own events and are mapped there.
- mergeMap(fields, f.toolFields(input, false))
- f.applyPythonMarker(fields, piToolName(input))
+ call := piToolCallOf(input)
+ mergeMap(fields, f.toolFields(call, input, false))
+ f.applyPythonMarker(fields, call.name)
applyToolCallID(fields, input)
return f.one("tool.invoked", "tool", "info", "tool invoked", fields)
@@ -204,11 +208,10 @@ func (f piFamily) endpointEvents(input map[string]interface{}, sessionID string)
// the tool.invoked that does carry the arguments, which is why it is promoted here as carefully as
// on the tool events themselves.
func (f piFamily) approvalEvents(input, fields map[string]interface{}, action, decision, messageSuffix string) []normalizedEvent {
- toolName := piToolName(input)
- if toolName != "" {
+ if piToolName(input) != "" {
// toolFields resolves the command, file and MCP blocks from the decided call's arguments
// when the extension attached them, and yields just the tool name when it did not.
- mergeMap(fields, f.toolFields(input, false))
+ mergeMap(fields, f.toolFields(piToolCallOf(input), input, false))
}
approval := map[string]interface{}{"required": true, "decision": decision}
@@ -288,15 +291,137 @@ func piToolInput(input map[string]interface{}) map[string]interface{} {
return map[string]interface{}{}
}
+// piToolCall is the tool call one Pi-family tool event describes: the tool that ran, the arguments
+// it ran with, and the details the runtime reported for it.
+//
+// It is usually just the payload's own toolName, input and details. The exception is a call routed
+// through Oh My Pi's tool-device transport, which reaches the tool by writing to an `xd://` URI;
+// see ompDeviceCall.
+type piToolCall struct {
+ name string
+ args map[string]interface{}
+ details map[string]interface{}
+}
+
+// piToolCallOf reads the tool call a tool_call, tool_result or approval payload describes.
+func piToolCallOf(input map[string]interface{}) piToolCall {
+ call := piToolCall{name: piToolName(input), args: piToolInput(input), details: firstMap(input, "details")}
+ if device, ok := ompDeviceCall(call); ok {
+ return device
+ }
+ return call
+}
+
+// ompDeviceScheme is the URI scheme through which Oh My Pi's read and write tools reach a tool
+// device: `read xd://<tool>` returns the tool's documentation, and `write xd://<tool>` with a JSON
+// payload calls it.
+const ompDeviceScheme = "xd://"
+
+// ompDeviceHelpContent matches a device write that asks for documentation rather than making a
+// call: an empty payload, `?`, or `help`. It mirrors HELP_CONTENT_RE in Oh My Pi's tools/xdev.ts,
+// which is how the runtime itself tells the two apart before anything has run.
+var ompDeviceHelpContent = regexp.MustCompile(`(?i)^\s*(\?|help)?\s*$`)
+
+// ompDeviceCall resolves a write to `xd://<tool>` into the call of <tool> it carries.
+//
+// Oh My Pi exposes MCP tools and its optional built-in tools as devices rather than as top-level
+// tools, so the model calls one by writing its arguments to the device's URI. Nothing is written
+// anywhere: the write tool is the transport, and the device is the tool that ran. Recording the
+// write as itself would put a file.created for `xd://mcp__…` in the log, and would name the call
+// `write` -- a different tool from the one every other runtime records when its agent calls the same
+// MCP server. So the call is recorded as the device: its name, the arguments it was given, and the
+// details it reported, which the runtime nests under `details.xdev`.
+//
+// The runtime also reports most device calls a second time from inside the dispatch, as the
+// device's own tool_call and tool_result under the same toolCallId. Both reports now describe the
+// same tool with the same call id, which is exactly what the endpoint writer's call-id dedupe treats
+// as one call -- so the call lands in the log once, as it would on any other runtime. Devices the
+// runtime handles in-process (report_issue, and its plan resolve/reject/propose devices) send no
+// second report, and are recorded from the write alone; nothing here needs to know which is which.
+//
+// A help request is a documentation lookup, the same as reading the device's URI, and is left as
+// the write it is.
+func ompDeviceCall(call piToolCall) (piToolCall, bool) {
+ if !strings.EqualFold(call.name, "write") {
+ return piToolCall{}, false
+ }
+ device, ok := strings.CutPrefix(getFirstStr(call.args, "path"), ompDeviceScheme)
+ if !ok || device == "" || strings.Contains(device, "/") {
+ return piToolCall{}, false
+ }
+ xdev := firstMap(call.details, "xdev")
+ if xdev != nil {
+ if getFirstStr(xdev, "mode") != "execute" {
+ return piToolCall{}, false
+ }
+ } else if ompDeviceHelpContent.MatchString(getFirstStr(call.args, "content")) {
+ return piToolCall{}, false
+ }
+
+ dispatched := piToolCall{name: device, args: firstMap(xdev, "args"), details: firstMap(xdev, "inner")}
+ if dispatched.args == nil {
+ // The tool_call and approval halves carry only the payload the model wrote. The result
+ // carries the runtime's validated arguments instead, but not when validation is what failed.
+ _ = json.Unmarshal([]byte(getFirstStr(call.args, "content")), &dispatched.args)
+ }
+ if dispatched.args == nil {
+ dispatched.args = map[string]interface{}{}
+ }
+ return dispatched, true
+}
+
+// piFilePath returns the filesystem path a read, edit or write target names, or "" when the target
+// is not a file.
+//
+// Oh My Pi's read and write tools take URIs as well as paths: `https://` fetches a web page, and its
+// internal schemes -- `artifact://`, `agent://`, `skill://`, `local://`, `proc://`, `xd://` and the
+// rest -- address runtime resources such as a spilled tool output, a subagent's report, a background
+// job, or a tool device. None of those is file activity, and recording one under file.path would put
+// a value that is not a filesystem path into the field every file rule, git helper and SIEM query
+// treats as one; the goose mapper refuses web URLs there for the same reason, and the collector
+// accepts only `file://` URIs. The runtime draws the same line: it reports a read's source as a
+// `path`, a `url` or an `internal` resource. A `file://` URI is a path spelled as a URI, and is
+// recorded as the path.
+func piFilePath(target string) string {
+ scheme, _, ok := strings.Cut(target, "://")
+ if !ok || !isURIScheme(scheme) {
+ return target
+ }
+ if !strings.EqualFold(scheme, "file") {
+ return ""
+ }
+ parsed, err := url.Parse(target)
+ if err != nil || (parsed.Host != "" && !strings.EqualFold(parsed.Host, "localhost")) {
+ return ""
+ }
+ return parsed.Path
+}
+
+// isURIScheme reports whether s is an RFC 3986 scheme. A single letter is not accepted, so a
+// Windows drive letter is never mistaken for one.
+func isURIScheme(s string) bool {
+ if len(s) < 2 {
+ return false
+ }
+ for i, r := range s {
+ switch {
+ case r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z':
+ case i > 0 && (r >= '0' && r <= '9' || r == '+' || r == '-' || r == '.'):
+ default:
+ return false
+ }
+ }
+ return true
+}
+
// toolFields builds the tool, command, and file blocks for one Pi-family tool event.
//
// The built-in tools have fixed, documented argument shapes -- bash takes `command`, and read,
// edit and write all take `path` -- so these are read by name rather than by guessing across
// spellings. A custom tool registered by another extension carries an arbitrary shape, and gets
// tool.name plus its raw arguments without a command or file block invented for it.
-func (f piFamily) toolFields(input map[string]interface{}, withResult bool) map[string]interface{} {
- name := piToolName(input)
- args := piToolInput(input)
+func (f piFamily) toolFields(call piToolCall, input map[string]interface{}, withResult bool) map[string]interface{} {
+ name, args := call.name, call.args
fields := map[string]interface{}{}
tool := map[string]interface{}{}
if name != "" {
@@ -326,21 +451,24 @@ func (f piFamily) toolFields(input map[string]interface{}, withResult bool) map[
fields["content"] = retainedContentFields(code)
}
case "read", "edit", "write":
- if path := getFirstStr(args, "path"); path != "" {
- tool["path"] = path
- file := map[string]interface{}{
- "path": path,
- "operation": piFileOperation(name),
+ // tool.path keeps the target as the tool was given it, URI or not, so the row still says
+ // what was read; only a filesystem target becomes a file block.
+ if target := getFirstStr(args, "path"); target != "" {
+ tool["path"] = target
+ if path := piFilePath(target); path != "" {
+ fields["file"] = map[string]interface{}{
+ "path": path,
+ "operation": piFileOperation(name),
+ "language": strings.TrimPrefix(filepath.Ext(path), "."),
+ }
}
- file["language"] = strings.TrimPrefix(filepath.Ext(path), ".")
- fields["file"] = file
}
}
if len(tool) > 0 {
fields["tool"] = tool
}
- f.applyMCPAttribution(fields, name)
+ f.applyMCPAttribution(fields, call)
if withResult {
if usage := piUsage(firstMap(input, "usage")); len(usage) > 0 {
fields["gen_ai"] = mergeNested(fields["gen_ai"], map[string]interface{}{"usage": usage})
@@ -361,13 +489,13 @@ func piFileOperation(name string) string {
}
}
-// applyMCPAttribution fills the `mcp` block when a tool name names an MCP-routed tool.
+// applyMCPAttribution fills the `mcp` block when the call is known to have reached an MCP server.
//
// Without it an MCP call lands in the log as a tool named `mcp__github_create_issue` and nothing
// else -- no server, no tool -- so the two questions actually asked about MCP activity ("which
// server did this agent reach, and what did it call there") have no field to answer them.
-func (f piFamily) applyMCPAttribution(fields map[string]interface{}, toolName string) {
- server, tool := piMCPServerTool(toolName)
+func (f piFamily) applyMCPAttribution(fields map[string]interface{}, call piToolCall) {
+ server, tool := piMCPServerTool(call)
if server == "" && tool == "" {
return
}
@@ -384,39 +512,48 @@ func (f piFamily) applyMCPAttribution(fields map[string]interface{}, toolName st
})
}
-// piMCPServerTool splits a Pi-family MCP tool name into its server and tool halves.
+// piMCPServerTool returns the MCP server and tool a Pi-family call reached, when that is known.
//
-// Two spellings reach here and they disagree about the separator. `mcp__<server>__<tool>` is the
-// widely used double-underscore form, and deriveMCPServerTool already reads it; Oh My Pi mints
-// `mcp__<server>_<tool>` with a single underscore (createMCPToolName in its mcp/tool-bridge.ts),
-// which that function returns nothing for because it needs three `__`-separated parts.
+// The runtime's own statement wins, as it does in the shared hook mapper and the collector: Oh My
+// Pi's MCP results carry `serverName` and `mcpToolName` in their details, on failures as well as
+// successes, and those are the server's configured name and the tool's own name exactly.
//
-// The double-underscore form is tried first because it is unambiguous. The single-underscore
-// fallback splits on the first underscore, which is exactly what Oh My Pi's own parseMCPToolName
-// does -- including its ambiguity, since a server named `my_server` yields `mcp__my_server_run` and
-// both parsers read that as server `my`. Reproducing the runtime's reading rather than inventing a
-// better one is deliberate: Beacon's `mcp.server` should say what the runtime itself would say, so
-// an operator comparing the two never finds them disagreeing.
-func piMCPServerTool(toolName string) (string, string) {
- if server, tool := deriveMCPServerTool(toolName); server != "" || tool != "" {
+// Without them only the reversible `mcp__<server>__<tool>` spelling is read. Oh My Pi's own names
+// are not reversible, so a tool_call or approval that carries nothing but one is given no server
+// rather than a guessed one. The runtime mints `mcp__<server>_<tool>` by lowercasing both halves,
+// turning every other character run into `_`, dropping a tool's redundant server prefix, and
+// hashing names past 64 characters -- so `beacon-managed`'s `beacon_lookup` becomes
+// `mcp__beacon_managed_beacon_lookup`, and no split of that string recovers the server. Splitting at
+// the first underscore reported it as server `beacon`, the name of Beacon's own local server. The
+// call's result, joined to it by gen_ai.tool.call.id, names the server.
+func piMCPServerTool(call piToolCall) (string, string) {
+ server := getFirstStr(call.details, "serverName")
+ tool := getFirstStr(call.details, "mcpToolName")
+ if server != "" && tool != "" {
return server, tool
}
- rest, ok := strings.CutPrefix(strings.TrimSpace(toolName), "mcp__")
- if !ok {
- return "", ""
- }
- server, tool, ok := strings.Cut(rest, "_")
- if !ok || server == "" || tool == "" {
- return "", ""
- }
- return server, tool
+ return deriveMCPServerTool(call.name)
+}
+
+// piIsMCPTool reports whether a call is MCP activity, whether or not its server is known.
+//
+// `mcp__` is the namespace Oh My Pi reserves for MCP tools, and the test its own isMCPToolName
+// applies, so a call carrying the prefix is MCP activity even where only its result can say which
+// server it reached.
+func piIsMCPTool(call piToolCall) bool {
+ if server, tool := piMCPServerTool(call); server != "" || tool != "" {
+ return true
+ }
+ rest, ok := strings.CutPrefix(strings.TrimSpace(call.name), "mcp__")
+ return ok && rest != ""
}
// toolResultEvents maps a completed tool call onto its outcome event.
func (f piFamily) toolResultEvents(input map[string]interface{}, fields map[string]interface{}) []normalizedEvent {
- mergeMap(fields, f.toolFields(input, true))
+ call := piToolCallOf(input)
+ mergeMap(fields, f.toolFields(call, input, true))
applyToolCallID(fields, input)
- name := piToolName(input)
+ name := call.name
f.applyPythonMarker(fields, name)
// Both of these read Prime Agent's `ipython` result and are no-ops for every other tool, so Pi
@@ -431,15 +568,15 @@ func (f piFamily) toolResultEvents(input map[string]interface{}, fields map[stri
return append(f.one("tool.failed", "tool", "high", "tool failed", fields), kernelWrites...)
}
- if diff := piEditDiff(input); diff != "" {
+ if diff := piEditDiff(call.details); diff != "" {
fields["content"] = retainedContentFields(diff)
}
- action, category := piToolAction(name)
+ action, category := piToolAction(call)
// A file action with no file is not a file action. The read tool accepts a path that failed to
- // resolve, and a custom tool can share a built-in's name, so reporting file.read with no file
- // field would produce a row every file-scoped query matches and none can explain -- the same
- // guard clineToolAfterEvents applies for the same reason.
+ // resolve and a target that is not a file at all, and a custom tool can share a built-in's name,
+ // so reporting file.read with no file field would produce a row every file-scoped query matches
+ // and none can explain -- the same guard clineToolAfterEvents applies for the same reason.
if strings.HasPrefix(action, "file.") {
if _, ok := fields["file"]; !ok {
action, category = "tool.completed", "tool"
@@ -613,17 +750,13 @@ func (f piFamily) pythonDiffEvents(toolName string, input, fields map[string]int
// EditToolDetails carries both a display-oriented `diff` and a standard unified `patch`. The patch
// is preferred because it is the machine-readable one; the diff is a fallback for a details object
// that carried only the display form.
-func piEditDiff(input map[string]interface{}) string {
- details := firstMap(input, "details")
- if details == nil {
- return ""
- }
+func piEditDiff(details map[string]interface{}) string {
return getFirstStr(details, "patch", "diff")
}
-// piToolAction maps a Pi-family tool name onto the endpoint action its completion represents.
-func piToolAction(name string) (string, string) {
- switch strings.ToLower(name) {
+// piToolAction maps a Pi-family tool call onto the endpoint action its completion represents.
+func piToolAction(call piToolCall) (string, string) {
+ switch strings.ToLower(call.name) {
case "bash", "ipython":
return "command.executed", "command"
case "read":
@@ -637,7 +770,7 @@ func piToolAction(name string) (string, string) {
// and mcp.tool_invoked is the action every other Beacon capture path already uses for it --
// so an MCP call through Oh My Pi joins the same rows a detection reads for Cline, Cursor
// and Claude Code rather than hiding under tool.completed.
- if server, tool := piMCPServerTool(name); server != "" || tool != "" {
+ if piIsMCPTool(call) {
return "mcp.tool_invoked", "mcp"
}
// grep, glob, and any tool another extension registered. These are real tool activity with
diff --git a/docs/runtimes/oh-my-pi.mdx b/docs/runtimes/oh-my-pi.mdx
index b3cfb631..307f6029 100644
--- a/docs/runtimes/oh-my-pi.mdx
+++ b/docs/runtimes/oh-my-pi.mdx
@@ -103,13 +103,21 @@ Unlike Pi, a project-level install needs no trust prompt: Oh My Pi loads `.omp`
| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed`, joined by `gen_ai.tool.call.id` |
| **Approval decisions** | **Supported.** `approval.requested`, `approval.allowed`, and `approval.denied` from real operator prompts, carrying the command or file being decided on, the approval mode the session was running under, and the tool call id of the execution they decided. This is the capability Oh My Pi has that upstream Pi does not |
| Commands | Supported. `command.executed` for the agent's `bash` tool, for commands you run with the `!` prefix, and for code you run with the `$` Python prefix — the last two marked as operator-initiated |
-| File activity | Supported. `file.read`, `file.created`, and `file.modified`, with the unified patch on an edit |
-| MCP activity | Supported. `mcp.tool_invoked` with the server and tool resolved from Oh My Pi's `mcp__<server>_<tool>` naming |
+| File activity | Supported. `file.read`, `file.created`, and `file.modified`, with the unified patch on an edit. Only filesystem targets count: see [tool devices and URIs](#tool-devices-and-uris) |
+| MCP activity | Supported. `tool.invoked` then `mcp.tool_invoked`, whether the model called the tool directly or through its `xd://` device. `mcp.server` and `mcp.tool` are the server's configured name and the tool's own name, read from the result Oh My Pi reports |
| Agent reasoning | Supported. `agent.reasoning` from an assistant message's thinking parts, in the OTel GenAI reasoning-part shape |
| Token usage and cost | Supported. `token.usage` normalized into `gen_ai.usage`, including cache and reasoning tokens and runtime-reported cost |
| Local JSONL and dashboard | Supported |
| MDM deployment | Supported for the endpoint agent. The extension installs separately in the logged-in user's context |
+### Tool devices and URIs
+
+Oh My Pi's `read` and `write` tools take URIs as well as paths. `https://` fetches a web page, and the runtime's own schemes (`artifact://`, `agent://`, `skill://`, `local://`, `proc://`, `omp://`, `xd://`, and others) address its resources: a spilled tool output, a subagent's report, a skill, a background job, its own docs, a tool device. None of these is file activity. Beacon records them as `tool.invoked` and `tool.completed` with the URI in `tool.path` and no `file` block, the same way every other runtime records a web fetch or a resource read. A `file://` URI is recorded as the path it names.
+
+Writing JSON to `xd://<tool>` is how the model calls a tool that Oh My Pi exposes as a device. That includes every MCP tool. Beacon records the device as the tool that ran, under the device's name, so an MCP call through a device produces the same `tool.invoked` and `mcp.tool_invoked` pair as one called directly. Oh My Pi reports most device calls twice: once as the `write`, and once from inside the dispatch as the device's own call, under the same tool call id. Beacon keeps one of them. Reading `xd://<tool>`, or writing `?` to it, fetches the device's documentation and is recorded as the `read` or `write` it is.
+
+An MCP call's server is known only once it has run. Oh My Pi names its MCP tools `mcp__<server>_<tool>`. It lowercases both halves, turns other characters into `_`, and shortens long names, so the server cannot be recovered from the name: `beacon-managed`'s `beacon_lookup` becomes `mcp__beacon_managed_beacon_lookup`. The result carries the real names. The `tool.invoked` before the call, and any approval for it, record the tool name without an `mcp` block. Their `gen_ai.tool.call.id` joins them to the attributed result.
+
### Approval telemetry
Beacon never synthesizes an approval from a tool call. A `tool_call` handler that blocks is an extension deciding, not an operator being asked, and recording that as an approval would be indistinguishable from an answer a human gave — which is why [Pi](/runtimes/pi) and [Cline](/runtimes/cline) carry no approval telemetry at all.