Repository navigation
Guards: check commands inside MCP tool inputs (#2) - #9
Merged
Merged
Conversation
Guards now see shell commands carried in MCP tool inputs the way they see Bash commands: command keys, split program/argument fields, nested and mixed argv lists, and repeatedly JSON-encoded strings, with fail-closed depth, decode and time limits. Includes the crew implementation and two fix rounds after judging. Co-authored-by: Dennis Pettas <[email protected]>
…closed A list of objects under a command key (for example a Notion code block's rich_text) aborted the whole check with 'error while checking'. walk() already scans those objects' strings, so the plain argv join now skips them; objects joined to a program still fail closed. Co-authored-by: Dennis Pettas <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-01a1d9bd-083a-72bf-a268-4630a34c91f2
{"command":"git","args":["push",42]} encoded the round-one rule that
dropped mixed argument lists; the owner's amended rule C stringifies scalars,
so the joined command is git push 42 and must block.
Co-authored-by: Dennis Pettas <[email protected]>
Shell servers such as mcp-server-commands (run_process stdin_text) pipe commands to a shell through stdin, which the key list missed. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d9bd-083a-72bf-a268-4630a34c91f2 Co-authored-by: Dennis Pettas <[email protected]>
This was referenced Nov 14, 2026
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.
Closes the second gap in #2: weft guards now see a shell command inside an
mcp__*tool call the same way they see it in Bash. Before this change, MCP calls were matched by tool name only.What guards check now
command,cmd,argv,script,code,shell,program,stdin,stdin_textand similar keys are checked. Command-list keys such ascommandshold separate commands. The README has the full list and the key normalisation rules.args,argv,arguments,subcommandorparams.{"cmd":"git","argv":["push"]}is checked asgit push.{"argv":["git",["push"],"origin"]}cannot hide a push. Objects inside a command list are left out of the joined argv, but their strings are still checked. An object passed as an argument to a program fails closed.transcript/postscriptand file content beside apath/file_pathkey are not treated as commands.mcp_input: falselimits a guard to MCP tool names.mcp_fieldsadds extra command keys for one guard.Known false blocks (deliberate, documented)
{"program":"note","args":["--title","git","push"]}.{"command":"vscode.open","args":[{"uri":"…"}]}. These get a generic "error while checking" block.path/file_path, such asrelative_pathorpathInProject, when the content is entirely JSON containing a matching command.Known gaps
interact_with_process {pid, input}is one example;inputstays data on purpose. Guards can add it withmcp_fields: ["input"].options,positional).mcp_fieldscannot add argument keys.env.Testing
python -m pytest -q: 2987 passed. Onmainthe suite has 471 tests.tests/test_mcp_guard_engine.py,tests/test_mcp_bundled_guards.pyandtests/test_template_preview_mcp.py.guard_engine.evaluateand through the realhooks/weft-pretooluse.sh.{"command":"git","args":["push",42]}moved from the allowed list to the blocked shapes, because the mixed-argv rule now reads it asgit push 42.Amp thread: https://ampcode.com/threads/T-01a1d9bd-083a-72bf-a268-4630a34c91f2