Skip to content

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

fix: MCP silently drops maxChars, maxTokens and depth when a client sends them as strings (PIN-046)

Luigi Agosti5fc28ba1190a
diff --git a/internal/mcp/handlers_helpers.go b/internal/mcp/handlers_helpers.go
index 4d79cd5b..858b4890 100644
--- a/internal/mcp/handlers_helpers.go
+++ b/internal/mcp/handlers_helpers.go
@@ -41,15 +41,6 @@ func optBool(r mcp.CallToolRequest, key string) (bool, bool) {
return v, ok
}
-func optNumber(r mcp.CallToolRequest, key string) float64 {
- v, _ := r.GetArguments()[key].(float64)
- return v
-}
-
-func formatInt(v float64) string {
- return fmt.Sprintf("%d", int(v))
-}
-
func firstNonEmptyString(r mcp.CallToolRequest, keys ...string) string {
for _, key := range keys {
if v := optTrimmedString(r, key); v != "" {
diff --git a/internal/mcp/handlers_navigation.go b/internal/mcp/handlers_navigation.go
index 86ff7459..641733f3 100644
--- a/internal/mcp/handlers_navigation.go
+++ b/internal/mcp/handlers_navigation.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/url"
+ "strconv"
"strings"
"github.com/mark3labs/mcp-go/mcp"
@@ -90,11 +91,11 @@ func handleSnapshot(c *Client) func(context.Context, mcp.CallToolRequest) (*mcp.
if sel := optString(r, "selector"); sel != "" {
q.Set("selector", sel)
}
- if v := optNumber(r, "maxTokens"); v > 0 {
- q.Set("maxTokens", formatInt(v))
+ if v, ok := optInt(r, "maxTokens"); ok && v > 0 {
+ q.Set("maxTokens", strconv.Itoa(v))
}
- if v := optNumber(r, "depth"); v > 0 {
- q.Set("depth", formatInt(v))
+ if v, ok := optInt(r, "depth"); ok && v > 0 {
+ q.Set("depth", strconv.Itoa(v))
}
if v, ok := optBool(r, "noAnimations"); ok && v {
q.Set("noAnimations", "true")
@@ -269,8 +270,8 @@ func handleCapture(c *Client) func(context.Context, mcp.CallToolRequest) (*mcp.C
if scale, ok := optFloat(r, "scale"); ok && scale > 0 {
q.Set("scale", fmt.Sprintf("%g", scale))
}
- if v := optNumber(r, "depth"); v > 0 {
- q.Set("depth", formatInt(v))
+ if v, ok := optInt(r, "depth"); ok && v > 0 {
+ q.Set("depth", strconv.Itoa(v))
}
if v, ok := optBool(r, "beyondViewport"); ok && v {
q.Set("beyondViewport", "true")
@@ -375,8 +376,8 @@ func handleGetText(c *Client) func(context.Context, mcp.CallToolRequest) (*mcp.C
if format := optString(r, "format"); format != "" {
q.Set("format", format)
}
- if v := optNumber(r, "maxChars"); v > 0 {
- q.Set("maxChars", formatInt(v))
+ if v, ok := optInt(r, "maxChars"); ok && v > 0 {
+ q.Set("maxChars", strconv.Itoa(v))
}
if browser := optString(r, "browser"); browser != "" {
q.Set("browser", browser)
diff --git a/internal/mcp/handlers_navigation_test.go b/internal/mcp/handlers_navigation_test.go
index f2b7ab5f..58f8be96 100644
--- a/internal/mcp/handlers_navigation_test.go
+++ b/internal/mcp/handlers_navigation_test.go
@@ -536,3 +536,32 @@ func TestHandleCaptureForwardsBrowser(t *testing.T) {
t.Fatalf("capture browser = %q, want cloak; query=%v", got, captureQuery)
}
}
+
+// MCP clients and LLM-generated tool calls routinely stringify numbers. Every
+// other numeric argument accepts that through optInt; the response-budget
+// arguments must too, or the cap is silently dropped and the caller gets a full
+// page instead of an error.
+func TestNumericArgumentsAcceptStringForm(t *testing.T) {
+ for _, tc := range []struct {
+ tool string
+ key string
+ value string
+ }{
+ {"pinchtab_get_text", "maxChars", "3000"},
+ {"pinchtab_snapshot", "maxTokens", "1500"},
+ {"pinchtab_snapshot", "depth", "4"},
+ } {
+ t.Run(tc.tool+"/"+tc.key, func(t *testing.T) {
+ srv := mockPinchTab()
+ defer srv.Close()
+
+ text := resultText(t, callTool(t, tc.tool, map[string]any{tc.key: tc.value}, srv))
+ if !strings.Contains(text, `"`+tc.key+`"`) {
+ t.Errorf("%s=%q was dropped from the query: %s", tc.key, tc.value, text)
+ }
+ if !strings.Contains(text, tc.value) {
+ t.Errorf("%s=%q did not reach the query: %s", tc.key, tc.value, text)
+ }
+ })
+ }
+}