From 17fcafc3d534a577a8445df2d1cf161c3eae3ae0 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 19 Mar 2026 10:14:18 -0400 Subject: [PATCH 1/4] Spec `unregisterTool(ModelContextTool)` --- index.bs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index e602129..7f7e8ca 100644 --- a/index.bs +++ b/index.bs @@ -121,6 +121,14 @@ A tool definition is a [=struct=] with the following [=struct/items=] : description :: a [=string=]. + : imperative input schema object + :: an {{object}}-or-null, initially null. + + Note: This is only populated for tools registered by the imperative form of this API (i.e., + {{ModelContext/registerTool()}}. In that case, it holds the raw + {{ModelContextTool/inputSchema}} object, and is used during in + {{ModelContext/unregisterTool()}} to find the right tool to unregister. + : input schema :: a [=string=]. @@ -178,7 +186,7 @@ The {{ModelContext}} interface provides methods for web applications to register [Exposed=Window, SecureContext] interface ModelContext { undefined registerTool(ModelContextTool tool); - undefined unregisterTool(DOMString name); + undefined unregisterTool(ModelContextTool tool); }; @@ -189,12 +197,15 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
navigator.{{Navigator/modelContext}}.{{ModelContext/registerTool(tool)}}
-

Registers a single tool without clearing the existing set of tools. The method throws an error, if a tool with the same name already exists, or if the {{ModelContextTool/inputSchema}} is invalid. +

Registers a single tool without clearing the existing set of tools. This method throws an + exception if a tool with the same name already exists, or if the + {{ModelContextTool/inputSchema}} is invalid.

-
navigator.{{Navigator/modelContext}}.{{ModelContext/unregisterTool(name)}}
+
navigator.{{Navigator/modelContext}}.{{ModelContext/unregisterTool(tool)}}
-

Removes the tool with the specified name from the registered set. +

Removes the tool from the registered set of tools. This method throws an exception if no + matching tool has been registered.

@@ -257,13 +268,45 @@ The registerTool(tool) method step
-The unregisterTool(name) method steps are: +The unregisterTool(tool) method steps are: 1. Let |tool map| be [=this=]'s [=ModelContext/internal context=]'s [=model context/tool map=]. -1. If |tool map|[|name|] does not [=map/exist=], then [=exception/throw=] an {{InvalidStateError}} +1. Let |name| be |tool|'s {{ModelContextTool/name}}. + +1. If |tool map|[|name|] does not [=map/exist=], then [=exception/throw=] an {{NotFoundError}} {{DOMException}}. +1. Let |registered tool| be |tool map|[|name|]. + +1. Let |matches| be true. + +1. [=Assert=]: |name| equals |registered tool|'s [=tool definition/name=]. + +1. If |tool|'s {{ModelContextTool/description}} does not equal |registered tool|'s [=tool + definition/description=], then set |matches| to false. + +1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and |registered tool|'s [=tool + definition/imperative input schema object=] is null, or if |tool|'s + {{ModelContextTool/inputSchema}} does not [=map/exist=] but |registered tool|'s [=tool + definition/imperative input schema object=] is not null, then set |matches| to false. + +1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and is not the same object as + |registered tool|'s [=tool definition/imperative input schema object=], then set |matches| to + false. + +1. Else if |tool|'s {{ModelContextTool/execute}} is not the same [=callback function=] that + |registered tool|'s [=tool definition/execute steps=] is prepared to run, then set |matches| to + false. + +1. Let |tool read-only hint| be true if |tool|'s {{ModelContextTool/annotations}} [=map/exists=] and + its {{ToolAnnotations/readOnlyHint}} is true; false otherwise. + +1. If |tool read-only hint| does not equal |registered tool|'s [=tool definition/read-only hint=], + then set |matches| to false. + +1. If |matches| is false, then [=exception/throw=] an {{NotFoundError}} {{DOMException}} and return. + 1. [=map/Remove=] |tool map|[|name|].
From 2859d035a9458309271c47538a701ae285077a5b Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 19 Mar 2026 21:14:00 -0400 Subject: [PATCH 2/4] Remove during --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 7f7e8ca..0c1c6e4 100644 --- a/index.bs +++ b/index.bs @@ -126,7 +126,7 @@ A tool definition is a [=struct=] with the following [=struct/items=] Note: This is only populated for tools registered by the imperative form of this API (i.e., {{ModelContext/registerTool()}}. In that case, it holds the raw - {{ModelContextTool/inputSchema}} object, and is used during in + {{ModelContextTool/inputSchema}} object, and is used in {{ModelContext/unregisterTool()}} to find the right tool to unregister. : input schema From 887d89dd8a898fdf9eb1fd3e67e8c522627da14e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 24 Mar 2026 16:02:57 -0400 Subject: [PATCH 3/4] Implement abort signal approach --- index.bs | 109 ++++++++++++++++++++++++------------------------------- 1 file changed, 47 insertions(+), 62 deletions(-) diff --git a/index.bs b/index.bs index 0c1c6e4..3026a13 100644 --- a/index.bs +++ b/index.bs @@ -121,14 +121,6 @@ A tool definition is a [=struct=] with the following [=struct/items=] : description :: a [=string=]. - : imperative input schema object - :: an {{object}}-or-null, initially null. - - Note: This is only populated for tools registered by the imperative form of this API (i.e., - {{ModelContext/registerTool()}}. In that case, it holds the raw - {{ModelContextTool/inputSchema}} object, and is used in - {{ModelContext/unregisterTool()}} to find the right tool to unregister. - : input schema :: a [=string=]. @@ -153,6 +145,19 @@ A tool definition is a [=struct=] with the following [=struct/items=] :: a [=boolean=], initially false. +
+To unregister a tool for a [=model context=] given a [=string=] +|tool name|, run these steps: + +1. Let |tool map| be the associated [=model context=]'s [=model context/tool map=]. + +1. [=Assert=] |tool map|[|tool name|] [=map/exists=]. + +1. [=map/Remove=] |tool map|[|tool name|]. + +
+ +

API