Skip to content

Commit 1380910

Browse files
DavidMulder0domfarolinoDavid Mulder (dmr9)
authored
Codify MCP tool name requirements and add tool title (#152)
Co-authored-by: Dominic Farolino <domfarolino@gmail.com> Co-authored-by: David Mulder (dmr9) <dmr9@3ds.com>
1 parent 90daeee commit 1380910

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

index.bs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ A <dfn>tool definition</dfn> is a [=struct=] with the following [=struct/items=]
118118
:: a [=string=] uniquely identifying a tool registered within a [=model context=]'s [=model
119119
context/tool map=]; it is the same as the [=map/key=] identifying this object.
120120

121+
The [=tool definition/name=]'s [=string/length=] must be between 1 and 128, inclusive, and only
122+
consist of [=ASCII alphanumeric=] [=code points=], U+005F LOW LINE (_),
123+
U+002D HYPHEN-MINUS (-), and U+002E FULL STOP (.).
124+
125+
: <dfn>title</dfn>
126+
:: A [=string=]-or-null representing a human-readable title of the tool for use in user interfaces.
127+
128+
Note: If {{ModelContextTool/title}} is not provided, the user agent is free to use a different
129+
value for display.
130+
121131
: <dfn>description</dfn>
122132
:: a [=string=].
123133

@@ -216,12 +226,18 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var
216226

217227
1. Let |tool name| be |tool|'s {{ModelContextTool/name}}.
218228

229+
1. Let |tool title| be |tool|'s {{ModelContextTool/title}}.
230+
219231
1. If |tool map|[|tool name|] [=map/exists=], then [=exception/throw=] an {{InvalidStateError}}
220232
{{DOMException}}.
221233

222-
1. If either |tool name| or {{ModelContextTool/description}} is the empty string, then
234+
1. If |tool name| or {{ModelContextTool/description}} is an empty string, then
223235
[=exception/throw=] an {{InvalidStateError}} {{DOMException}}.
224236

237+
1. If either |tool name| is the empty string, or its [=string/length=] is greater than 128, or if
238+
|tool name| contains a [=code point=] that is not an [=ASCII alphanumeric=], U+005F (_),
239+
U+002D (-), or U+002E (.), then [=exception/throw=] an {{InvalidStateError}}.
240+
225241
1. Let |stringified input schema| be the empty string.
226242

227243
1. If |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=], then set |stringified input schema|
@@ -261,6 +277,9 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var
261277
: [=tool definition/name=]
262278
:: |tool name|
263279

280+
: [=tool definition/title=]
281+
:: |tool title|
282+
264283
: [=tool definition/description=]
265284
:: |tool|'s {{ModelContextTool/description}}
266285

@@ -284,6 +303,9 @@ The {{ModelContextTool}} dictionary describes a tool that can be invoked by [=ag
284303
<xmp class="idl">
285304
dictionary ModelContextTool {
286305
required DOMString name;
306+
// Because `title` is for display in possibly native UIs, this must be a `USVString`.
307+
// See https://w3ctag.github.io/design-principles/#idl-string-types.
308+
USVString title;
287309
required DOMString description;
288310
object inputSchema;
289311
required ToolExecuteCallback execute;
@@ -303,6 +325,13 @@ callback ToolExecuteCallback = Promise<any> (object input, ModelContextClient cl
303325
<p>A unique identifier for the tool. This is used by [=agents=] to reference the tool when making tool calls.
304326
</dd>
305327

328+
<dt><code><var ignore>tool</var>["{{ModelContextTool/title}}"]</code></dt>
329+
<dd>
330+
<p>A label for the tool. This is used by the user agent to reference the tool in the user interface.
331+
<p>It is recommended that this string be localized to the user's
332+
{{NavigatorLanguage/language}}.
333+
</dd>
334+
306335
<dt><code><var ignore>tool</var>["{{ModelContextTool/description}}"]</code></dt>
307336
<dd>
308337
<p>A natural language description of the tool's functionality. This helps [=agents=] understand when and how to use the tool.

0 commit comments

Comments
 (0)