fix(mcp-agent): correct modifier key-combo normalization (Error Input Format) + cap UI-tree recursion depth#477
Open
DieBurgerSouce wants to merge 2 commits into
Conversation
…yntax
press_key / press_key_global rejected every modifier combo. normalize_key
wrapped the whole string in braces, turning "Ctrl+Z" into "{Ctrl+Z}" — a single
unknown token the uiautomation backend rejects with E_INVALIDARG ("Error Input
Format"). The documented examples ("{Ctrl}{V}") were also wrong: a single letter
inside braces ("{V}") is not a valid named key.
Parse "+"-separated combos instead: modifiers -> {Ctrl}/{Alt}/{Shift}/{Win};
a final single character -> literal held under the modifier (e.g. "{Ctrl}z");
a final named key -> braced (e.g. "{Alt}{F4}"). Already-braced raw syntax and
lone characters pass through unchanged. Mirrors the existing, tested
translate_gemini_keys converter. Adds unit tests and corrects the misleading
schema docstrings for both tools.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
build_node_from_cached_element recurses unbounded when the caller passes no tree_max_depth. Deeply nested windows can overflow the native stack — Windows kills the process with 0xC00000FD, which the npm wrapper detects and restarts. Add cap_tree_depth() / SAFE_MAX_TREE_DEPTH (50) and apply it in build_tree_with_cache so the cached tree walk is always bounded. Adds a unit test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Two independent fixes for the Windows MCP agent:
press_key/press_key_global.1. Key-combo normalization (
crates/terminator-mcp-agent/src/helpers.rs)normalize_keywrapped the entire key string in braces when it didn't alreadycontain
{, so the documented"Ctrl+Z"became"{Ctrl+Z}"— a single unknowntoken that the
uiautomationbackend rejects:Every modifier combo (
Ctrl+Z,Ctrl+A,Alt+F4, …) failed. The schemadocstrings also recommended a broken form (
"{Ctrl}{V}"): a single letterinside braces (
{V}) is not a valid named key.Fix: parse
+-separated combos into validuiautomationsyntax —modifiers →
{Ctrl}/{Alt}/{Shift}/{Win}; a final single character → aliteral char held under the modifier (
"{Ctrl}z"); a final named key → braced(
"{Alt}{F4}"). Already-braced raw syntax and lone characters pass throughunchanged. This matches the behaviour of the existing, tested
translate_gemini_keysconverter interminator-computer-use.Also corrects the misleading
keydocstrings forPressKeyArgs/GlobalKeyArgs(src/utils.rs).Ctrl+Z{Ctrl+Z}❌{Ctrl}z✅Ctrl+Shift+S{Ctrl+Shift+S}❌{Ctrl}{Shift}s✅Alt+F4{Alt+F4}❌{Alt}{F4}✅2. UI-tree depth cap (
crates/terminator/src/platforms/windows/tree_builder.rs)build_node_from_cached_elementrecurses unbounded when the caller passes notree_max_depth. Deeply-nested windows overflow the native stack — Windowsterminates the process with
0xC00000FD(the exit code the npm wrapper alreadyspecial-cases and restarts on). Add
cap_tree_depth()/SAFE_MAX_TREE_DEPTH(50) and apply it in
build_tree_with_cacheso the cached walk is alwaysbounded, even with no explicit depth.
Testing
normalize_key(combos, single keys, passthrough) andcap_tree_depth. Verified red→green (breaking the fix fails the test).cargo test -p terminator-mcp-agent --lib/-p terminator-rs --libpass.press_key_globalwithCtrl+N/Ctrl+A/Ctrl+Wnow returnexecuted_without_error(
key_pressed: "{Ctrl}n"etc.) where the previous build returnedError Input Format.🤖 Generated with Claude Code