Commit 83bda7c
committed
fix(sensor): attribute MCP servers and failed tool calls in Claude Code sessions
The Claude Code parser hardcoded `tool_type="tool_use"` for every tool call, never
populated `server_name`, and dropped the `is_error` flag from tool results. On a real
corpus of 1,814 sessions / 90,626 tool calls this meant:
- every call landed in a single `tool_use` bucket, so terminal commands were
indistinguishable from MCP calls;
- no MCP server attribution at all, even though Claude Code namespaces MCP tools as
`mcp__<server>__<tool>` and the server is recoverable from the name;
- zero errors reported across all 90,626 calls, because `is_error` was never read.
After the fix, the same corpus yields `terminal_command` 48,008 / `tool_use` 24,617 /
`mcp_tool` 18,001, 15 distinct MCP servers, and 5,327 failed calls (5.9%). Failed and
blocked tool calls matter for detection, so losing them silently is a meaningful gap.
This mirrors what `opencode_parser._classify_tool()` already does for opencode; the
Claude Code parser had simply not received the same treatment. Also preserves
`server_name` across the tool_use -> tool_result merge, which previously dropped it.
Adds three tests: tool classification, server attribution surviving the result merge,
and `is_error` producing `status="error"`.1 parent d0e62f9 commit 83bda7c
2 files changed
Lines changed: 138 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
70 | 88 | | |
71 | 89 | | |
72 | 90 | | |
| |||
186 | 204 | | |
187 | 205 | | |
188 | 206 | | |
189 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
190 | 214 | | |
191 | 215 | | |
192 | 216 | | |
| |||
245 | 269 | | |
246 | 270 | | |
247 | 271 | | |
| 272 | + | |
248 | 273 | | |
249 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
250 | 281 | | |
251 | 282 | | |
252 | 283 | | |
| 284 | + | |
253 | 285 | | |
254 | 286 | | |
255 | | - | |
| 287 | + | |
| 288 | + | |
256 | 289 | | |
257 | 290 | | |
258 | 291 | | |
| |||
274 | 307 | | |
275 | 308 | | |
276 | 309 | | |
| 310 | + | |
| 311 | + | |
277 | 312 | | |
278 | | - | |
279 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
280 | 316 | | |
281 | 317 | | |
282 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
79 | 177 | | |
80 | 178 | | |
81 | 179 | | |
| |||
0 commit comments