Skip to content

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

fix: MCP silently drops numeric arguments sent as strings through the strict accessor (PIN-046)

Luigi Agosti46d6f551f2f7
diff --git a/internal/mcp/handlers_helpers.go b/internal/mcp/handlers_helpers.go
index 858b4890..2554098e 100644
--- a/internal/mcp/handlers_helpers.go
+++ b/internal/mcp/handlers_helpers.go
@@ -19,23 +19,26 @@ func optTrimmedString(r mcp.CallToolRequest, key string) string {
return strings.TrimSpace(optString(r, key))
}
+// Tool calls are written by language models, and a stringified number is one of
+// the commonest shapes they emit. Every numeric argument accepts both, so a
+// future one cannot pick a strict accessor by accident — there is none.
func optFloat(r mcp.CallToolRequest, key string) (float64, bool) {
- v, ok := r.GetArguments()[key].(float64)
- return v, ok
-}
-
-func optInt(r mcp.CallToolRequest, key string) (int, bool) {
- if v, ok := optFloat(r, key); ok {
- return int(v), true
+ if v, ok := r.GetArguments()[key].(float64); ok {
+ return v, true
}
if raw := optTrimmedString(r, key); raw != "" {
- if n, err := strconv.Atoi(raw); err == nil {
- return n, true
+ if v, err := strconv.ParseFloat(raw, 64); err == nil {
+ return v, true
}
}
return 0, false
}
+func optInt(r mcp.CallToolRequest, key string) (int, bool) {
+ v, ok := optFloat(r, key)
+ return int(v), ok
+}
+
func optBool(r mcp.CallToolRequest, key string) (bool, bool) {
v, ok := r.GetArguments()[key].(bool)
return v, ok
diff --git a/internal/mcp/handlers_navigation_test.go b/internal/mcp/handlers_navigation_test.go
index 58f8be96..67423296 100644
--- a/internal/mcp/handlers_navigation_test.go
+++ b/internal/mcp/handlers_navigation_test.go
@@ -550,6 +550,15 @@ func TestNumericArgumentsAcceptStringForm(t *testing.T) {
{"pinchtab_get_text", "maxChars", "3000"},
{"pinchtab_snapshot", "maxTokens", "1500"},
{"pinchtab_snapshot", "depth", "4"},
+ {"pinchtab_capture", "depth", "4"},
+ // Fractional arguments went through the other accessor, which stayed
+ // strict after the budget controls were moved off it.
+ {"pinchtab_screenshot", "scale", "0.5"},
+ {"pinchtab_screenshot", "quality", "60"},
+ {"pinchtab_capture", "scale", "0.5"},
+ {"pinchtab_capture", "quality", "60"},
+ {"pinchtab_network", "limit", "25"},
+ {"pinchtab_network", "bufferSize", "500"},
} {
t.Run(tc.tool+"/"+tc.key, func(t *testing.T) {
srv := mockPinchTab()
@@ -565,3 +574,19 @@ func TestNumericArgumentsAcceptStringForm(t *testing.T) {
})
}
}
+
+// Coordinates take a different route to a different place — resolveXY, into a
+// POST body rather than a query — so the query-based table above cannot speak
+// for them. Both must parse or hasXY goes false and the click falls back to a
+// selector that was never given.
+func TestCoordinateArgumentsAcceptStringForm(t *testing.T) {
+ srv := mockPinchTab()
+ defer srv.Close()
+
+ text := resultText(t, callTool(t, "pinchtab_click", map[string]any{"x": "10", "y": "20"}, srv))
+ for _, want := range []string{`"hasXY":true`, `"x":10`, `"y":20`} {
+ if !strings.Contains(text, want) {
+ t.Errorf("string-form coordinates: want %s in %s", want, text)
+ }
+ }
+}