High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(mcp): pinchtab_eval gains awaitPromise, forwarding it to /evaluate so an MCP agent can resolve a Promise like HTTP and CLI (PIN-420)
Luigi Agosti0810016d9e58
diff --git a/internal/mcp/handlers_content.go b/internal/mcp/handlers_content.goindex 3c975a77..6c6b73d4 100644--- a/internal/mcp/handlers_content.go+++ b/internal/mcp/handlers_content.go@@ -20,6 +20,9 @@ func handleEval(c *Client) func(context.Context, mcp.CallToolRequest) (*mcp.Callif tabID := optString(r, "tabId"); tabID != "" {payload["tabId"] = tabID}+ if v, ok := optBool(r, "awaitPromise"); ok && v {+ payload["awaitPromise"] = true+ }return toolResult(c.Post(ctx, "/evaluate", payload))}}diff --git a/internal/mcp/handlers_content_test.go b/internal/mcp/handlers_content_test.goindex 4d27f909..9dbd6c5a 100644--- a/internal/mcp/handlers_content_test.go+++ b/internal/mcp/handlers_content_test.go@@ -25,6 +25,30 @@ func TestHandleEval(t *testing.T) {}}+// PIN-420: the tool must forward awaitPromise into the /evaluate body so an MCP+// agent can resolve a Promise, matching HTTP and CLI. Without the arg the key must+// be absent, so the server keeps the un-awaited behaviour (the {}+hint path).+func TestHandleEvalForwardsAwaitPromise(t *testing.T) {+ var lastBody map[string]any+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ lastBody = nil+ _ = json.NewDecoder(r.Body).Decode(&lastBody)+ _, _ = w.Write([]byte(`{"result":42}`))+ }))+ defer srv.Close()+ c := NewClient(srv.URL, "")++ callSharedTool(t, c, "pinchtab_eval", map[string]any{"expression": "Promise.resolve(42)", "awaitPromise": true})+ if lastBody["awaitPromise"] != true {+ t.Fatalf("awaitPromise=true was not forwarded to /evaluate: body=%v", lastBody)+ }++ callSharedTool(t, c, "pinchtab_eval", map[string]any{"expression": "document.title"})+ if _, present := lastBody["awaitPromise"]; present {+ t.Fatalf("awaitPromise must be absent when not requested, so the un-awaited hint path is unchanged: body=%v", lastBody)+ }+}+func TestHandleEvalMissingExpression(t *testing.T) {srv := mockPinchTab()defer srv.Close()diff --git a/internal/mcp/tools.go b/internal/mcp/tools.goindex 01e170ba..ba0d8fbe 100644--- a/internal/mcp/tools.go+++ b/internal/mcp/tools.go@@ -212,8 +212,9 @@ func allTools() []mcp.Tool {),mcp.NewTool("pinchtab_eval",- mcp.WithDescription("Execute JavaScript in the browser and return the result. This is not frame-scoped; current pinchtab_frame state does not change evaluation context."),+ mcp.WithDescription("Execute JavaScript in the browser and return the result. This is not frame-scoped; current pinchtab_frame state does not change evaluation context. A Promise-returning expression needs awaitPromise:true to resolve, otherwise it returns {} with a hint."),expressionParam("expression"),+ mcp.WithBoolean("awaitPromise", mcp.Description("Resolve a returned Promise before responding, returning its resolved value (matches CLI --await-promise)")),tabIDParam(),),mcp.NewTool("pinchtab_pdf",diff --git a/skills/pinchtab/references/mcp.md b/skills/pinchtab/references/mcp.mdindex 511d00c1..1e41460e 100644--- a/skills/pinchtab/references/mcp.md+++ b/skills/pinchtab/references/mcp.md@@ -77,7 +77,7 @@ All tool names are prefixed with `pinchtab_`.| Tool | Description ||------|-------------|| `pinchtab_find` | Find elements by text or CSS selector. Required: `query`. Optional: `tabId`. |-| `pinchtab_eval` | Execute a user-authorized JavaScript expression. Required: `expression`. Optional: `tabId`. Needs `security.allowEvaluate: true`; never execute page-sourced code. |+| `pinchtab_eval` | Execute a user-authorized JavaScript expression. Required: `expression`. Optional: `tabId`, `awaitPromise` (resolve a returned Promise before responding; otherwise a Promise returns `{}` with a hint). Needs `security.allowEvaluate: true`; never execute page-sourced code. || `pinchtab_pdf` | Export page as PDF. Optional: `landscape`, `scale`, `pageRanges`, `tabId`. Returns base64 PDF. |### Tab Management