Repository navigation
feat(guards): inspect MCP tool invocations and record refusal telemetry - #3
Open
Pipe5linger wants to merge 3 commits into
Open
Pipe5linger wants to merge 3 commits into
Pipe5linger wants to merge 3 commits into
Conversation
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.
Motivation & Summary
Closes #2.
This PR addresses the two gaps identified in #2 when running agentic workflows with Claude Code:
mcp__*, context-mode'sctx_execute, custom shell execution tools) previously evadedPreToolUseinspection because the matcher and parser were hardcoded solely toBash,Edit, andWrite.~/.local/state/agentry/events.jsonl), making it impossible to differentiate an agent that was stopped from one that never attempted the action.What's Changed
PreToolUse Hook Matcher (
hooks/hooks.json):PreToolUsematcher pattern to includemcp__.*:"matcher": "Bash|Edit|Write|Agent|mcp__.*".MCP Command Extraction (
core/guard_engine.py):_extract_command_and_target(tool_name, tool_input)to extract commands or script bodies from MCP tools and custom executors matchingcommand,cmd,script,query,eval, orcode.file_path).Bash.Refusal Telemetry Logging (
core/guard_engine.py):_log_refusal(): when a tool call is blocked, writes an append-only refusal record to~/.local/state/agentry/events.jsonlwith:event:"guard"tool: tool name (e.g.,Bash,mcp__...)refused_input: the attempted command/pathrule: matching guard patternreason: refusal messagebuild_id&task: parsed from theAGENT_P_TAGSenvironment variable (e.g.,build_id=xyz,task=abc).Dedicated Test Suite (
tests/test_mcp_guards.py):mcp__context_mode__ctx_execute) are caught by step guards.cmd,script) are inspected.~/.local/state/agentry/events.jsonlwith tags parsed fromAGENT_P_TAGS.Verification
$ pytest tests/test_mcp_guards.py -v ============================== 3 passed in 0.25s ==============================All existing unit tests in
tests/test_guard_engine.pycontinue to pass without regression.