From 88b279e20b6c71054dc6b5120730715588c1d6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Thu, 19 Mar 2026 09:33:40 +0100 Subject: [PATCH 1/4] Add ToolActivatedEvent and ToolCancelEvent interfaces --- index.bs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/index.bs b/index.bs index 732d006..fa6992d 100644 --- a/index.bs +++ b/index.bs @@ -526,6 +526,8 @@ interface ModelContext : EventTarget { Promise executeTool(RegisteredTool tool, DOMString inputArguments, optional ModelContextExecuteToolOptions options = {}); attribute EventHandler ontoolchange; + attribute EventHandler ontoolactivated; + attribute EventHandler ontoolcancel; }; @@ -557,6 +559,13 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}. +
+ : ontoolactivated + :: An [=event handler IDL attribute=] for the {{ModelContext/toolactivated}} event type. + : ontoolcancel + :: An [=event handler IDL attribute=] for the {{ModelContext/toolcancel}} event type. +
+
The registerTool(tool, options) method steps are: @@ -1158,6 +1167,56 @@ dictionary RegisteredTool { +

ToolActivatedEvent Interface

+ +The {{ToolActivatedEvent}} interface represents a toolactivated event that is dispatched at {{Navigator/modelContext}} when a tool is invoked by an [=agent=]. + + +[Exposed=Window, SecureContext] +interface ToolActivatedEvent : Event { + constructor(DOMString type, optional ToolActivatedEventInit eventInitDict = {}); + readonly attribute DOMString toolName; + readonly attribute Element? element; +}; + +dictionary ToolActivatedEventInit : EventInit { + DOMString toolName = ""; + Element? element = null; +}; + + +
+ : toolName + :: Returns the name of the tool that was activated. + : element + :: Returns the form element associated with the tool, if any. +
+ +

ToolCancelEvent Interface

+ +The {{ToolCancelEvent}} interface represents a toolcancel event that is dispatched at {{Navigator/modelContext}} when a tool's invocation is canceled by an [=agent=]. + + +[Exposed=Window, SecureContext] +interface ToolCancelEvent : Event { + constructor(DOMString type, optional ToolCancelEventInit eventInitDict = {}); + readonly attribute DOMString toolName; + readonly attribute Element? element; +}; + +dictionary ToolCancelEventInit : EventInit { + DOMString toolName = ""; + Element? element = null; +}; + + +
+ : toolName + :: Returns the name of the tool that was canceled. + : element + :: Returns the form element associated with the tool, if any. +
+

Declarative WebMCP

This section is entirely a TODO. For now, refer to the [explainer draft](https://github.com/webmachinelearning/webmcp/pull/76). From 7dbb2aad6ce83f505e9c791b974dac07b4141166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Wed, 27 May 2026 08:43:20 +0200 Subject: [PATCH 2/4] Rebase --- index.bs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/index.bs b/index.bs index fa6992d..22e8fca 100644 --- a/index.bs +++ b/index.bs @@ -559,13 +559,6 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}. -
- : ontoolactivated - :: An [=event handler IDL attribute=] for the {{ModelContext/toolactivated}} event type. - : ontoolcancel - :: An [=event handler IDL attribute=] for the {{ModelContext/toolcancel}} event type. -
-
The registerTool(tool, options) method steps are: @@ -1169,7 +1162,7 @@ dictionary RegisteredTool {

ToolActivatedEvent Interface

-The {{ToolActivatedEvent}} interface represents a toolactivated event that is dispatched at {{Navigator/modelContext}} when a tool is invoked by an [=agent=]. +The {{ToolActivatedEvent}} interface represents a {{ModelContext/toolactivated}} event that is dispatched at {{ModelContext}} when a tool is invoked by an [=agent=]. [Exposed=Window, SecureContext] @@ -1194,7 +1187,7 @@ dictionary ToolActivatedEventInit : EventInit { <h4 id="tool-cancel-event">ToolCancelEvent Interface</h4> -The {{ToolCancelEvent}} interface represents a <dfn event for=ModelContext>toolcancel</dfn> event that is dispatched at {{Navigator/modelContext}} when a tool's invocation is canceled by an [=agent=]. +The {{ToolCancelEvent}} interface represents a {{ModelContext/toolcancel}} event that is dispatched at {{ModelContext}} when a tool's invocation is canceled by an [=agent=]. <xmp class="idl"> [Exposed=Window, SecureContext] @@ -1276,6 +1269,12 @@ that must be supported, as [=event handler IDL attributes=], by all {{ModelConte <tr> <td><dfn attribute for="ModelContext">ontoolchange</dfn> <td><dfn event for="ModelContext">toolchange</dfn> + <tr> + <td><dfn attribute for="ModelContext">ontoolactivated</dfn> + <td><dfn event for="ModelContext">toolactivated</dfn> + <tr> + <td><dfn attribute for="ModelContext">ontoolcancel</dfn> + <td><dfn event for="ModelContext">toolcancel</dfn> </table> <h3 id="permissions-policy">Permissions policy integration</h3> From 46633b138500a44104127f675f939e4427e5e85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= <beaufort.francois@gmail.com> Date: Thu, 6 Aug 2026 11:40:05 +0200 Subject: [PATCH 3/4] Specify and fire toolactivated event in imperative execute steps --- index.bs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 22e8fca..1c5d519 100644 --- a/index.bs +++ b/index.bs @@ -411,7 +411,9 @@ The <dfn>imperative execute steps</dfn>, given a {{ModelContextTool}} |tool|, a 1. If |inputObject| [=Object type|is not an Object=] is false, then run |completionSteps| given null and false, and abort these steps. - Issue(#146): Specify and fire the "<code>toolactivated</code>" event. +1. [=Fire an event=] named {{ModelContext/toolactivated}} at |targetDocument|'s [=Document/associated + ModelContext|associated <code>ModelContext</code>=], using {{ToolActivatedEvent}}, with its + {{ToolActivatedEvent/toolName}} attribute initialized to |tool|'s {{ModelContextTool/name}}. 1. Let |toolPromise| be the result of [=invoke|invoking=] |tool|'s {{ModelContextTool/execute}} with |inputObject|. From 1099a809a5021b0c35547506612cf844884561a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= <beaufort.francois@gmail.com> Date: Thu, 6 Aug 2026 11:49:07 +0200 Subject: [PATCH 4/4] Specify and fire toolcancel event when tool execution is aborted --- index.bs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.bs b/index.bs index 1c5d519..70af171 100644 --- a/index.bs +++ b/index.bs @@ -832,6 +832,11 @@ The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputArgument 1. [=Assert=]: |expectedTargetOrigin| is not an [=opaque origin=]. +1. Let |targetWindow| be |tool|'s {{RegisteredTool/window}}. + +1. Let |targetDocument| be |targetWindow|'s [=associated Document|associated + <code>Document</code>=]. + 1. Let |promise| be [=a new promise=] created in [=this=]'s [=relevant realm=]. 1. If |options|'s {{ModelContextExecuteToolOptions/signal}} [=map/exists=], then: @@ -845,15 +850,13 @@ The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputArgument 1. [=Reject=] |promise| with |signal|'s [=AbortSignal/abort reason=]. - Issue(#48): Wire up |signal| to the tool execution callback in the tool host's document, so - that tool abort is communicated all the way through. This should also fire the - "<code>toolcanceled</code>" event in the target document. See also <a - href=https://github.com/webmachinelearning/webmcp/issues/146>issue #146</a>. + 1. [=Fire an event=] named {{ModelContext/toolcancel}} at |targetDocument|'s + [=Document/associated ModelContext|associated <code>ModelContext</code>=], using + {{ToolCancelEvent}}, with its {{ToolCancelEvent/toolName}} attribute initialized to + |tool|'s {{RegisteredTool/name}}. -1. Let |targetWindow| be |tool|'s {{RegisteredTool/window}}. - -1. Let |targetDocument| be |targetWindow|'s [=associated Document|associated - <code>Document</code>=]. + Issue(#48): Wire up |signal| to the tool execution callback in the tool host's document, so + that tool abort is communicated all the way through. 1. Run the following steps [=in parallel=]: