High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: MCP pinchtab_fill cannot clear a field - it rejects an empty value, while the raw API documents "text": "" as the way to clear (PIN-206)
Luigi Agostid2056c7c1870
diff --git a/docs/reference/mcp-tools.md b/docs/reference/mcp-tools.mdindex 9a776867..733f8831 100644--- a/docs/reference/mcp-tools.md+++ b/docs/reference/mcp-tools.md@@ -46,7 +46,7 @@ All element-action tools accept the unified `selector` and the legacy aliases `r| `pinchtab_select` | `selector`, `ref`, `query`, `nodeId`, `value` required, `tabId`, `snap` | Select `<option>` by value or visible text; target with `selector` or `nodeId` || `pinchtab_scroll` | `selector`, `ref`, `query`, `nodeId`, `pixels`, `deltaX`, `deltaY`, `direction`, `steps`, `x`, `y`, `tabId` | Omit every target to scroll the page; element + `pixels` uses wheel semantics; `direction` accepts `up`/`down` || `pinchtab_scroll_into_view` | `selector`, `ref`, `query`, `nodeId`, `tabId` | Scrolls the target into view and returns geometry for stable follow-up actions; target with `selector` or `nodeId` |-| `pinchtab_fill` | `selector`, `ref`, `query`, `nodeId`, `value` required, `tabId`, `snap` | Direct fill via JS dispatch instead of keystrokes; target with `selector` or `nodeId` |+| `pinchtab_fill` | `selector`, `ref`, `query`, `nodeId`, `value` required, `tabId`, `snap` | Direct fill via JS dispatch instead of keystrokes; target with `selector` or `nodeId`. An empty `value` clears the field; omitting it entirely is refused |## Keyboarddiff --git a/internal/mcp/handlers_helpers.go b/internal/mcp/handlers_helpers.goindex 9863d672..35775b11 100644--- a/internal/mcp/handlers_helpers.go+++ b/internal/mcp/handlers_helpers.go@@ -64,6 +64,32 @@ func firstNonEmptyString(r mcp.CallToolRequest, keys ...string) string {return ""}+// firstSuppliedString answers "was this argument sent", for the one argument whose+// empty string MEANS something: a fill clears the field. That is the same question+// the bridge asks — ActionRequest.HasText is inferred from key presence over the same+// text/value pair — and it is the question firstNonEmptyString cannot answer, since+// collapsing empty and absent is its entire job.+//+// The value travels verbatim rather than trimmed, so MCP fill and POST /action fill+// agree on every input and not merely on the clear case.+//+// Every other caller keeps the collapsing helper deliberately: typing nothing is+// meaningless, and for select and the dialog arguments the BRIDGE itself collapses+// empty with absent (actionSelect refuses an empty value; DialogText is a plain+// string with no presence flag), so reading presence here would promise a+// distinction the request cannot carry.+func firstSuppliedString(r mcp.CallToolRequest, keys ...string) (string, bool) {+ args := r.GetArguments()+ for _, key := range keys {+ if raw, ok := args[key]; ok {+ if v, isString := raw.(string); isString {+ return v, true+ }+ }+ }+ return "", false+}+func looksLikeStructuredSelector(v string) bool {v = strings.TrimSpace(v)if v == "" {diff --git a/internal/mcp/handlers_interaction.go b/internal/mcp/handlers_interaction.goindex 97579c57..a7861a06 100644--- a/internal/mcp/handlers_interaction.go+++ b/internal/mcp/handlers_interaction.go@@ -188,9 +188,13 @@ func handleAction(c *Client, kind string) func(context.Context, mcp.CallToolRequif _, err := resolveSelector(!hasNodeID); err != nil {return mcp.NewToolResultError(err.Error()), nil}- value := firstNonEmptyString(r, "value", "text")- if value == "" {- return mcp.NewToolResultError("required parameter 'value' is missing"), nil+ // Presence, not emptiness: an empty value is how a caller clears a field,+ // so refusing it made the one documented clear idiom inexpressible here+ // while the raw API accepted it — and the old message claimed a parameter+ // the caller had supplied was missing.+ value, supplied := firstSuppliedString(r, "value", "text")+ if !supplied {+ return mcp.NewToolResultError("fill needs a 'value' argument; send \"\" to clear the field"), nil}// "text" is the field actionFill reads. Posting the same string under "value"// reached a real ActionRequest field that fill ignores, so the write was emptydiff --git a/internal/mcp/handlers_interaction_test.go b/internal/mcp/handlers_interaction_test.goindex 8738f0e2..6292f94a 100644--- a/internal/mcp/handlers_interaction_test.go+++ b/internal/mcp/handlers_interaction_test.go@@ -518,3 +518,57 @@ func TestHandleFillAcceptsTheTextSpellingToo(t *testing.T) {t.Fatalf("forwarded text = %q, want FROM_TEXT; payload was %v", got, body)}}++// The pair is the assertion. Supplied-empty must clear and absent must still refuse —+// either half alone is satisfiable by deleting the check, which would silently forward a+// fill with no text at all. Driven through the tool surface, because the bridge action+// was always able to express both and the MCP layer was the only one that could not.+func TestFillClearsOnASuppliedEmptyValueAndStillRefusesAnAbsentOne(t *testing.T) {+ srv := mockPinchTab()+ defer srv.Close()++ for _, key := range []string{"value", "text"} {+ t.Run("supplied empty "+key+" clears", func(t *testing.T) {+ r := callTool(t, "pinchtab_fill", map[string]any{"ref": "e0", key: ""}, srv)+ if r.IsError {+ t.Fatalf("a supplied empty %s was refused: %s", key, resultText(t, r))+ }+ body, _ := resultJSON(t, r)["body"].(map[string]any)+ text, present := body["text"]+ if !present {+ t.Fatalf("payload carries no text key, so the bridge cannot tell a clear from a request whose text never arrived: %v", body)+ }+ if got, _ := text.(string); got != "" {+ t.Errorf("forwarded text = %q, want the empty string that clears the field", got)+ }+ })+ }++ t.Run("absent value is refused", func(t *testing.T) {+ r := callTool(t, "pinchtab_fill", map[string]any{"ref": "e0"}, srv)+ if !r.IsError {+ body, _ := resultJSON(t, r)["body"].(map[string]any)+ t.Fatalf("a fill with no value at all was forwarded as %v; absent is not a clear", body)+ }+ message := resultText(t, r)+ if strings.Contains(message, "is missing") && strings.Contains(message, "'value'") {+ t.Errorf("refusal %q reads as a supplied parameter being missing; it must say what fill needs and how to clear", message)+ }+ if !strings.Contains(message, "clear") {+ t.Errorf("refusal %q does not tell the caller how to clear a field, which is the case it is most likely to be confused with", message)+ }+ })+}++// Whitespace is content, not a clear: the raw API fills it verbatim, so the tool must not+// trim a supplied value into the clear idiom.+func TestFillForwardsASuppliedValueVerbatim(t *testing.T) {+ srv := mockPinchTab()+ defer srv.Close()++ r := callTool(t, "pinchtab_fill", map[string]any{"ref": "e0", "value": " spaced "}, srv)+ body, _ := resultJSON(t, r)["body"].(map[string]any)+ if got, _ := body["text"].(string); got != " spaced " {+ t.Errorf("forwarded text = %q, want the caller's string unmodified", got)+ }+}diff --git a/internal/mcp/tools.go b/internal/mcp/tools.goindex c91570d4..c76fe694 100644--- a/internal/mcp/tools.go+++ b/internal/mcp/tools.go@@ -200,7 +200,7 @@ func allTools() []mcp.Tool {mcp.WithString("selector", mcp.Description("Unified selector: ref (e.g. 'e5'), CSS, XPath, text, or semantic. Non-ref selectors resolve in the current frame scope.")),mcp.WithString("ref", mcp.Description("(deprecated) Element ref — use 'selector' instead")),mcp.WithString("query", mcp.Description("Alias for semantic targeting when selector is omitted")),- mcp.WithString("value", mcp.Required(), mcp.Description("Value to fill")),+ mcp.WithString("value", mcp.Required(), mcp.Description("Value to fill; send an empty string to clear the field")),mcp.WithNumber("nodeId", mcp.Description("Optional backend node ID to target directly")),mcp.WithString("tabId", mcp.Description("Target tab ID")),mcp.WithBoolean("snap", mcp.Description("Return interactive compact snapshot after fill (saves a round-trip)")),diff --git a/skills/pinchtab/references/mcp.md b/skills/pinchtab/references/mcp.mdindex eea67053..534e076a 100644--- a/skills/pinchtab/references/mcp.md+++ b/skills/pinchtab/references/mcp.md@@ -62,7 +62,7 @@ All tool names are prefixed with `pinchtab_`.|------|-------------|| `pinchtab_click` | Click element by selector. Required: `selector` or legacy `ref`. Optional: `waitNav`, `mode` (`dom` or `dispatch` as a broad low-level escape hatch), `tabId`. `mode` and `humanize` are mutually exclusive. || `pinchtab_type` | Type text keystroke-by-keystroke. Required: `selector` or legacy `ref`, plus `text`. Optional: `tabId`. |-| `pinchtab_fill` | Fill input via JS dispatch. Required: `selector` or legacy `ref`, plus `value`. Optional: `tabId`. |+| `pinchtab_fill` | Fill input via JS dispatch. Required: `selector` or legacy `ref`, plus `value` — send `value=""` to clear the field (omitting it is refused). Optional: `tabId`. || `pinchtab_press` | Press a named key (`Enter`, `Tab`, `Escape`, etc.). Required: `key`. Optional: `tabId`. || `pinchtab_hover` | Hover over element. Required: `selector` or legacy `ref`. Optional: `tabId`. || `pinchtab_focus` | Focus an element. Required: `selector` or legacy `ref`. Optional: `tabId`. |