Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Bound rejected WebMCP registration retries and explain DOM recovery

Barack Sokullue89b62f6fb9b
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index a1fad1f37..3f18a61db 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -10664,7 +10664,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
success: false,
denied: true,
noDispatch: true,
- error: 'execute_webmcp_tool requires a tool_id from list_webmcp_tools.',
+ error: 'execute_webmcp_tool requires an exact opaque tool_id returned by list_webmcp_tools. Browser functions and JavaScript are not WebMCP tool IDs.',
+ hint: 'If the page has no registered WebMCP tools, use ordinary accessibility, DOM, or execute_js tools instead.',
},
};
}
@@ -10689,10 +10690,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
denied: true,
noDispatch: true,
staleToolId: true,
- error: 'This WebMCP tool ID is no longer registered. Call list_webmcp_tools again.',
+ error: 'This WebMCP tool ID is not registered. Call list_webmcp_tools once and use only an exact returned tool_id; never invent an ID.',
+ hint: 'If the catalog is empty, use ordinary accessibility, DOM, or execute_js tools instead.',
},
};
}
+ // Resolving a real registration repairs this failure class; unrelated
+ // failed browser actions keep their own counters.
+ this.failedActionLoops.get(tabId)?.delete('webmcp-tool-registration');
const preparedArgs = {
...args,
tool_id: toolId,
@@ -12262,12 +12267,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
? { args: fnArgs }
: await this._prepareWebMCPToolCall(tabId, fnName, fnArgs);
if (webMcpPreparation.error) {
- messages.push({
- role: 'tool',
- tool_call_id: tc.id,
- content: JSON.stringify(webMcpPreparation.error),
- });
- onUpdate('warning', { message: webMcpPreparation.error.error });
+ const result = {
+ ...webMcpPreparation.error,
+ dispatched: false,
+ failureScope: 'webmcp-tool-registration',
+ };
+ const recovery = await recordPreparationFailure(toolIndex, fnName, fnArgs, result, result.error);
+ if (recovery) return recovery;
+ if (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }
continue;
}
fnArgs = webMcpPreparation.args;
@@ -34152,7 +34159,10 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
};
}
try {
- return await cdpClient.listWebMCPTools(tabId, args || {});
+ const catalog = await cdpClient.listWebMCPTools(tabId, args || {});
+ return catalog.total === 0
+ ? { ...catalog, hint: 'This page has no registered WebMCP capabilities. Use ordinary accessibility, DOM, or execute_js tools; do not invent tool IDs.' }
+ : catalog;
} catch (error) {
return {
success: false,
diff --git a/test/agent-lifecycle.mjs b/test/agent-lifecycle.mjs
index 15885a4ab..a1bbd585e 100644
--- a/test/agent-lifecycle.mjs
+++ b/test/agent-lifecycle.mjs
@@ -411,6 +411,63 @@ function assertCompleteToolHistory(messages) {
assert.equal(outstanding.size, 0, 'last tool batch has unanswered calls');
}
+test('chrome: rejected WebMCP registrations enter bounded recovery despite invented ID churn and interleaved reads', async () => {
+ const {cdpClient} = await import('../src/chrome/src/cdp/cdp-client.js');
+ const before = cdpClient.getWebMCPToolContext;
+ const Agent = variants.find(([browser]) => browser === 'chrome')[1];
+ const agent = setup(Agent);
+ allowBatchPreparation(agent);
+ agent.webMcpEnabled = true;
+ agent._effectiveRunMode = () => 'act';
+ agent.executeTool = async () => assert.fail('Rejected registration or dependent browser action was dispatched');
+ cdpClient.getWebMCPToolContext = async () => null;
+ const messages = [], updates = [], results = [];
+ try {
+ for(let attempt=1;attempt<=3;attempt++) {
+ if(attempt>1) agent._checkLoop(91,'get_accessibility_tree',{}, {success:true});
+ results.push(await agent._executeToolBatch(91, [
+ {id:'webmcp-'+attempt,function:{name:'execute_webmcp_tool',arguments:JSON.stringify({tool_id:attempt===1?'':`invented-${attempt}`,input:{}})}},
+ {id:'dependent-'+attempt,function:{name:'navigate',arguments:'{"url":"https://example.com/next"}'}},
+ ], messages, (type,data)=>updates.push({type,data}), agent._activeProvider(91),null,new Set(['execute_webmcp_tool','navigate']),attempt));
+ }
+ assert.deepEqual(results.map(r=>r.action),['continue','continue','recover']);
+ assert.equal(results[2].status,'loop_stopped');
+ assert.equal(messages.length,6);
+ assert.match(messages.find(m=>m.tool_call_id==='webmcp-2').content,/FAILED ACTION LOOP/);
+ for(let attempt=1;attempt<=3;attempt++) {
+ const denied=JSON.parse(messages.find(m=>m.tool_call_id==='webmcp-'+attempt).content.split('\n')[0]);
+ assert.equal(denied.noDispatch,true);assert.equal(denied.dispatched,false);
+ assert.match(denied.hint,/ordinary accessibility/);
+ assert.equal(JSON.parse(messages.find(m=>m.tool_call_id==='dependent-'+attempt).content).skipped,true);
+ }
+ assert.equal(updates.filter(u=>u.type==='tool_call'&&u.data.name==='execute_webmcp_tool').length,3);
+ assert.equal(updates.filter(u=>u.type==='tool_result'&&u.data.name==='execute_webmcp_tool').length,3);
+ agent.failedActionLoops.set(91,new Map([['webmcp-tool-registration',2],['unrelated',1]]));
+ cdpClient.getWebMCPToolContext = async () => ({frameId:'trusted-frame',targetUrl:'https://example.com/',declaredReadOnly:false});
+ const valid=await agent._prepareWebMCPToolCall(91,'execute_webmcp_tool',{tool_id:'wmcp_real',_webMcpDeclaredReadOnly:true});
+ assert.equal(valid.args._webMcpDeclaredReadOnly,false);
+ assert.equal(valid.args._webMcpFrameId,'trusted-frame');
+ assert.deepEqual([...agent.failedActionLoops.get(91)],[['unrelated',1]]);
+ } finally {cdpClient.getWebMCPToolContext=before;}
+});
+
+test('chrome: empty WebMCP catalogs give DOM guidance without hiding real registrations', async () => {
+ const {cdpClient} = await import('../src/chrome/src/cdp/cdp-client.js');
+ const before = cdpClient.listWebMCPTools;
+ const Agent = variants.find(([browser]) => browser === 'chrome')[1];
+ const agent = setup(Agent);
+ agent.webMcpEnabled = true;
+ agent._chromeProtectedPageFailure = async () => null;
+ try {
+ cdpClient.listWebMCPTools = async()=>({success:true,total:0,tools:[]});
+ const empty=await agent.executeTool(92,'list_webmcp_tools',{});
+ assert.match(empty.hint,/do not invent tool IDs/);assert.equal(empty.total,0);
+ const real={success:true,total:1,tools:[{tool_id:'wmcp_real'}]};
+ cdpClient.listWebMCPTools = async()=>real;
+ assert.deepEqual(await agent.executeTool(92,'list_webmcp_tools',{}),real);
+ } finally {cdpClient.listWebMCPTools=before;}
+});
+
for (const [browser, Agent] of variants) {
for (const streaming of [false, true]) {
test(`${browser}: unlimited ${streaming ? 'stream' : 'chat'} run recovers from repeated rejected clicks`, async () => {