@@ -121,14 +121,6 @@ A <dfn>tool definition</dfn> is a [=struct=] with the following [=struct/items=]
121121 : <dfn>description</dfn>
122122 :: a [=string=] .
123123
124- : <dfn>imperative input schema object</dfn>
125- :: an {{object}} -or-null, initially null.
126-
127- Note: This is only populated for tools registered by the imperative form of this API (i.e.,
128- {{ModelContext/registerTool()}} . In that case, it holds the raw
129- {{ModelContextTool/inputSchema}} object, and is used in
130- {{ModelContext/unregisterTool()}} to find the right tool to unregister.
131-
132124 : <dfn>input schema</dfn>
133125 :: a [=string=] .
134126
@@ -153,6 +145,19 @@ A <dfn>tool definition</dfn> is a [=struct=] with the following [=struct/items=]
153145 :: a [=boolean=] , initially false.
154146</dl>
155147
148+ <div algorithm>
149+ To <dfn for="model context">unregister a tool</dfn> for a [=model context=] given a [=string=]
150+ |tool name|, run these steps:
151+
152+ 1. Let |tool map| be the associated [=model context=] 's [=model context/tool map=] .
153+
154+ 1. [=Assert=] |tool map|[|tool name|] [=map/exists=] .
155+
156+ 1. [=map/Remove=] |tool map|[|tool name|] .
157+
158+ </div>
159+
160+
156161<h2 id="api">API</h2>
157162
158163<!--
@@ -185,8 +190,7 @@ The {{ModelContext}} interface provides methods for web applications to register
185190<xmp class="idl">
186191[Exposed=Window, SecureContext]
187192interface ModelContext {
188- undefined registerTool(ModelContextTool tool);
189- undefined unregisterTool(ModelContextTool tool);
193+ undefined registerTool(ModelContextTool tool, optional ModelContextRegisterToolOptions options = {});
190194};
191195</xmp>
192196
@@ -195,23 +199,17 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
195199
196200
197201<dl class="domintro">
198- <dt><code><var ignore> navigator</var> .{{Navigator/modelContext}} .{{ModelContext/registerTool(tool)}} </code></dt>
202+ <dt><code><var ignore> navigator</var> .{{Navigator/modelContext}} .{{ModelContext/registerTool(tool, options )}} </code></dt>
199203 <dd>
200204 <p> Registers a single tool without clearing the existing set of tools. This method throws an
201205 exception if a tool with the same name already exists, or if the
202206 {{ModelContextTool/inputSchema}} is invalid.</p>
203207 </dd>
204-
205- <dt><code><var ignore> navigator</var> .{{Navigator/modelContext}} .{{ModelContext/unregisterTool(tool)}} </code></dt>
206- <dd>
207- <p> Removes the tool from the registered set of tools. This method throws an exception if no
208- matching tool has been registered.</p>
209- </dd>
210208</dl>
211209
212210
213211<div algorithm>
214- The <dfn method for=ModelContext>registerTool(<var>tool</var>)</dfn> method steps are:
212+ The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var> )</dfn> method steps are:
215213
2162141. Let |tool map| be [=this=] 's [=ModelContext/internal context=]' s [=model context/tool map=] .
217215
@@ -246,6 +244,17 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>)</dfn> method step
2462441. Let |read-only hint| be true if |tool|'s {{ModelContextTool/annotations}} [=map/exists=] and
247245 its {{ToolAnnotations/readOnlyHint}} is true. Otherwise, let it be false.
248246
247+ 1. Let |signal| be |options|'s {{ModelContextRegisterToolOptions/signal}} .
248+
249+ 1. If |signal| [=map/exists=] , then:
250+
251+ 1. If |signal| is [=AbortSignal/aborted=] , then optionally [=report a warning to the console=]
252+ indicating that the tool will not be registered because the {{AbortSignal}} is already
253+ [=AbortSignal/aborted=] , and return.
254+
255+ 1. [=AbortSignal/add|Add an abort algorithm=] to |signal| that [=model context/unregisters a
256+ tool=] from [=this=] [=ModelContext/internal context=] given |tool name|.
257+
2492581. Let |tool definition| be a new [=tool definition=] , with the following [=struct/items=] :
250259
251260 : [=tool definition/name=]
@@ -267,50 +276,6 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>)</dfn> method step
267276
268277</div>
269278
270- <div algorithm>
271- The <dfn method for=ModelContext>unregisterTool(<var>tool</var>)</dfn> method steps are:
272-
273- 1. Let |tool map| be [=this=] 's [=ModelContext/internal context=]' s [=model context/tool map=] .
274-
275- 1. Let |name| be |tool|'s {{ModelContextTool/name}} .
276-
277- 1. If |tool map|[|name|] does not [=map/exist=] , then [=exception/throw=] an {{NotFoundError}}
278- {{DOMException}} .
279-
280- 1. Let |registered tool| be |tool map|[|name|] .
281-
282- 1. Let |matches| be true.
283-
284- 1. [=Assert=] : |name| equals |registered tool|'s [=tool definition/name=] .
285-
286- 1. If |tool|'s {{ModelContextTool/description}} does not equal |registered tool|' s [=tool
287- definition/description=] , then set |matches| to false.
288-
289- 1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and |registered tool|' s [=tool
290- definition/imperative input schema object=] is null, or if |tool|'s
291- {{ModelContextTool/inputSchema}} does not [=map/exist=] but |registered tool|'s [=tool
292- definition/imperative input schema object=] is not null, then set |matches| to false.
293-
294- 1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and is not the same object as
295- |registered tool|'s [=tool definition/imperative input schema object=] , then set |matches| to
296- false.
297-
298- 1. Else if |tool|'s {{ModelContextTool/execute}} is not the same [=callback function=] that
299- |registered tool|'s [=tool definition/execute steps=] is prepared to run, then set |matches| to
300- false.
301-
302- 1. Let |tool read-only hint| be true if |tool|'s {{ModelContextTool/annotations}} [=map/exists=] and
303- its {{ToolAnnotations/readOnlyHint}} is true; false otherwise.
304-
305- 1. If |tool read-only hint| does not equal |registered tool|'s [=tool definition/read-only hint=] ,
306- then set |matches| to false.
307-
308- 1. If |matches| is false, then [=exception/throw=] an {{NotFoundError}} {{DOMException}} and return.
309-
310- 1. [=map/Remove=] |tool map|[|name|] .
311-
312- </div>
313-
314279<h4 id="model-context-tool">ModelContextTool Dictionary</h4>
315280
316281The {{ModelContextTool}} dictionary describes a tool that can be invoked by [=agents=] .
@@ -367,6 +332,26 @@ The {{ToolAnnotations}} dictionary provides optional metadata about a tool:
367332 :: If true, indicates that the tool does not modify any state and only reads data. This hint can help [=agents=] make decisions about when it is safe to call the tool.
368333</dl>
369334
335+ <h4 id="model-context-register-tool-options">ModelContextRegisterToolOptions Dictionary</h4>
336+
337+ The {{ModelContextRegisterToolOptions}} dictionary carries information pertaining to a tool's
338+ registration, in contrast with the {{ModelContextTool}} dictionary which carries the tool
339+ definition itself.
340+
341+ <xmp class="idl">
342+ dictionary ModelContextRegisterToolOptions {
343+ AbortSignal signal;
344+ };
345+ </xmp>
346+
347+ <dl class="domintro">
348+ <dt><code><var ignore> tool</var> ["{{ModelContextTool/name}}"] </code></dt>
349+ <dd>
350+ <p> An {{AbortSignal}} that unregisters the tool when aborted.
351+ </dd>
352+ </dl>
353+
354+
370355<h4 id="model-context-client">ModelContextClient Interface</h4>
371356
372357The {{ModelContextClient}} interface represents an [=agent=] executing a tool provided by the site through the {{ModelContext}} API.
0 commit comments