From 0bb0c34c3bc54dc2f4c4c2125a07e6ae4dacf615 Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Fri, 5 Jun 2026 01:09:24 -0700 Subject: [PATCH] Track toolautosubmit attribute changes for declarative tools Declarative WebMCP tools registered via the
element now correctly respond to changes in the 'toolautosubmit' attribute. Previously, modifying this attribute after the tool was registered would leave the tool's 'autosubmit' annotation in a stale state for the inspector. This change: 1. Updates HTMLFormMcpTool to capture the 'toolautosubmit' attribute state at the time of registration. 2. Modified HTMLFormElement::UpdateMcpDefinitionsIfNeeded to detect drifts between the current attribute state and the registered tool. 3. Updated HTMLFormElement::AttributeChanged to trigger a tool re-registration when 'toolautosubmit' is added or removed. 4. Adds an inspector protocol test to verify that toggling the attribute correctly triggers toolsRemoved/toolsAdded events with the updated annotation. Fixed: 509838990 Change-Id: I68b55c73478cdedafea2e266aeb86a4fa528a308 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7827761 Reviewed-by: Dominic Farolino Auto-Submit: Philip Pfaffe Commit-Queue: Philip Pfaffe Cr-Commit-Position: refs/heads/main@{#1642180} --- ...oolchange-on-attribute-mutation.https.html | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/webmcp/declarative/toolchange-on-attribute-mutation.https.html b/webmcp/declarative/toolchange-on-attribute-mutation.https.html index 1ee85331ed4089..fe2890c89a072a 100644 --- a/webmcp/declarative/toolchange-on-attribute-mutation.https.html +++ b/webmcp/declarative/toolchange-on-attribute-mutation.https.html @@ -96,6 +96,28 @@ assert_equals(tools[0].description, 'Restored Description'); } + // Test adding toolautosubmit attribute + { + const changePromise = waitForToolChange(); + form.setAttribute('toolautosubmit', ''); + await changePromise; + + let tools = await navigator.modelContext.getTools(); + assert_equals(tools.length, 1, "Tool still registered after adding toolautosubmit"); + assert_equals(tools[0].name, 'new_tool_name', "Tool name is still the same"); + } + + // Test removing toolautosubmit attribute + { + const changePromise = waitForToolChange(); + form.removeAttribute('toolautosubmit'); + await changePromise; + + let tools = await navigator.modelContext.getTools(); + assert_equals(tools.length, 1, "Tool still registered after removing toolautosubmit"); + assert_equals(tools[0].name, 'new_tool_name', "Tool name is still the same"); + } + // Test removing toolname attribute (should unregister the tool since it's required) { const changePromise = waitForToolChange(); @@ -105,6 +127,6 @@ let tools = await navigator.modelContext.getTools(); assert_equals(tools.length, 0, "Tool should be unregistered when name is removed"); } -}, "Test that mutating or removing form attributes (toolname, tooldescription, tooltitle) fires toolchange and updates getTools() correctly"); +}, "Test that mutating or removing form attributes (toolname, tooldescription, tooltitle, toolautosubmit) fires toolchange and updates getTools() correctly");