Repository navigation
Conversation
vschs007
force-pushed
the
fix/claude-parser-mcp-attribution
branch
from
November 1, 2026 04:14
0edda36 to
885ed06
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Related issue: Supersedes and closes #38 (incorporating review feedback from @pengyuzhang)
What changed?
Tool Classification & MCP Attribution:
_classify_tool()toClaudeParser:Bashshell executions astool_type="terminal_command".mcp__<server>__<tool>invocations, classifying them astool_type="mcp_tool"and populatingserver_name="<server>".Read,Edit,Glob,Grep,View) totool_type="tool_use".isinstance(tool_name, str)safety guard and defaults present-but-null names ("name": null) to"unknown", preventing session drop crashes._classify_toolinto assistant tool extraction so initialToolUsageobjects carry bothtool_typeandserver_name.Accurate Error & Completion Status Tracking:
is_erroracross bothtool_resultcontent blocks (item.get("is_error")) and top-leveltoolUseResultmetadata objects (tur.get("is_error")/tur.get("status") == "error").toolUseResult["error"]if content is empty.status = "error" if is_error else "success". Because atool_resultis an authoritative completion signal, successful tools returning empty strings (e.g.ToolSearchwith 0 matches) are correctly recorded asstatus="success"rather than ambiguous"unknown".tool_typeandserver_nameduring thereplace(old_tool, ...)result merge.Documentation:
Sensor/README.mdto document tool classification, MCP attribution, and error retention under the Claude Code section.Unit Tests:
Sensor/tests/test_claude_parser.py:Bash,mcp__*, built-ins, and malformed prefixes.server_nameandtool_typesurviving user turn result merge.is_error: True) settingstatus="error"and populatingerror.toolUseResultenvelope error fallback.status="success"."name": null) safely defaulting to"unknown"without discarding sessions.Why?
PR #38 originally proposed MCP attribution and
is_errorhandling for Claude Code, and review verified the premise against real corpora (is_errorliving ontool_resultblocks; ~18k MCP calls needing attribution). However, PR #38 was abandoned and blocked by CLA before addressing review comments:_classify_toolcrashed withAttributeErroron"name": null, discarding whole sessions.status="unknown".While the post-#130 telemetry refactor (
abc12c2) solved identity indexing withpending_tools[tool_use_id] = (msg_idx, tool_idx), the tool classification andis_errorhandling were never carried intomain. Currently:tool_typeis hardcoded to"tool_use"for all tools, obscuring arbitrary shell commands.server_nameis alwaysNone, breaking MCP policy governance in downstream detectors.status="success".This PR brings the verified improvements to
mainwhile addressing all review items from #38.How did you test it?
ruff check Sensor/adr_sensor/parsers/claude_parser.py Sensor/tests/test_claude_parser.py # All checks passed!