Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: MCP fill reports a wrong-typed value as a missing argument, so a model that sends value: 2024 is told to send the value it just sent (PIN-242)

Luigi Agosti9a0c5557ef92
diff --git a/internal/mcp/handlers_helpers.go b/internal/mcp/handlers_helpers.go
index 35775b11..a9ac4317 100644
--- a/internal/mcp/handlers_helpers.go
+++ b/internal/mcp/handlers_helpers.go
@@ -78,16 +78,43 @@ func firstNonEmptyString(r mcp.CallToolRequest, keys ...string) string {
// 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) {
+// wrongType names the JSON type of a value that WAS supplied under one of the keys but is
+// not a string. The library does not enforce the declared type before calling a handler, so
+// a model answering a numeric-looking field with 2024 rather than "2024" arrives here — and
+// collapsing that into "not supplied" reproduces the very complaint this helper was written
+// for: telling a caller an argument it sent is missing.
+func firstSuppliedString(r mcp.CallToolRequest, keys ...string) (value string, supplied bool, wrongType string) {
args := r.GetArguments()
for _, key := range keys {
- if raw, ok := args[key]; ok {
- if v, isString := raw.(string); isString {
- return v, true
- }
+ raw, ok := args[key]
+ if !ok {
+ continue
+ }
+ if v, isString := raw.(string); isString {
+ return v, true, ""
+ }
+ if wrongType == "" {
+ wrongType = jsonTypeName(raw)
}
}
- return "", false
+ return "", false, wrongType
+}
+
+func jsonTypeName(v any) string {
+ switch v.(type) {
+ case nil:
+ return "null"
+ case bool:
+ return "boolean"
+ case float64, int, int64:
+ return "number"
+ case []any:
+ return "array"
+ case map[string]any:
+ return "object"
+ default:
+ return fmt.Sprintf("%T", v)
+ }
}
func looksLikeStructuredSelector(v string) bool {
diff --git a/internal/mcp/handlers_interaction.go b/internal/mcp/handlers_interaction.go
index a7861a06..3f0dba07 100644
--- a/internal/mcp/handlers_interaction.go
+++ b/internal/mcp/handlers_interaction.go
@@ -192,8 +192,11 @@ func handleAction(c *Client, kind string) func(context.Context, mcp.CallToolRequ
// 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")
+ value, supplied, wrongType := firstSuppliedString(r, "value", "text")
if !supplied {
+ if wrongType != "" {
+ return mcp.NewToolResultError(fmt.Sprintf("fill's 'value' must be a string, got %s; quote it, or send \"\" to clear the field", wrongType)), nil
+ }
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"
diff --git a/internal/mcp/handlers_interaction_test.go b/internal/mcp/handlers_interaction_test.go
index 6292f94a..7bae994c 100644
--- a/internal/mcp/handlers_interaction_test.go
+++ b/internal/mcp/handlers_interaction_test.go
@@ -1,6 +1,9 @@
package mcp
import (
+ "io"
+ "net/http"
+ "net/http/httptest"
"strings"
"testing"
)
@@ -572,3 +575,60 @@ func TestFillForwardsASuppliedValueVerbatim(t *testing.T) {
t.Errorf("forwarded text = %q, want the caller's string unmodified", got)
}
}
+
+// The library does not enforce a declared argument type before calling a handler, so a model
+// answering a numeric-looking field with 2024 rather than "2024" reaches fill with a number.
+// Reporting that as a MISSING argument is the same dead end this tool was fixed to remove:
+// the caller sent the argument, is told it did not, sends it the same way again.
+func TestFillNamesAWrongTypedValueInsteadOfCallingItMissing(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ args map[string]any
+ wantSays string
+ }{
+ {name: "a number", args: map[string]any{"selector": "e5", "value": float64(2024)}, wantSays: "must be a string, got number"},
+ {name: "a boolean", args: map[string]any{"selector": "e5", "value": true}, wantSays: "must be a string, got boolean"},
+ {name: "an object", args: map[string]any{"selector": "e5", "value": map[string]any{"a": 1}}, wantSays: "must be a string, got object"},
+ {name: "genuinely absent", args: map[string]any{"selector": "e5"}, wantSays: "needs a 'value' argument"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ t.Error("fill posted a request for an unusable value instead of refusing it")
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{}`))
+ }))
+ defer srv.Close()
+
+ res := callTool(t, "pinchtab_fill", tc.args, srv)
+
+ if !res.IsError {
+ t.Fatalf("accepted %v", tc.args)
+ }
+ if text := resultText(t, res); !strings.Contains(text, tc.wantSays) {
+ t.Errorf("error = %q, want it to say %q so the caller knows what to change", text, tc.wantSays)
+ }
+ })
+ }
+}
+
+// The clear idiom must keep working, since distinguishing a wrong type from an absent one
+// must not re-refuse the empty string this tool was fixed to accept.
+func TestFillStillSendsAnEmptyStringVerbatim(t *testing.T) {
+ var body string
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ raw, _ := io.ReadAll(r.Body)
+ body = string(raw)
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"ok":true}`))
+ }))
+ defer srv.Close()
+
+ res := callTool(t, "pinchtab_fill", map[string]any{"selector": "e5", "value": ""}, srv)
+
+ if res.IsError {
+ t.Fatalf("an empty value was refused: %s", resultText(t, res))
+ }
+ if !strings.Contains(body, `"text":""`) {
+ t.Errorf("posted %s, want text:\"\" — the documented way to clear a field", body)
+ }
+}