The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
extend mcp schema
Justin D'Souzad6822b163273
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.goindex 8bcccd2f..8f808288 100644--- a/cli/beacon-hooks/cmd/endpoint_events.go+++ b/cli/beacon-hooks/cmd/endpoint_events.go@@ -8,6 +8,7 @@ import ("os""os/exec""path/filepath"+ "strconv""strings""time"@@ -147,6 +148,10 @@ func sessionFields(sessionID string, input map[string]interface{}) map[string]in}func toolFields(toolName string, toolInput map[string]interface{}) map[string]interface{} {+ return toolFieldsWithResponse(toolName, toolInput, nil)+}++func toolFieldsWithResponse(toolName string, toolInput, toolResponse map[string]interface{}) map[string]interface{} {fields := map[string]interface{}{}if toolName != "" {fields["tool"] = map[string]interface{}{"name": toolName}@@ -163,15 +168,167 @@ func toolFields(toolName string, toolInput map[string]interface{}) map[string]in}fields["tool"] = mergeNested(fields["tool"], map[string]interface{}{"path": path})}- if server := firstToolString(toolInput, "server", "server_name", "mcp_server"); server != "" || strings.Contains(strings.ToLower(toolName), "mcp") {- fields["mcp"] = map[string]interface{}{- "server": server,- "tool": firstToolString(toolInput, "tool", "tool_name", "name"),+ if mcp := mcpToolFields(toolName, toolInput, toolResponse); len(mcp) > 0 {+ fields["mcp"] = mcp+ tool := firstNestedString(mcp, "tool")+ fields["gen_ai"] = genAIToolFields(tool, toolInput, toolResponse)+ for key, value := range mcpStandardFields(toolInput, toolResponse) {+ fields[key] = value}}return fields}+func mcpToolFields(toolName string, toolInput, toolResponse map[string]interface{}) map[string]interface{} {+ server := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "server", "server_name", "mcp_server", "mcp_server_name", "mcp.server", "mcp.server.name")+ tool := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "tool", "tool_name", "function_name", "mcp_tool", "mcp_tool_name", "mcp.tool", "mcp.tool.name", "gen_ai.tool.name")+ genericToolName := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "name")+ method := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "mcp.method.name", "mcp_method_name", "mcp_method", "method_name", "method")+ protocol := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "mcp.protocol.version", "mcp_protocol_version", "protocol_version")+ resource := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "mcp.resource.uri", "mcp_resource_uri", "resource_uri", "uri")+ session := firstToolStringAcross([]map[string]interface{}{toolInput, toolResponse}, "mcp.session.id", "mcp_session_id")++ if derivedServer, derivedTool := deriveMCPServerTool(toolName); derivedServer != "" || derivedTool != "" {+ if server == "" {+ server = derivedServer+ }+ if tool == "" {+ tool = derivedTool+ }+ }++ isMCP := server != "" || tool != "" || method != "" || protocol != "" || resource != "" || session != "" || strings.Contains(strings.ToLower(toolName), "mcp")+ if !isMCP {+ return nil+ }+ if tool == "" {+ tool = genericToolName+ }+ if method == "" {+ method = "tools/call"+ }+ out := map[string]interface{}{"server": server, "tool": tool}+ if method != "" {+ out["method"] = map[string]interface{}{"name": method}+ }+ if protocol != "" {+ out["protocol"] = map[string]interface{}{"version": protocol}+ }+ if resource != "" {+ out["resource"] = map[string]interface{}{"uri": resource}+ }+ if session != "" {+ out["session"] = map[string]interface{}{"id": session}+ }+ return out+}++func deriveMCPServerTool(toolName string) (string, string) {+ trimmed := strings.TrimSpace(toolName)+ lower := strings.ToLower(trimmed)+ if strings.HasPrefix(lower, "mcp:") {+ return "", strings.TrimSpace(trimmed[len("MCP:"):])+ }+ if strings.HasPrefix(lower, "mcp__") {+ parts := strings.Split(trimmed, "__")+ if len(parts) >= 3 {+ return parts[1], strings.Join(parts[2:], "__")+ }+ }+ return "", ""+}++func genAIToolFields(tool string, toolInput, toolResponse map[string]interface{}) map[string]interface{} {+ genAI := map[string]interface{}{+ "operation": map[string]interface{}{"name": "execute_tool"},+ }+ toolInfo := map[string]interface{}{}+ if tool != "" {+ toolInfo["name"] = tool+ }+ call := map[string]interface{}{}+ if len(toolInput) > 0 {+ call["arguments"] = toolInput+ }+ if len(toolResponse) > 0 {+ call["result"] = toolResponse+ }+ if len(call) > 0 {+ toolInfo["call"] = call+ }+ if len(toolInfo) > 0 {+ genAI["tool"] = toolInfo+ }+ return genAI+}++func mcpStandardFields(toolInput, toolResponse map[string]interface{}) map[string]interface{} {+ fields := map[string]interface{}{}+ maps := []map[string]interface{}{toolInput, toolResponse}+ if errorType := mcpErrorType(toolResponse); errorType != "" {+ fields["error"] = map[string]interface{}{"type": errorType}+ } else if errorType := firstToolStringAcross(maps, "error.type", "error_type"); errorType != "" {+ fields["error"] = map[string]interface{}{"type": errorType}+ }+ jsonrpc := map[string]interface{}{}+ if id := firstToolStringAcross(maps, "jsonrpc.request.id", "jsonrpc_request_id", "request_id", "id"); id != "" {+ jsonrpc["request"] = map[string]interface{}{"id": id}+ }+ if version := firstToolStringAcross(maps, "jsonrpc.protocol.version", "jsonrpc_protocol_version", "jsonrpc"); version != "" {+ jsonrpc["protocol"] = map[string]interface{}{"version": version}+ }+ if len(jsonrpc) > 0 {+ fields["jsonrpc"] = jsonrpc+ }+ network := map[string]interface{}{}+ networkProtocol := map[string]interface{}{}+ if name := firstToolStringAcross(maps, "network.protocol.name", "network_protocol_name"); name != "" {+ networkProtocol["name"] = strings.ToLower(name)+ }+ if version := firstToolStringAcross(maps, "network.protocol.version", "network_protocol_version"); version != "" {+ networkProtocol["version"] = version+ }+ if len(networkProtocol) > 0 {+ network["protocol"] = networkProtocol+ }+ if transport := firstToolStringAcross(maps, "network.transport", "network_transport", "transport"); transport != "" {+ network["transport"] = strings.ToLower(transport)+ }+ if len(network) > 0 {+ fields["network"] = network+ }+ if status := firstToolStringAcross(maps, "rpc.response.status_code", "rpc_response_status_code", "status_code"); status != "" {+ fields["rpc"] = map[string]interface{}{"response": map[string]interface{}{"status_code": status}}+ }+ server := map[string]interface{}{}+ if address := firstToolStringAcross(maps, "server.address", "server_address", "serverAddress", "address"); address != "" {+ server["address"] = address+ }+ if port, ok := firstToolIntAcross(maps, "server.port", "server_port", "serverPort", "port"); ok {+ server["port"] = port+ }+ if len(server) > 0 {+ fields["server"] = server+ }+ return fields+}++func mcpErrorType(toolResponse map[string]interface{}) string {+ if toolResponse == nil {+ return ""+ }+ if errorType := firstToolString(toolResponse, "error.type", "error_type"); errorType != "" {+ return errorType+ }+ if isError := firstToolString(toolResponse, "isError", "is_error"); strings.EqualFold(isError, "true") {+ return "tool_error"+ }+ if errorText := firstToolString(toolResponse, "error"); errorText != "" {+ return "tool_error"+ }+ return ""+}+func diffFields(filePath, diffStr string) map[string]interface{} {if filePath == "" {return nil@@ -216,6 +373,57 @@ func firstToolString(input map[string]interface{}, keys ...string) string {return ""}+func firstToolStringAcross(inputs []map[string]interface{}, keys ...string) string {+ for _, input := range inputs {+ if input == nil {+ continue+ }+ if value := firstToolString(input, keys...); value != "" {+ return value+ }+ }+ return ""+}++func firstToolIntAcross(inputs []map[string]interface{}, keys ...string) (int, bool) {+ for _, input := range inputs {+ if input == nil {+ continue+ }+ for _, key := range keys {+ value, ok := input[key]+ if !ok {+ continue+ }+ switch typed := value.(type) {+ case int:+ return typed, true+ case int64:+ return int(typed), true+ case float64:+ return int(typed), true+ case string:+ parsed, err := strconv.Atoi(strings.TrimSpace(typed))+ if err == nil {+ return parsed, true+ }+ }+ }+ }+ return 0, false+}++func firstNestedString(input map[string]interface{}, key string) string {+ if input == nil {+ return ""+ }+ value, ok := input[key]+ if !ok {+ return ""+ }+ return normalizeToolString(value)+}+func normalizeToolString(value interface{}) string {str := strings.TrimSpace(fmt.Sprint(value))if str == "" || str == "<nil>" {diff --git a/cli/beacon-hooks/cmd/endpoint_events_test.go b/cli/beacon-hooks/cmd/endpoint_events_test.goindex 082308ff..0de4e41c 100644--- a/cli/beacon-hooks/cmd/endpoint_events_test.go+++ b/cli/beacon-hooks/cmd/endpoint_events_test.go@@ -10,6 +10,111 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon-hooks/internal/logging")+func TestToolFieldsMapsMCPGenAIStandardFields(t *testing.T) {+ tests := []struct {+ name string+ toolName string+ toolInput map[string]interface{}+ wantServer string+ wantTool string+ }{+ {+ name: "cursor tool name",+ toolName: "MCP:get_organizations",+ toolInput: map[string]interface{}{+ "jsonrpc_request_id": "req-1",+ "jsonrpc_protocol_version": "2.0",+ "mcp_protocol_version": "2025-06-18",+ "mcp_session_id": "mcp-session",+ "network_transport": "pipe",+ },+ wantTool: "get_organizations",+ },+ {+ name: "claude tool name",+ toolName: "mcp__memory__write",+ toolInput: map[string]interface{}{},+ wantServer: "memory",+ wantTool: "write",+ },+ {+ name: "payload server tool wins",+ toolName: "MCP:derived_tool",+ toolInput: map[string]interface{}{"server_name": "linear", "tool_name": "issue-get"},+ wantServer: "linear",+ wantTool: "issue-get",+ },+ }+ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ fields := toolFieldsWithResponse(tt.toolName, tt.toolInput, map[string]interface{}{"ok": true})+ mcp := fields["mcp"].(map[string]interface{})+ if mcp["server"] != tt.wantServer || mcp["tool"] != tt.wantTool {+ t.Fatalf("mcp = %#v, want server=%q tool=%q", mcp, tt.wantServer, tt.wantTool)+ }+ method := mcp["method"].(map[string]interface{})+ if method["name"] != "tools/call" {+ t.Fatalf("mcp.method = %#v, want tools/call", method)+ }+ genAI := fields["gen_ai"].(map[string]interface{})+ if op := genAI["operation"].(map[string]interface{})["name"]; op != "execute_tool" {+ t.Fatalf("gen_ai.operation = %q, want execute_tool", op)+ }+ tool := genAI["tool"].(map[string]interface{})+ if tool["name"] != tt.wantTool {+ t.Fatalf("gen_ai.tool = %#v, want name %q", tool, tt.wantTool)+ }+ call := tool["call"].(map[string]interface{})+ if len(tt.toolInput) > 0 && call["arguments"] == nil {+ t.Fatalf("gen_ai.tool.call = %#v, want arguments", call)+ }+ if call["result"] == nil {+ t.Fatalf("gen_ai.tool.call = %#v, want result", call)+ }+ })+ }+}++func TestToolFieldsMapsMCPTransportContext(t *testing.T) {+ fields := toolFields("MCP:read_resource", map[string]interface{}{+ "resource_uri": "file:///tmp/report.md",+ "jsonrpc_request_id": "request-7",+ "jsonrpc": "2.0",+ "network_protocol_name": "HTTP",+ "network_protocol_version": "2",+ "network_transport": "TCP",+ "server_address": "example.com",+ "server_port": "443",+ "status_code": "OK",+ })+ if got := fields["jsonrpc"].(map[string]interface{})["request"].(map[string]interface{})["id"]; got != "request-7" {+ t.Fatalf("jsonrpc.request.id = %q, want request-7", got)+ }+ if got := fields["network"].(map[string]interface{})["transport"]; got != "tcp" {+ t.Fatalf("network.transport = %q, want tcp", got)+ }+ if got := fields["server"].(map[string]interface{})["port"]; got != 443 {+ t.Fatalf("server.port = %#v, want 443", got)+ }+ if got := fields["rpc"].(map[string]interface{})["response"].(map[string]interface{})["status_code"]; got != "OK" {+ t.Fatalf("rpc.response.status_code = %q, want OK", got)+ }+ mcp := fields["mcp"].(map[string]interface{})+ if got := mcp["resource"].(map[string]interface{})["uri"]; got != "file:///tmp/report.md" {+ t.Fatalf("mcp.resource.uri = %q, want resource URI", got)+ }+}++func TestToolFieldsDoesNotTreatGenericNameAsMCP(t *testing.T) {+ fields := toolFields("Write", map[string]interface{}{"name": "README.md"})+ if _, ok := fields["mcp"]; ok {+ t.Fatalf("non-MCP tool should not include mcp fields: %#v", fields)+ }+ if _, ok := fields["gen_ai"]; ok {+ t.Fatalf("non-MCP tool should not include gen_ai fields: %#v", fields)+ }+}+func TestMaybeEmitInventoryHeartbeatInvokesBeaconCLI(t *testing.T) {oldPlatform := platformFlagoldRunner := runInventoryHeartbeatCommanddiff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.goindex ea5bab75..8bf0c6cb 100644--- a/cli/beacon-hooks/cmd/post_tool.go+++ b/cli/beacon-hooks/cmd/post_tool.go@@ -300,7 +300,8 @@ func emitPostToolObserved(logger *logging.Logger, input map[string]interface{})}sessionID := resolveSessionID(input, platformFlag)fields := sessionFields(sessionID, input)- for key, value := range toolFields(toolName, toolInput) {+ toolResponse := resolveToolResponse(input)+ for key, value := range toolFieldsWithResponse(toolName, toolInput, toolResponse) {fields[key] = value}if hookEvent == "PostToolUseFailure" || hookEvent == "postToolUseFailure" || hookEvent == "post_tool_use_failure" || getFirstStr(input, "error") != "" {diff --git a/cli/beacon-hooks/cmd/post_tool_test.go b/cli/beacon-hooks/cmd/post_tool_test.goindex 3a9515b6..c4f67ba1 100644--- a/cli/beacon-hooks/cmd/post_tool_test.go+++ b/cli/beacon-hooks/cmd/post_tool_test.go@@ -114,6 +114,62 @@ func TestRunPostToolEmitsCursorAfterShellExecution(t *testing.T) {}}+func TestRunPostToolEmitsCursorMCPGenAIFields(t *testing.T) {+ setupHookConfigDirs(t)+ platformFlag = "cursor"+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)++ out := runHookWithInput(t, runPostTool, map[string]interface{}{+ "conversation_id": "conv-mcp",+ "hook_event_name": "postToolUse",+ "tool_name": "MCP:get_organizations",+ "tool_input": map[string]interface{}{+ "jsonrpc_request_id": "req-1",+ "mcp_protocol_version": "2025-06-18",+ "mcp_session_id": "mcp-session",+ "network_transport": "pipe",+ },+ "tool_response": map[string]interface{}{"organizations": []interface{}{"meulo"}},+ "cwd": "/repo",+ })+ if len(out) != 0 {+ t.Fatalf("post-tool response = %#v, want empty response", out)+ }++ event := lastEndpointEvent(t, logPath)+ if action := event["event"].(map[string]interface{})["action"]; action != "mcp.tool_invoked" {+ t.Fatalf("event.action = %q, want mcp.tool_invoked", action)+ }+ if tool := event["tool"].(map[string]interface{})["name"]; tool != "MCP:get_organizations" {+ t.Fatalf("tool.name = %q, want raw Cursor MCP tool name", tool)+ }+ mcp := event["mcp"].(map[string]interface{})+ if mcp["tool"] != "get_organizations" {+ t.Fatalf("mcp = %#v, want get_organizations", mcp)+ }+ if method := mcp["method"].(map[string]interface{})["name"]; method != "tools/call" {+ t.Fatalf("mcp.method.name = %q, want tools/call", method)+ }+ genAI := event["gen_ai"].(map[string]interface{})+ if operation := genAI["operation"].(map[string]interface{})["name"]; operation != "execute_tool" {+ t.Fatalf("gen_ai.operation.name = %q, want execute_tool", operation)+ }+ genAITool := genAI["tool"].(map[string]interface{})+ if genAITool["name"] != "get_organizations" {+ t.Fatalf("gen_ai.tool = %#v, want get_organizations", genAITool)+ }+ if result := genAITool["call"].(map[string]interface{})["result"]; result == nil {+ t.Fatalf("gen_ai.tool.call.result missing: %#v", genAITool)+ }+ if transport := event["network"].(map[string]interface{})["transport"]; transport != "pipe" {+ t.Fatalf("network.transport = %q, want pipe", transport)+ }+ if requestID := event["jsonrpc"].(map[string]interface{})["request"].(map[string]interface{})["id"]; requestID != "req-1" {+ t.Fatalf("jsonrpc.request.id = %q, want req-1", requestID)+ }+}+func TestRunPostToolSuppressesCursorCloudReadPostToolDuplicate(t *testing.T) {setupHookConfigDirs(t)platformFlag = "cursor"@@ -538,8 +594,23 @@ func TestRunPostToolEmitsClaudeToolEvents(t *testing.T) {if severity := events[2]["severity"]; severity != "high" {t.Fatalf("failure severity = %q, want high", severity)}- if mcp := events[3]["mcp"].(map[string]interface{}); mcp["tool"] != "remember" {- t.Fatalf("mcp = %#v, want tool remember", mcp)+ mcp := events[3]["mcp"].(map[string]interface{})+ if mcp["server"] != "memory" || mcp["tool"] != "write" {+ t.Fatalf("mcp = %#v, want server memory tool write", mcp)+ }+ if method := mcp["method"].(map[string]interface{})["name"]; method != "tools/call" {+ t.Fatalf("mcp.method.name = %q, want tools/call", method)+ }+ genAI := events[3]["gen_ai"].(map[string]interface{})+ if operation := genAI["operation"].(map[string]interface{})["name"]; operation != "execute_tool" {+ t.Fatalf("gen_ai.operation.name = %q, want execute_tool", operation)+ }+ genAITool := genAI["tool"].(map[string]interface{})+ if genAITool["name"] != "write" {+ t.Fatalf("gen_ai.tool = %#v, want write", genAITool)+ }+ if result := genAITool["call"].(map[string]interface{})["result"]; result == nil {+ t.Fatalf("gen_ai.tool.call.result missing: %#v", genAITool)}}diff --git a/cli/beacon/beacon.zip b/cli/beacon/beacon.zipnew file mode 100644index 00000000..607b5f08Binary files /dev/null and b/cli/beacon/beacon.zip differdiff --git a/cli/beacon/internal/endpoint/dashboard/static/inventory-hooks.html b/cli/beacon/internal/endpoint/dashboard/static/inventory-hooks.htmlnew file mode 100644index 00000000..3b113df2--- /dev/null+++ b/cli/beacon/internal/endpoint/dashboard/static/inventory-hooks.html@@ -0,0 +1,108 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <title>Beacon Endpoint Hook Inventory</title>+ <link rel="stylesheet" href="/styles.css" />+ </head>+ <body data-page="inventory-hooks">+ <header class="topbar">+ <div>+ <p class="eyebrow">Local-only</p>+ <h1>Beacon Endpoint Hook Inventory</h1>+ </div>+ <nav class="nav-toggle" aria-label="Dashboard navigation">+ <a href="/">Log Search</a>+ <a href="/overview.html">Security Analytics</a>+ <a href="/findings.html">Findings</a>+ <a href="/detections.html">Detections</a>+ <a class="active" href="/inventory-hooks.html" aria-current="page">Agent Inventory</a>+ <a href="/tokens.html">Token Usage</a>+ </nav>+ <button id="refresh">Refresh</button>+ </header>++ <main>+ <section class="panel status-panel">+ <div>+ <h2>Endpoint</h2>+ <p id="log-path" class="muted">Loading runtime log...</p>+ </div>+ <div id="inventory-meta" class="muted"></div>+ </section>++ <section class="subnav" aria-label="Inventory views">+ <a href="/inventory.html">Inventory Overview</a>+ <a class="active" href="/inventory-hooks.html" aria-current="page">Hook Inventory</a>+ </section>++ <section>+ <div class="section-head overview-head">+ <div>+ <h2>Hook Inventory at a Glance</h2>+ <p class="muted">Installed hook adapters and hook manifest files discovered across supported local AI agent runtimes.</p>+ </div>+ </div>+ <div class="cards" id="hook-inventory-cards"></div>+ </section>++ <section class="panel">+ <div class="section-head">+ <div>+ <h2>Hook Targets</h2>+ <p class="muted">Supported runtimes Beacon checks for local hook configuration. Command bodies and hook file contents are not shown.</p>+ </div>+ </div>+ <div class="table-wrap">+ <table>+ <thead>+ <tr>+ <th>Runtime</th>+ <th>Status</th>+ <th>Scope</th>+ <th>Beacon Managed</th>+ <th>Binary</th>+ <th>Manifest</th>+ <th>Message</th>+ </tr>+ </thead>+ <tbody id="hook-targets"></tbody>+ </table>+ </div>+ </section>++ <section class="panel">+ <div class="section-head">+ <div>+ <h2>Hook Manifest Files</h2>+ <p class="muted">Discovered hook config files with parser status, timestamps, and hashes for change tracking.</p>+ </div>+ </div>+ <div class="table-wrap">+ <table>+ <thead>+ <tr>+ <th>Runtime</th>+ <th>Scope</th>+ <th>Parser</th>+ <th>Beacon Managed</th>+ <th>Modified</th>+ <th>Manifest SHA</th>+ <th>Manifest</th>+ </tr>+ </thead>+ <tbody id="hook-manifests"></tbody>+ </table>+ </div>+ </section>++ <section class="panel">+ <h2>Scan Scope</h2>+ <div id="inventory-scope" class="scope-grid"></div>+ </section>+ </main>++ <script src="/app.js"></script>+ </body>+</html>diff --git a/cli/beacon/internal/endpoint/schema/event.go b/cli/beacon/internal/endpoint/schema/event.goindex 0f4c6218..3f4217be 100644--- a/cli/beacon/internal/endpoint/schema/event.go+++ b/cli/beacon/internal/endpoint/schema/event.go@@ -49,6 +49,14 @@ type UserInfo = asymptoteobserve.UserInfotype HarnessInfo = asymptoteobserve.HarnessInfotype SessionInfo = asymptoteobserve.SessionInfotype TraceInfo = asymptoteobserve.TraceInfo+type ErrorInfo = asymptoteobserve.ErrorInfo+type JSONRPCInfo = asymptoteobserve.JSONRPCInfo+type JSONRPCRequestInfo = asymptoteobserve.JSONRPCRequestInfo+type JSONRPCProtocolInfo = asymptoteobserve.JSONRPCProtocolInfo+type NetworkInfo = asymptoteobserve.NetworkInfo+type NetworkProtocolInfo = asymptoteobserve.NetworkProtocolInfo+type RPCInfo = asymptoteobserve.RPCInfo+type RPCResponseInfo = asymptoteobserve.RPCResponseInfotype RunInfo = asymptoteobserve.RunInfotype ToolInfo = asymptoteobserve.ToolInfotype FileInfo = asymptoteobserve.FileInfo@@ -64,6 +72,7 @@ type PromptInfo = asymptoteobserve.PromptInfotype ContentInfo = asymptoteobserve.ContentInfotype DestinationInfo = asymptoteobserve.DestinationInfotype HealthInfo = asymptoteobserve.HealthInfo+type ServerInfo = asymptoteobserve.ServerInfotype GenAIInfo = asymptoteobserve.GenAIInfotype GenAIAgentInfo = asymptoteobserve.GenAIAgentInfotype GenAIConversationInfo = asymptoteobserve.GenAIConversationInfodiff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex 21e615d2..d3b2d5a0 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -623,11 +623,11 @@ func (c Converter) PopulateCommon(event *Event, attrs map[string]interface{}) {WorkingDirectory: FirstString(attrs, "cwd", "working_directory", "beacon.session.working_directory", "process.command_args.cwd", "workspace"),}}- if name := FirstString(attrs, "tool.name", "gen_ai.tool.name", "mcp.tool.name", "function_name", "tool_name"); name != "" || ToolCommandString(attrs) != "" {+ if name := FirstString(attrs, "tool.name", "gen_ai.tool.name", "beacon.tool.name", "mcp.tool.name", "function_name", "tool_name"); name != "" || ToolCommandString(attrs) != "" {event.Tool = &ToolInfo{Name: name,Command: FirstNonEmpty(ToolCommandString(attrs), FirstString(attrs, "process.command_line")),- Path: FirstString(attrs, "tool.path", "file.path", "file_path"),+ Path: FirstString(attrs, "tool.path", "beacon.tool.path", "file.path", "file_path"),}}path := FirstString(attrs, "file.path", "file_path", "code.filepath")@@ -657,6 +657,13 @@ func (c Converter) PopulateCommon(event *Event, attrs map[string]interface{}) {if mcp := MCPFromAttrs(attrs); mcp != nil {event.MCP = mcp}+ if standard := StandardContextFromAttrs(attrs); standard != nil {+ event.Error = standard.Error+ event.JSONRPC = standard.JSONRPC+ event.Network = standard.Network+ event.RPC = standard.RPC+ event.Server = standard.Server+ }if decision := FirstString(attrs, "approval.decision", "policy.decision", "decision"); decision != "" {event.Approval = &ApprovalInfo{Required: true,@@ -709,7 +716,7 @@ func GenAIFromAttrs(attrs map[string]interface{}) *GenAIInfo {} else if messages, ok := AnyAttr(attrs, "llm.prompts", "gen_ai.prompts"); ok {genai.Input = &GenAIInputInfo{Messages: messages}}- if name := FirstString(attrs, "gen_ai.operation.name"); name != "" {+ if name := FirstString(attrs, "gen_ai.operation.name", "beacon.gen_ai.operation.name"); name != "" {genai.Operation = &GenAIOperationInfo{Name: name}}if messages, ok := AnyAttr(attrs, "gen_ai.output.messages"); ok {@@ -816,18 +823,18 @@ func GenAIResponseFromAttrs(attrs map[string]interface{}) *GenAIResponseInfo {func GenAIToolFromAttrs(attrs map[string]interface{}) *GenAIToolInfo {tool := &GenAIToolInfo{Description: FirstString(attrs, "gen_ai.tool.description"),- Name: FirstString(attrs, "gen_ai.tool.name", "tool.name"),+ Name: FirstString(attrs, "gen_ai.tool.name", "beacon.gen_ai.tool.name", "beacon.tool.name", "tool.name", "mcp.tool.name", "function_name", "tool_name"),Type: FirstString(attrs, "gen_ai.tool.type"),}if definitions, ok := AnyAttr(attrs, "gen_ai.tool.definitions"); ok {tool.Definitions = definitions}- if args, ok := AnyAttr(attrs, "gen_ai.tool.call.arguments", "function_args", "arguments"); ok {- tool.Call = &GenAIToolCallInfo{Arguments: args, ID: FirstString(attrs, "gen_ai.tool.call.id")}- } else if id := FirstString(attrs, "gen_ai.tool.call.id"); id != "" {+ if args, ok := AnyAttr(attrs, "gen_ai.tool.call.arguments", "beacon.gen_ai.tool.call.arguments", "function_args", "arguments"); ok {+ tool.Call = &GenAIToolCallInfo{Arguments: args, ID: FirstString(attrs, "gen_ai.tool.call.id", "beacon.gen_ai.tool.call.id")}+ } else if id := FirstString(attrs, "gen_ai.tool.call.id", "beacon.gen_ai.tool.call.id"); id != "" {tool.Call = &GenAIToolCallInfo{ID: id}}- if result, ok := AnyAttr(attrs, "gen_ai.tool.call.result"); ok {+ if result, ok := AnyAttr(attrs, "gen_ai.tool.call.result", "beacon.gen_ai.tool.call.result"); ok {if tool.Call == nil {tool.Call = &GenAIToolCallInfo{}}@@ -871,8 +878,8 @@ func GenAIUsageFromAttrs(attrs map[string]interface{}) *GenAIUsageInfo {}func MCPFromAttrs(attrs map[string]interface{}) *MCPInfo {- server := FirstString(attrs, "mcp.server.name", "mcp.server", "gen_ai.mcp.server", "mcp_server_name")- tool := FirstString(attrs, "mcp.tool.name", "tool.name", "function_name")+ server := FirstString(attrs, "mcp.server", "beacon.mcp.server", "mcp.server.name", "gen_ai.mcp.server", "mcp_server_name")+ tool := FirstString(attrs, "mcp.tool", "beacon.mcp.tool", "mcp.tool.name")method := FirstString(attrs, "mcp.method.name")protocol := FirstString(attrs, "mcp.protocol.version")resource := FirstString(attrs, "mcp.resource.uri")@@ -880,6 +887,9 @@ func MCPFromAttrs(attrs map[string]interface{}) *MCPInfo {if server == "" && tool == "" && method == "" && protocol == "" && resource == "" && session == "" && FirstString(attrs, "tool_type") != "mcp" {return nil}+ if tool == "" {+ tool = FirstString(attrs, "gen_ai.tool.name", "beacon.gen_ai.tool.name", "beacon.tool.name", "tool.name", "function_name", "tool_name")+ }out := &MCPInfo{Server: server, Tool: tool}if method != "" {out.Method = &MCPMethodInfo{Name: method}@@ -896,6 +906,53 @@ func MCPFromAttrs(attrs map[string]interface{}) *MCPInfo {return out}+type standardContext struct {+ Error *ErrorInfo+ JSONRPC *JSONRPCInfo+ Network *NetworkInfo+ RPC *RPCInfo+ Server *ServerInfo+}++func StandardContextFromAttrs(attrs map[string]interface{}) *standardContext {+ out := &standardContext{}+ if errorType := FirstString(attrs, "error.type"); errorType != "" {+ out.Error = &ErrorInfo{Type: errorType}+ }+ if requestID := FirstString(attrs, "jsonrpc.request.id"); requestID != "" || FirstString(attrs, "jsonrpc.protocol.version") != "" {+ out.JSONRPC = &JSONRPCInfo{}+ if requestID != "" {+ out.JSONRPC.Request = &JSONRPCRequestInfo{ID: requestID}+ }+ if version := FirstString(attrs, "jsonrpc.protocol.version"); version != "" {+ out.JSONRPC.Protocol = &JSONRPCProtocolInfo{Version: version}+ }+ }+ if protocolName := FirstString(attrs, "network.protocol.name"); protocolName != "" || FirstString(attrs, "network.protocol.version", "network.transport") != "" {+ out.Network = &NetworkInfo{}+ if protocolName != "" || FirstString(attrs, "network.protocol.version") != "" {+ out.Network.Protocol = &NetworkProtocolInfo{+ Name: strings.ToLower(protocolName),+ Version: FirstString(attrs, "network.protocol.version"),+ }+ }+ out.Network.Transport = strings.ToLower(FirstString(attrs, "network.transport"))+ }+ if status := FirstString(attrs, "rpc.response.status_code"); status != "" {+ out.RPC = &RPCInfo{Response: &RPCResponseInfo{StatusCode: status}}+ }+ if address := FirstString(attrs, "server.address"); address != "" || HasAttr(attrs, "server.port") {+ out.Server = &ServerInfo{Address: address}+ if port, ok := IntAttr(attrs, "server.port"); ok {+ out.Server.Port = &port+ }+ }+ if out.Error == nil && out.JSONRPC == nil && out.Network == nil && out.RPC == nil && out.Server == nil {+ return nil+ }+ return out+}+func populateRunContext(event *Event, attrs map[string]interface{}) {switch RunString(attrs, asymptoteobserve.AttributeOrigin) {case string(asymptoteobserve.OriginLocal):@@ -981,7 +1038,7 @@ func RunString(attrs map[string]interface{}, keys ...string) string {}func ToolCommandString(attrs map[string]interface{}) string {- if command := FirstString(attrs, "tool.command", "command", "function_args"); command != "" {+ if command := FirstString(attrs, "tool.command", "beacon.tool.command", "command", "function_args"); command != "" {return command}return FirstStringAttr(attrs, "gen_ai.tool.call.arguments")@@ -1358,9 +1415,10 @@ func NormalizeHarnessName(name string) string {}func InferAction(attrs map[string]interface{}, fallback string) string {- tool := strings.ToLower(FirstString(attrs, "tool.name", "gen_ai.tool.name", "mcp.tool.name", "function_name", "tool_name"))+ tool := strings.ToLower(FirstString(attrs, "tool.name", "gen_ai.tool.name", "beacon.tool.name", "beacon.gen_ai.tool.name", "mcp.tool", "beacon.mcp.tool", "mcp.tool.name", "function_name", "tool_name"))operation := strings.ToLower(FirstString(attrs, "gen_ai.operation.name"))mcpMethod := strings.ToLower(FirstString(attrs, "mcp.method.name"))+ mcpServer := FirstString(attrs, "mcp.server", "beacon.mcp.server", "mcp.server.name", "mcp_server_name")harness := HarnessName(attrs, fallback)text := strings.ToLower(strings.Join([]string{fallback,@@ -1376,6 +1434,8 @@ func InferAction(attrs map[string]interface{}, fallback string) string {return "mcp.tool_invoked"case mcpMethod == "resources/read" && IsFileURI(FirstString(attrs, "mcp.resource.uri")):return "file.read"+ case mcpServer != "" || FirstString(attrs, "mcp.tool", "beacon.mcp.tool", "mcp.tool.name") != "":+ return "mcp.tool_invoked"case operation == "execute_tool":return "tool.invoked"case (operation == "chat" || operation == "generate_content" || operation == "text_completion") && HasPromptLikeContent(attrs):diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.goindex 782c7809..7cfdeb02 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go@@ -609,6 +609,113 @@ func TestPopulateCommonMapsBeaconSessionAttributes(t *testing.T) {}}+func TestEventsFromTracesMapsMCPGenAIClientSpanAttributes(t *testing.T) {+ span, traces := newObserveSDKTraceSpan("tools/call get_organizations")+ attrs := span.Attributes()+ attrs.PutStr("gen_ai.operation.name", "execute_tool")+ attrs.PutStr("gen_ai.tool.name", "get_organizations")+ attrs.PutStr("gen_ai.tool.call.id", "call-1")+ attrs.PutStr("gen_ai.tool.call.arguments", `{"org":"meulo"}`)+ attrs.PutStr("gen_ai.tool.call.result", `{"ok":true}`)+ attrs.PutStr("mcp.method.name", "tools/call")+ attrs.PutStr("mcp.protocol.version", "2025-06-18")+ attrs.PutStr("mcp.resource.uri", "file:///tmp/report.md")+ attrs.PutStr("mcp.session.id", "mcp-session")+ attrs.PutStr("jsonrpc.request.id", "request-7")+ attrs.PutStr("jsonrpc.protocol.version", "2.0")+ attrs.PutStr("rpc.response.status_code", "OK")+ attrs.PutStr("network.protocol.name", "HTTP")+ attrs.PutStr("network.protocol.version", "2")+ attrs.PutStr("network.transport", "TCP")+ attrs.PutStr("server.address", "example.com")+ attrs.PutInt("server.port", 443)+ attrs.PutStr("error.type", "tool_error")++ events := NewConverter(Options{}).EventsFromTraces(traces)+ if len(events) != 1 {+ t.Fatalf("expected 1 event, got %d", len(events))+ }+ event := events[0]+ if event.Event.Action != "mcp.tool_invoked" || event.Event.Category != "mcp" {+ t.Fatalf("event = %#v, want mcp.tool_invoked/mcp", event.Event)+ }+ if event.GenAI == nil || event.GenAI.Operation == nil || event.GenAI.Operation.Name != "execute_tool" {+ t.Fatalf("gen_ai operation = %#v, want execute_tool", event.GenAI)+ }+ if event.GenAI.Tool == nil || event.GenAI.Tool.Name != "get_organizations" || event.GenAI.Tool.Call == nil {+ t.Fatalf("gen_ai tool = %#v, want get_organizations call", event.GenAI.Tool)+ }+ if event.MCP == nil || event.MCP.Method == nil || event.MCP.Method.Name != "tools/call" || event.MCP.Protocol == nil || event.MCP.Protocol.Version != "2025-06-18" {+ t.Fatalf("mcp = %#v, want method/protocol", event.MCP)+ }+ if event.JSONRPC == nil || event.JSONRPC.Request == nil || event.JSONRPC.Request.ID != "request-7" || event.JSONRPC.Protocol == nil || event.JSONRPC.Protocol.Version != "2.0" {+ t.Fatalf("jsonrpc = %#v, want request/protocol", event.JSONRPC)+ }+ if event.Network == nil || event.Network.Protocol == nil || event.Network.Protocol.Name != "http" || event.Network.Transport != "tcp" {+ t.Fatalf("network = %#v, want lower-cased protocol/transport", event.Network)+ }+ if event.RPC == nil || event.RPC.Response == nil || event.RPC.Response.StatusCode != "OK" {+ t.Fatalf("rpc = %#v, want OK response status", event.RPC)+ }+ if event.Server == nil || event.Server.Address != "example.com" || event.Server.Port == nil || *event.Server.Port != 443 {+ t.Fatalf("server = %#v, want example.com:443", event.Server)+ }+ if event.Error == nil || event.Error.Type != "tool_error" {+ t.Fatalf("error = %#v, want tool_error", event.Error)+ }+}++func TestEventsFromTracesMapsBeaconMCPAliases(t *testing.T) {+ span, traces := newObserveSDKTraceSpan("beacon mcp tool")+ attrs := span.Attributes()+ attrs.PutStr("beacon.tool.name", "alias_tool")+ attrs.PutStr("beacon.tool.command", "alias command")+ attrs.PutStr("beacon.tool.path", "/tmp/input.txt")+ attrs.PutStr("beacon.mcp.server", "clickhouse")+ attrs.PutStr("beacon.mcp.tool", "query")+ attrs.PutStr("mcp.method.name", "tools/call")++ events := NewConverter(Options{}).EventsFromTraces(traces)+ if len(events) != 1 {+ t.Fatalf("expected 1 event, got %d", len(events))+ }+ event := events[0]+ if event.Event.Action != "mcp.tool_invoked" {+ t.Fatalf("event.action = %q, want mcp.tool_invoked", event.Event.Action)+ }+ if event.Tool == nil || event.Tool.Name != "alias_tool" || event.Tool.Command != "alias command" || event.Tool.Path != "/tmp/input.txt" {+ t.Fatalf("tool = %#v, want beacon.tool aliases", event.Tool)+ }+ if event.MCP == nil || event.MCP.Server != "clickhouse" || event.MCP.Tool != "query" {+ t.Fatalf("mcp = %#v, want beacon.mcp aliases", event.MCP)+ }+ if event.GenAI == nil || event.GenAI.Tool == nil || event.GenAI.Tool.Name != "alias_tool" {+ t.Fatalf("gen_ai tool = %#v, want beacon.tool.name fallback", event.GenAI)+ }+}++func TestEventsFromTracesDoesNotPromotePlainGenAIToolToMCP(t *testing.T) {+ span, traces := newObserveSDKTraceSpan("execute_tool plain_tool")+ attrs := span.Attributes()+ attrs.PutStr("gen_ai.operation.name", "execute_tool")+ attrs.PutStr("gen_ai.tool.name", "plain_tool")++ events := NewConverter(Options{}).EventsFromTraces(traces)+ if len(events) != 1 {+ t.Fatalf("expected 1 event, got %d", len(events))+ }+ event := events[0]+ if event.Event.Action != "tool.invoked" {+ t.Fatalf("event.action = %q, want tool.invoked", event.Event.Action)+ }+ if event.GenAI == nil || event.GenAI.Tool == nil || event.GenAI.Tool.Name != "plain_tool" {+ t.Fatalf("gen_ai tool = %#v, want plain_tool", event.GenAI)+ }+ if event.MCP != nil {+ t.Fatalf("plain GenAI tool should not populate MCP: %#v", event.MCP)+ }+}+func newObserveSDKTraceSpan(name string) (ptrace.Span, ptrace.Traces) {traces := ptrace.NewTraces()resourceSpans := traces.ResourceSpans().AppendEmpty()diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/event.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/event.goindex e10dbb2c..2d5c7a02 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/event.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/event.go@@ -18,6 +18,14 @@ type UserInfo = asymptoteobserve.UserInfotype HarnessInfo = asymptoteobserve.HarnessInfotype SessionInfo = asymptoteobserve.SessionInfotype TraceInfo = asymptoteobserve.TraceInfo+type ErrorInfo = asymptoteobserve.ErrorInfo+type JSONRPCInfo = asymptoteobserve.JSONRPCInfo+type JSONRPCRequestInfo = asymptoteobserve.JSONRPCRequestInfo+type JSONRPCProtocolInfo = asymptoteobserve.JSONRPCProtocolInfo+type NetworkInfo = asymptoteobserve.NetworkInfo+type NetworkProtocolInfo = asymptoteobserve.NetworkProtocolInfo+type RPCInfo = asymptoteobserve.RPCInfo+type RPCResponseInfo = asymptoteobserve.RPCResponseInfotype RunInfo = asymptoteobserve.RunInfotype ToolInfo = asymptoteobserve.ToolInfotype FileInfo = asymptoteobserve.FileInfo@@ -31,6 +39,7 @@ type ApprovalInfo = asymptoteobserve.ApprovalInfotype PolicyInfo = asymptoteobserve.PolicyInfotype PromptInfo = asymptoteobserve.PromptInfotype ContentInfo = asymptoteobserve.ContentInfo+type ServerInfo = asymptoteobserve.ServerInfotype GenAIInfo = asymptoteobserve.GenAIInfotype GenAIAgentInfo = asymptoteobserve.GenAIAgentInfotype GenAIConversationInfo = asymptoteobserve.GenAIConversationInfo@@ -67,9 +76,14 @@ type Event struct {User UserInfo `json:"user,omitempty"`Harness HarnessInfo `json:"harness"`Origin asymptoteobserve.Origin `json:"origin,omitempty"`+ Error *ErrorInfo `json:"error,omitempty"`Run *RunInfo `json:"run,omitempty"`Session *SessionInfo `json:"session,omitempty"`Trace *TraceInfo `json:"trace,omitempty"`+ JSONRPC *JSONRPCInfo `json:"jsonrpc,omitempty"`+ Network *NetworkInfo `json:"network,omitempty"`+ RPC *RPCInfo `json:"rpc,omitempty"`+ Server *ServerInfo `json:"server,omitempty"`Tool *ToolInfo `json:"tool,omitempty"`File *FileInfo `json:"file,omitempty"`Command *CommandInfo `json:"command,omitempty"`diff --git a/docs/sdk/reference.mdx b/docs/sdk/reference.mdxindex 7789307a..4936a4f6 100644--- a/docs/sdk/reference.mdx+++ b/docs/sdk/reference.mdx@@ -87,6 +87,12 @@ Cloud SDKs should prefer standard OpenTelemetry attributes when they exist, espe| `beacon.file.language` | Language identifier || `beacon.mcp.server` | MCP server name || `beacon.mcp.tool` | MCP tool name |+| `gen_ai.operation.name` | OpenTelemetry GenAI operation name, such as `execute_tool` |+| `gen_ai.tool.name` | OpenTelemetry GenAI tool name |+| `gen_ai.tool.call.arguments`, `gen_ai.tool.call.id`, `gen_ai.tool.call.result` | OpenTelemetry GenAI tool call details |+| `mcp.method.name`, `mcp.protocol.version`, `mcp.resource.uri`, `mcp.session.id` | OpenTelemetry MCP request context |+| `jsonrpc.request.id`, `jsonrpc.protocol.version`, `rpc.response.status_code` | JSON-RPC and RPC request/response context |+| `network.protocol.name`, `network.protocol.version`, `network.transport`, `server.address`, `server.port`, `error.type` | MCP transport, peer, and error context || `beacon.approval.decision` | Approval or policy decision || `beacon.approval.reason` | Approval or policy reason || `beacon.prompt.text` | Prompt text when available |diff --git a/docs/telemetry-schema/fields.mdx b/docs/telemetry-schema/fields.mdxindex a1e1ac7c..15c00f49 100644--- a/docs/telemetry-schema/fields.mdx+++ b/docs/telemetry-schema/fields.mdx@@ -17,10 +17,15 @@ Beacon models each event as an action plus a set of typed entities. The [`event`| `origin` | Event origin for local endpoint, cloud, or CI telemetry | `local`, `cloud`, `ci` || `run` | CI or ephemeral run context | `provider`, `run_id`, `run_attempt`, `workflow`, `job`, `event_name`, `commit`, `repository`, `branch`, `pr`, `pr_number`, `actor`, `ephemeral` || `session` | Conversation or runtime session context | `id`, `working_directory` |+| `error` | Standard error context when an MCP/JSON-RPC/tool operation fails | `type` |+| `jsonrpc` | JSON-RPC request and protocol context for MCP calls | `request.id`, `protocol.version` |+| `network` | Network protocol and transport context | `protocol.name`, `protocol.version`, `transport` |+| `rpc` | RPC response context | `response.status_code` |+| `server` | Peer server context when available | `address`, `port` || `tool` | Tool invocation context, including shell-like tools | `name`, `command`, `path` || `file` | File activity context | `path`, `operation`, `language`, `diff_hash`, `diff_bytes` || `command` | Shell or process execution context | `command`, `exit_code`, `duration_ms` |-| `mcp` | MCP-like server and tool context | `server`, `tool` |+| `mcp` | MCP server, tool, method, protocol, resource, and session context | `server`, `tool`, `method.name`, `protocol.version`, `resource.uri`, `session.id` || `approval` | Approval or policy decision context | `required`, `decision`, `reason` || `policy` | Policy metadata when available from a runtime or integration | `id`, `name`, `decision`, `enforcement`, `reason` || `prompt` | Prompt text when the source emits it and content handling allows it | `text` |@@ -59,7 +64,8 @@ Optional context fields add detail when available:| `tool` | Tool name, command, or path metadata || `file` | File path, operation, language, diff hash, or diff byte counts || `command` | Shell command, exit code, or duration metadata |-| `mcp` | MCP-like server and tool metadata |+| `mcp` | MCP server, tool, method, protocol, resource, or session metadata |+| `jsonrpc`, `rpc`, `network`, `server`, `error` | MCP client-span context projected from OpenTelemetry semantic conventions when available || `approval` | Approval requirement, decision, or reason || `policy` | Policy ID, name, decision, enforcement mode, or reason || `content` | Content inclusion, redaction, and truncation state |diff --git a/docs/telemetry-schema/normalization.mdx b/docs/telemetry-schema/normalization.mdxindex ea2fb82b..41540eeb 100644--- a/docs/telemetry-schema/normalization.mdx+++ b/docs/telemetry-schema/normalization.mdx@@ -12,10 +12,13 @@ Beacon normalizes [OTLP](/concepts/core-concepts#otlp) attributes and [hook](/co| Source signal | Normalized field or action ||---------------|----------------------------|| `gen_ai.request.model`, `gen_ai.response.model`, `model`, `ai.model` | `model` |-| `gen_ai.tool.name`, `tool.name`, `function_name`, `tool_name` | `tool.name` and `gen_ai.tool.name` |+| `gen_ai.tool.name`, `tool.name`, `beacon.tool.name`, `function_name`, `tool_name` | `tool.name` and `gen_ai.tool.name` || `gen_ai.tool.call.arguments`, `function_args`, `arguments` | `tool.command` when command-like, plus `gen_ai.tool.call.arguments` || `gen_ai.tool.call.id`, `gen_ai.tool.call.result` | `gen_ai.tool.call.id`, `gen_ai.tool.call.result` |-| `mcp.tool.name` | `mcp.tool` |+| `mcp.method.name`, `mcp.protocol.version`, `mcp.resource.uri`, `mcp.session.id` | `mcp.method.name`, `mcp.protocol.version`, `mcp.resource.uri`, `mcp.session.id` |+| `mcp.tool`, `beacon.mcp.tool`, `mcp.tool.name` | `mcp.tool` |+| `mcp.server`, `beacon.mcp.server`, `mcp.server.name` | `mcp.server` |+| `jsonrpc.*`, `rpc.response.status_code`, `network.*`, `server.*`, `error.type` | `jsonrpc`, `rpc`, `network`, `server`, and `error` || `process.command_line` | `command.command` || `file.path` | `file.path` || `conversation.id` | `session.id` |diff --git a/packages/asymptote-sdk-js/src/constants.ts b/packages/asymptote-sdk-js/src/constants.tsindex ff388256..ef359bed 100644--- a/packages/asymptote-sdk-js/src/constants.ts+++ b/packages/asymptote-sdk-js/src/constants.ts@@ -25,6 +25,25 @@ export const ATTR_BEACON_FILE_LANGUAGE = "beacon.file.language";export const ATTR_BEACON_MCP_SERVER = "beacon.mcp.server";export const ATTR_BEACON_MCP_TOOL = "beacon.mcp.tool";+export const ATTR_GEN_AI_OPERATION_NAME = "gen_ai.operation.name";+export const ATTR_GEN_AI_TOOL_NAME = "gen_ai.tool.name";+export const ATTR_GEN_AI_TOOL_CALL_ARGUMENTS = "gen_ai.tool.call.arguments";+export const ATTR_GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";+export const ATTR_GEN_AI_TOOL_CALL_RESULT = "gen_ai.tool.call.result";+export const ATTR_MCP_METHOD_NAME = "mcp.method.name";+export const ATTR_MCP_PROTOCOL_VERSION = "mcp.protocol.version";+export const ATTR_MCP_RESOURCE_URI = "mcp.resource.uri";+export const ATTR_MCP_SESSION_ID = "mcp.session.id";+export const ATTR_JSONRPC_REQUEST_ID = "jsonrpc.request.id";+export const ATTR_JSONRPC_PROTOCOL_VERSION = "jsonrpc.protocol.version";+export const ATTR_RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";+export const ATTR_NETWORK_PROTOCOL_NAME = "network.protocol.name";+export const ATTR_NETWORK_PROTOCOL_VERSION = "network.protocol.version";+export const ATTR_NETWORK_TRANSPORT = "network.transport";+export const ATTR_SERVER_ADDRESS = "server.address";+export const ATTR_SERVER_PORT = "server.port";+export const ATTR_ERROR_TYPE = "error.type";+export const ATTR_BEACON_APPROVAL_DECISION = "beacon.approval.decision";export const ATTR_BEACON_APPROVAL_REASON = "beacon.approval.reason";diff --git a/pkg/asymptoteobserve/dedupe.go b/pkg/asymptoteobserve/dedupe.gonew file mode 100644index 00000000..d3db1ce4--- /dev/null+++ b/pkg/asymptoteobserve/dedupe.go@@ -0,0 +1,224 @@+package asymptoteobserve++import (+ "bytes"+ "encoding/json"+ "os"+ "strings"+ "time"+)++const (+ // EndpointDuplicateWindow is intentionally short: it catches overlapping+ // hook/OTLP reports for the same runtime action without collapsing separate+ // tool calls that happen later in the same session.+ EndpointDuplicateWindow = 2 * time.Second+ endpointDedupeTailBytes = 256 * 1024+)++type endpointDedupeEvent struct {+ action string+ key string+ ts time.Time+}++// IsDuplicateEndpointEvent reports whether candidateLine duplicates a recently+// appended endpoint event in path. It is best called while the runtime log lock+// is already held by the caller.+func IsDuplicateEndpointEvent(path string, candidateLine []byte, window time.Duration) bool {+ candidate, ok := endpointDedupeCandidate(candidateLine)+ if !ok {+ return false+ }+ data, err := readEndpointDedupeTail(path)+ if err != nil {+ return false+ }+ effectiveWindow := endpointDedupeWindow(candidate.action, window)+ for _, line := range bytes.Split(data, []byte{'\n'}) {+ existing, ok := endpointDedupeCandidate(line)+ if !ok || existing.key != candidate.key {+ continue+ }+ diff := candidate.ts.Sub(existing.ts)+ if diff < 0 {+ diff = -diff+ }+ if diff <= effectiveWindow {+ return true+ }+ }+ return false+}++func readEndpointDedupeTail(path string) ([]byte, error) {+ f, err := os.Open(path)+ if err != nil {+ return nil, err+ }+ defer f.Close()+ info, err := f.Stat()+ if err != nil {+ return nil, err+ }+ size := info.Size()+ offset := int64(0)+ if size > endpointDedupeTailBytes {+ offset = size - endpointDedupeTailBytes+ }+ buf := make([]byte, size-offset)+ _, err = f.ReadAt(buf, offset)+ if err != nil && len(buf) == 0 {+ return nil, err+ }+ return buf, nil+}++func endpointDedupeCandidate(line []byte) (endpointDedupeEvent, bool) {+ line = bytes.TrimSpace(line)+ if len(line) == 0 {+ return endpointDedupeEvent{}, false+ }+ var event map[string]interface{}+ if err := json.Unmarshal(line, &event); err != nil {+ return endpointDedupeEvent{}, false+ }+ action := nestedString(event, "event", "action")+ if !dedupeAction(action) {+ return endpointDedupeEvent{}, false+ }+ sessionID := nestedString(event, "session", "id")+ if sessionID == "" {+ return endpointDedupeEvent{}, false+ }+ ts, err := time.Parse(time.RFC3339Nano, stringValue(event["timestamp"]))+ if err != nil || ts.IsZero() {+ return endpointDedupeEvent{}, false+ }+ target := dedupeTarget(action, event)+ if target == "" {+ return endpointDedupeEvent{}, false+ }+ workspace := firstNonEmptyString(+ nestedString(event, "session", "working_directory"),+ stringValue(event["repository"]),+ )+ key := strings.Join([]string{+ strings.ToLower(action),+ sessionID,+ strings.ToLower(workspace),+ target,+ }, "\x00")+ return endpointDedupeEvent{action: strings.ToLower(action), key: key, ts: ts.UTC()}, true+}++func endpointDedupeWindow(action string, fallback time.Duration) time.Duration {+ if fallback <= 0 {+ fallback = EndpointDuplicateWindow+ }+ if strings.EqualFold(action, "tool.completed") && fallback < 10*time.Second {+ return 10 * time.Second+ }+ return fallback+}++func dedupeAction(action string) bool {+ switch strings.ToLower(strings.TrimSpace(action)) {+ case "mcp.tool_invoked",+ "command.executed",+ "file.read",+ "file.modified",+ "tool.invoked",+ "tool.completed",+ "tool.failed":+ return true+ default:+ return false+ }+}++func dedupeTarget(action string, event map[string]interface{}) string {+ switch strings.ToLower(strings.TrimSpace(action)) {+ case "mcp.tool_invoked":+ return canonicalTarget("mcp",+ nestedString(event, "mcp", "server"),+ firstNonEmptyString(+ nestedString(event, "mcp", "tool"),+ nestedString(event, "tool", "name"),+ stringValue(event["message"]),+ ),+ )+ case "command.executed":+ return canonicalTarget("command", nestedString(event, "command", "command"), nestedString(event, "tool", "command"))+ case "file.read", "file.modified":+ return canonicalTarget("file", nestedString(event, "file", "path"), nestedString(event, "file", "operation"))+ case "tool.completed":+ return canonicalTarget("tool.completed", stringValue(event["model"]), stringValue(event["message"]))+ case "tool.invoked", "tool.failed":+ return canonicalTarget("tool", nestedString(event, "tool", "name"), nestedString(event, "tool", "path"), stringValue(event["message"]))+ default:+ return ""+ }+}++func canonicalTarget(prefix string, values ...string) string {+ var parts []string+ for _, value := range values {+ value = strings.ToLower(strings.TrimSpace(value))+ value = strings.TrimPrefix(value, "mcp:")+ value = strings.TrimPrefix(value, "mcp__")+ value = strings.ReplaceAll(value, "__", ":")+ if value != "" && value != "<nil>" {+ parts = append(parts, value)+ }+ }+ if len(parts) == 0 {+ return ""+ }+ return prefix + ":" + strings.Join(parts, "|")+}++func nestedString(root map[string]interface{}, keys ...string) string {+ var current interface{} = root+ for _, key := range keys {+ next, ok := current.(map[string]interface{})+ if !ok {+ return ""+ }+ current = next[key]+ }+ return stringValue(current)+}++func stringValue(value interface{}) string {+ switch typed := value.(type) {+ case string:+ return strings.TrimSpace(typed)+ case nil:+ return ""+ default:+ return strings.TrimSpace(toString(typed))+ }+}++func toString(value interface{}) string {+ switch typed := value.(type) {+ case []byte:+ return string(typed)+ default:+ data, err := json.Marshal(typed)+ if err != nil {+ return ""+ }+ return strings.Trim(string(data), `"`)+ }+}++func firstNonEmptyString(values ...string) string {+ for _, value := range values {+ if strings.TrimSpace(value) != "" {+ return strings.TrimSpace(value)+ }+ }+ return ""+}diff --git a/pkg/asymptoteobserve/dedupe_test.go b/pkg/asymptoteobserve/dedupe_test.gonew file mode 100644index 00000000..f31ff343--- /dev/null+++ b/pkg/asymptoteobserve/dedupe_test.go@@ -0,0 +1,60 @@+package asymptoteobserve++import (+ "os"+ "path/filepath"+ "testing"+)++func TestIsDuplicateEndpointEventMatchesAcrossHarnesses(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ existing := `{"timestamp":"2026-06-18T21:11:24Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"cursor"},"session":{"id":"s1","working_directory":"/repo"},"mcp":{"server":"clickhouse","tool":"execute_sql"},"message":"Tool execution observed"}`+ candidate := []byte(`{"timestamp":"2026-06-18T21:11:25Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"claude"},"session":{"id":"s1","working_directory":"/repo"},"tool":{"name":"MCP:execute_sql"},"mcp":{"server":"clickhouse","tool":"execute_sql"},"message":"Tool execution observed"}`)+ if err := os.WriteFile(path, []byte(existing+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if !IsDuplicateEndpointEvent(path, candidate, EndpointDuplicateWindow) {+ t.Fatal("expected duplicate MCP event across harnesses")+ }+}++func TestIsDuplicateEndpointEventKeepsSeparateCallsOutsideWindow(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ existing := `{"timestamp":"2026-06-18T21:11:19Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"cursor"},"session":{"id":"s1"},"mcp":{"server":"clickhouse","tool":"execute_sql"}}`+ candidate := []byte(`{"timestamp":"2026-06-18T21:11:24Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"claude"},"session":{"id":"s1"},"mcp":{"server":"clickhouse","tool":"execute_sql"}}`)+ if err := os.WriteFile(path, []byte(existing+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if IsDuplicateEndpointEvent(path, candidate, EndpointDuplicateWindow) {+ t.Fatal("did not expect events five seconds apart to dedupe")+ }+}++func TestIsDuplicateEndpointEventRequiresSession(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ existing := `{"timestamp":"2026-06-18T21:11:24Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"cursor"},"mcp":{"tool":"list_tables"}}`+ candidate := []byte(`{"timestamp":"2026-06-18T21:11:25Z","event":{"action":"mcp.tool_invoked"},"harness":{"name":"claude"},"mcp":{"tool":"list_tables"}}`)+ if err := os.WriteFile(path, []byte(existing+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if IsDuplicateEndpointEvent(path, candidate, EndpointDuplicateWindow) {+ t.Fatal("events without session IDs should not dedupe")+ }+}++func TestIsDuplicateEndpointEventMatchesToolCompletion(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ existing := `{"timestamp":"2026-06-18T21:11:25Z","event":{"action":"tool.completed"},"harness":{"name":"cursor"},"session":{"id":"s1"},"model":"gpt-5.5-medium","message":"Agent response completed"}`+ candidate := []byte(`{"timestamp":"2026-06-18T21:11:34Z","event":{"action":"tool.completed"},"harness":{"name":"claude"},"session":{"id":"s1"},"model":"gpt-5.5-medium","message":"Agent response completed"}`)+ if err := os.WriteFile(path, []byte(existing+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if IsDuplicateEndpointEvent(path, candidate, EndpointDuplicateWindow) {+ return+ }+ t.Fatal("expected duplicate tool completion within custom window")+}diff --git a/pkg/asymptoteobserve/event.go b/pkg/asymptoteobserve/event.goindex ec4fec65..cf32cbc4 100644--- a/pkg/asymptoteobserve/event.go+++ b/pkg/asymptoteobserve/event.go@@ -83,6 +83,41 @@ type TraceInfo struct {ParentSpanID string `json:"parent_span_id,omitempty"`}+type ErrorInfo struct {+ Type string `json:"type,omitempty"`+}++type JSONRPCRequestInfo struct {+ ID string `json:"id,omitempty"`+}++type JSONRPCProtocolInfo struct {+ Version string `json:"version,omitempty"`+}++type JSONRPCInfo struct {+ Request *JSONRPCRequestInfo `json:"request,omitempty"`+ Protocol *JSONRPCProtocolInfo `json:"protocol,omitempty"`+}++type NetworkProtocolInfo struct {+ Name string `json:"name,omitempty"`+ Version string `json:"version,omitempty"`+}++type NetworkInfo struct {+ Protocol *NetworkProtocolInfo `json:"protocol,omitempty"`+ Transport string `json:"transport,omitempty"`+}++type RPCResponseInfo struct {+ StatusCode string `json:"status_code,omitempty"`+}++type RPCInfo struct {+ Response *RPCResponseInfo `json:"response,omitempty"`+}+type RunInfo struct {Provider string `json:"provider,omitempty"`RunID string `json:"run_id,omitempty"`@@ -336,6 +371,11 @@ type HealthInfo struct {Reason string `json:"reason,omitempty"`}+type ServerInfo struct {+ Address string `json:"address,omitempty"`+ Port *int `json:"port,omitempty"`+}+type Event struct {Timestamp string `json:"timestamp"`Vendor string `json:"vendor"`@@ -347,9 +387,14 @@ type Event struct {User UserInfo `json:"user,omitempty"`Harness HarnessInfo `json:"harness"`Origin Origin `json:"origin,omitempty"`+ Error *ErrorInfo `json:"error,omitempty"`Run *RunInfo `json:"run,omitempty"`Session *SessionInfo `json:"session,omitempty"`Trace *TraceInfo `json:"trace,omitempty"`+ JSONRPC *JSONRPCInfo `json:"jsonrpc,omitempty"`+ Network *NetworkInfo `json:"network,omitempty"`+ RPC *RPCInfo `json:"rpc,omitempty"`+ Server *ServerInfo `json:"server,omitempty"`Tool *ToolInfo `json:"tool,omitempty"`File *FileInfo `json:"file,omitempty"`Command *CommandInfo `json:"command,omitempty"`diff --git a/pkg/asymptoteobserve/event_test.go b/pkg/asymptoteobserve/event_test.goindex 8babf8da..7173f6e3 100644--- a/pkg/asymptoteobserve/event_test.go+++ b/pkg/asymptoteobserve/event_test.go@@ -38,6 +38,11 @@ func TestNewEventSetsRequiredInvariants(t *testing.T) {event.File = &FileInfo{Path: "main.go", Operation: "modify"}event.Command = &CommandInfo{Command: "go test ./..."}event.MCP = &MCPInfo{Server: "github", Tool: "get_issue", Method: &MCPMethodInfo{Name: "tools/call"}}+ event.JSONRPC = &JSONRPCInfo{Request: &JSONRPCRequestInfo{ID: "request-7"}, Protocol: &JSONRPCProtocolInfo{Version: "2.0"}}+ event.Network = &NetworkInfo{Protocol: &NetworkProtocolInfo{Name: "http", Version: "2"}, Transport: "tcp"}+ event.RPC = &RPCInfo{Response: &RPCResponseInfo{StatusCode: "OK"}}+ event.Server = &ServerInfo{Address: "example.com", Port: intPtr(443)}+ event.Error = &ErrorInfo{Type: "tool_error"}event.Prompt = &PromptInfo{Text: "Summarize this file"}event.Content = &ContentInfo{Retention: ContentRetentionMetadata, Included: false}event.GenAI = &GenAIInfo{@@ -101,6 +106,10 @@ func int64Ptr(value int64) *int64 {return &value}+func intPtr(value int) *int {+ return &value+}+func float64Ptr(value float64) *float64 {return &value}@@ -141,6 +150,45 @@ func TestTraceAndUsageCostSerializeWithSemconvNames(t *testing.T) {}}+func TestMCPStandardContextSerializesWithSemconvNames(t *testing.T) {+ event := NewEvent(NewEventOptions{Action: "mcp.tool_invoked", Category: "mcp", Harness: HarnessInfo{Name: "cursor"}})+ event.MCP = &MCPInfo{+ Method: &MCPMethodInfo{Name: "tools/call"},+ Protocol: &MCPProtocolInfo{Version: "2025-06-18"},+ Resource: &MCPResourceInfo{URI: "file:///tmp/report.md"},+ Session: &MCPSessionInfo{ID: "mcp-session"},+ }+ event.GenAI = &GenAIInfo{+ Operation: &GenAIOperationInfo{Name: "execute_tool"},+ Tool: &GenAIToolInfo{Name: "get_organizations", Call: &GenAIToolCallInfo{ID: "call-1"}},+ }+ event.JSONRPC = &JSONRPCInfo{Request: &JSONRPCRequestInfo{ID: "request-7"}, Protocol: &JSONRPCProtocolInfo{Version: "2.0"}}+ event.Network = &NetworkInfo{Protocol: &NetworkProtocolInfo{Name: "http", Version: "2"}, Transport: "tcp"}+ event.RPC = &RPCInfo{Response: &RPCResponseInfo{StatusCode: "OK"}}+ event.Server = &ServerInfo{Address: "example.com", Port: intPtr(443)}+ event.Error = &ErrorInfo{Type: "tool_error"}++ data, err := json.Marshal(event)+ if err != nil {+ t.Fatalf("marshal event: %v", err)+ }+ text := string(data)+ for _, want := range []string{+ `"gen_ai":{"operation":{"name":"execute_tool"}`,+ `"tool":{"call":{"id":"call-1"},"name":"get_organizations"}`,+ `"mcp":{"method":{"name":"tools/call"},"protocol":{"version":"2025-06-18"},"resource":{"uri":"file:///tmp/report.md"},"session":{"id":"mcp-session"}}`,+ `"jsonrpc":{"request":{"id":"request-7"},"protocol":{"version":"2.0"}}`,+ `"network":{"protocol":{"name":"http","version":"2"},"transport":"tcp"}`,+ `"rpc":{"response":{"status_code":"OK"}}`,+ `"server":{"address":"example.com","port":443}`,+ `"error":{"type":"tool_error"}`,+ } {+ if !strings.Contains(text, want) {+ t.Fatalf("JSON missing %s: %s", want, text)+ }+ }+}+func TestTraceAndUsageCostOmittedWhenUnset(t *testing.T) {event := NewEvent(NewEventOptions{Action: "tool.invoked", Harness: HarnessInfo{Name: "cursor"}})event.GenAI = &GenAIInfo{Usage: &GenAIUsageInfo{InputTokens: int64Ptr(1)}}diff --git a/spec/threat-rules/FIELDS.md b/spec/threat-rules/FIELDS.mdindex 11b7c6cd..7656f2fb 100644--- a/spec/threat-rules/FIELDS.md+++ b/spec/threat-rules/FIELDS.md@@ -25,6 +25,7 @@ Regenerate with `beacon rules fields --markdown > spec/threat-rules/FIELDS.md`.| `e.endpoint.agent_version` | string || `e.endpoint.hostname` | string || `e.endpoint.os` | string |+| `e.error.type` | string || `e.event.action` | string || `e.event.category` | string || `e.event.kind` | string |@@ -85,6 +86,8 @@ Regenerate with `beacon rules fields --markdown > spec/threat-rules/FIELDS.md`.| `e.health.component` | string || `e.health.reason` | string || `e.health.status` | string |+| `e.jsonrpc.protocol.version` | string |+| `e.jsonrpc.request.id` | string || `e.mcp.method.name` | string || `e.mcp.protocol.version` | string || `e.mcp.resource.uri` | string |@@ -93,6 +96,9 @@ Regenerate with `beacon rules fields --markdown > spec/threat-rules/FIELDS.md`.| `e.mcp.tool` | string || `e.message` | string || `e.model` | string |+| `e.network.protocol.name` | string |+| `e.network.protocol.version` | string |+| `e.network.transport` | string || `e.origin` | string || `e.policy.decision` | string || `e.policy.enforcement` | string |@@ -102,6 +108,7 @@ Regenerate with `beacon rules fields --markdown > spec/threat-rules/FIELDS.md`.| `e.product` | string || `e.prompt.text` | string || `e.repository` | string |+| `e.rpc.response.status_code` | string || `e.run.actor` | string || `e.run.branch` | string || `e.run.commit` | string |@@ -116,6 +123,8 @@ Regenerate with `beacon rules fields --markdown > spec/threat-rules/FIELDS.md`.| `e.run.run_id` | string || `e.run.workflow` | string || `e.schema_version` | string |+| `e.server.address` | string |+| `e.server.port` | int || `e.session.id` | string || `e.session.working_directory` | string || `e.severity` | string |