Repository navigation
Support "*" in getTools fromOrigins #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4a63adf
5b13707
74a9b53
5e07ae0
9963cba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,13 +347,15 @@ await document.modelContext.registerTool({ | |
| Any document in the tree matching these origins (and allowed to use `tools` permission) will: | ||
|
|
||
| - Receive the `toolchange` event on its `document.modelContext` when the tool is registered or unregistered. | ||
| - Be able to discover and run the tools | ||
| - Be able to discover the tools (for cross-origin discovery, the consumer's `fromOrigins` must include the provider's origin or `"*"`), and run them subject to execution checks. | ||
|
|
||
| #### Discovering and running tools: `getTools()` and `executeTool()` | ||
|
|
||
| Once tools are registered, in-page agents can discover and invoke them using `getTools()` and `executeTool()`. | ||
|
|
||
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option. This array only supports secure origins. | ||
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option, or use `{ fromOrigins: ["*"] }` to query all origins in that tree, including opaque origins. The API's secure-context restriction still applies. | ||
|
|
||
| In `fromOrigins`, only the exact `"*"` string is special. It does not bypass Permissions Policy or execution checks. Discovery still requires the provider's explicit `exposedTo` origin list to allow the caller. A wildcard opts into any eligible origin, not just origins trusted by the author; wildcard consumers may discover tools with untrusted descriptions. Prefer explicit origin lists when possible. Other entries are still validated even when `"*"` is present. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the sole-entry rule, "Other entries are still validated even when Also, "Discovery still requires the provider's explicit |
||
|
|
||
| ```js | ||
| // Discover tools exposed by same-origin frames in the tree (default) | ||
|
|
@@ -371,9 +373,14 @@ for (const tool of tools) { | |
| const crossOriginTools = await document.modelContext.getTools({ | ||
| fromOrigins: ["https://trusted-partner.example"] | ||
| }); | ||
|
|
||
| // Discover tools exposed to the caller by frames of any origin: | ||
| const allOriginTools = await document.modelContext.getTools({ | ||
| fromOrigins: ["*"] | ||
| }); | ||
| ``` | ||
|
|
||
| An agent executes a discovered `Tool` by passing it and input arguments along to `document.modelContext.executeTool()`. The browser securely mediates the execution, ensuring the [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) and [`fromOrigins`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextgettooloptions-fromorigins) agree, and the tool runs in the tool owner's execution context. `Tool` objects can only be obtained from `getTools()`, and each one refers to the specific tool registration it was returned for: if that tool is unregistered, executing the `Tool` fails, even if a new tool is later registered under the same name. | ||
| An agent executes a discovered `Tool` by passing it and input arguments along to `document.modelContext.executeTool()`. The browser securely mediates the execution, checking [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) again, and the tool runs in the tool owner's execution context. [`fromOrigins`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextgettooloptions-fromorigins) filters discovery, not execution. `Tool` objects can only be obtained from `getTools()`, and each one refers to the specific tool registration it was returned for: if that tool is unregistered, executing the `Tool` fails, even if a new tool is later registered under the same name. | ||
|
|
||
| ```js | ||
| const tools = await document.modelContext.getTools(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -175,6 +175,15 @@ An <dfn>AI platform</dfn> is a provider of agentic assistants such as OpenAI’s | |||||||||||||||||||
|
|
||||||||||||||||||||
| <h2 id="supporting-concepts">Supporting concepts</h2> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| An <dfn>origin wildcard</dfn> is the [=string=] "`*`", used in | ||||||||||||||||||||
| {{ModelContextGetToolOptions/fromOrigins}} to request discovery from all origins. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| In {{ModelContextGetToolOptions/fromOrigins}}, | ||||||||||||||||||||
| only the exact string "`*`" is an [=origin wildcard=]. All other entries are parsed and validated | ||||||||||||||||||||
| as origins, even when the array also contains an [=origin wildcard=]. | ||||||||||||||||||||
|
Comment on lines
+178
to
+183
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two paragraphs say the same thing twice. With the sole-entry rule (see below), I'd merge them into one:
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| Issue(#317): Consider supporting {{URLPattern}} objects for more selective origin matching. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| A <dfn>model context</dfn> is a [=struct=] with the following [=struct/items=]: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <dl dfn-for="model context"> | ||||||||||||||||||||
|
|
@@ -1066,10 +1075,18 @@ The <dfn method for=ModelContext>getTools(<var>options</var>)</dfn> method steps | |||||||||||||||||||
|
|
||||||||||||||||||||
| 1. Let |from origins| be an empty [=list=] of [=origins=]. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. Let |includeAllOrigins| be false. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=map/exists=], then: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. [=list/For each=] |origin| of |options|'s {{ModelContextGetToolOptions/fromOrigins}}: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. If |origin| is the [=origin wildcard=], then: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. Set |includeAllOrigins| to true. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. [=iteration/continue=]. | ||||||||||||||||||||
|
Comment on lines
+1078
to
+1088
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a suggested change that requires the wildcard to be the only entry. I used 1. Let |includeAllOrigins| be false.
1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=map/exists=], then:
+ 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=list/contains=] the [=origin
+ wildcard=], then:
+
+ 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}}'s [=list/size=] is not 1, then
+ return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
+
+ 1. Set |includeAllOrigins| to true.
+
+ 1. Otherwise, [=list/for each=] |origin| of |options|'s
+ {{ModelContextGetToolOptions/fromOrigins}}:
- 1. [=list/For each=] |origin| of |options|'s {{ModelContextGetToolOptions/fromOrigins}}:
-
- 1. If |origin| is the [=origin wildcard=], then:
-
- 1. Set |includeAllOrigins| to true.
-
- 1. [=iteration/continue=].
1. Let |parsedURL| be the result of running the [=URL parser=] on |origin|.
... |
||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. Let |parsedURL| be the result of running the [=URL parser=] on |origin|. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. If |parsedURL| is failure or its [=url/origin=] is not [$is origin potentially | ||||||||||||||||||||
|
|
@@ -1101,7 +1118,8 @@ The <dfn method for=ModelContext>getTools(<var>options</var>)</dfn> method steps | |||||||||||||||||||
| 1. Let |callerOrigin| be |toolRequestor|'s [=Document/origin=]. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. Let |toolOwnerIsRequested| be true if |targetOrigin| is [=same origin=] with | ||||||||||||||||||||
| |callerOrigin|, or if |from origins| [=list/contains=] |targetOrigin|; otherwise, false. | ||||||||||||||||||||
| |callerOrigin|, |from origins| [=list/contains=] |targetOrigin|, or |includeAllOrigins| | ||||||||||||||||||||
| is true; otherwise, false. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 1. If |toolOwnerIsRequested| is false, then [=iteration/continue=]. | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -1472,7 +1490,9 @@ dictionary ModelContextRegisterToolOptions { | |||||||||||||||||||
|
|
||||||||||||||||||||
| <dl class="domintro"> | ||||||||||||||||||||
| : <code><var ignore>options</var>["{{ModelContextRegisterToolOptions/exposedTo}}"]</code> | ||||||||||||||||||||
| :: An array of origins that control which documents this tool is exposed to, in the current document's tree. | ||||||||||||||||||||
| :: An array of origin strings that control which documents this tool is exposed to, in the | ||||||||||||||||||||
| current document's tree. | ||||||||||||||||||||
| An omitted or empty array only permits same-origin access by documents. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| : <code><var ignore>options</var>["{{ModelContextRegisterToolOptions/signal}}"]</code> | ||||||||||||||||||||
| :: An {{AbortSignal}} that unregisters the tool when aborted. | ||||||||||||||||||||
|
|
@@ -1493,9 +1513,22 @@ dictionary ModelContextGetToolOptions { | |||||||||||||||||||
| : <code><var ignore>options</var>["{{ModelContextGetToolOptions/fromOrigins}}"]</code> | ||||||||||||||||||||
| :: An array of origins from which to query tools. Documents whose origin appears in this list, or | ||||||||||||||||||||
| are same-origin with the caller, have their tools queried. An empty list only includes | ||||||||||||||||||||
| same-origin documents. | ||||||||||||||||||||
| same-origin documents. The [=origin wildcard=] queries documents regardless of their origin, | ||||||||||||||||||||
| including [=opaque origins=], in the current document's tree. | ||||||||||||||||||||
| Tools must still be exposed to the caller, and documents must be [=allowed to use=] the | ||||||||||||||||||||
| "{{tools}}" feature. | ||||||||||||||||||||
|
Comment on lines
1513
to
+1519
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things:
|
||||||||||||||||||||
| </dl> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <div class=example id=origin-wildcard-options> | ||||||||||||||||||||
| Use the [=origin wildcard=] to discover tools exposed to the caller by documents of any origin | ||||||||||||||||||||
| in the current document's tree: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```js | ||||||||||||||||||||
| const tools = await document.modelContext.getTools({ fromOrigins: ["*"] }); | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| </div> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <h4 id="model-context-execute-tool-options">ModelContextExecuteToolOptions Dictionary</h4> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The {{ModelContextExecuteToolOptions}} dictionary allows web applications to pass options to | ||||||||||||||||||||
|
|
@@ -2271,9 +2304,9 @@ operations or extract sensitive state from another [=origin=]. | |||||||||||||||||||
| By default, WebMCP enforces strict [=same origin=] isolation: a tool registered via <code><var | ||||||||||||||||||||
| ignore>document</var>.{{Document/modelContext}}.{{ModelContext/registerTool()}}</code> is only | ||||||||||||||||||||
| visible to and executable by {{Document}}s that are [=same origin=] with the registering | ||||||||||||||||||||
| {{Document}} (tool owner). Cross-origin {{Document}}s cannot discover, observe | ||||||||||||||||||||
| {{ModelContext/toolchange}} events for, or execute a tool unless three independent access-control | ||||||||||||||||||||
| gates are satisfied: | ||||||||||||||||||||
| {{Document}} (tool owner). Cross-origin tool discovery requires three independent access-control | ||||||||||||||||||||
| gates. Tool invocation and {{ModelContext/toolchange}} notifications require the first two gates; | ||||||||||||||||||||
| {{ModelContextGetToolOptions/fromOrigins}} filters discovery, not invocation or notifications: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <ol> | ||||||||||||||||||||
| <li> | ||||||||||||||||||||
|
|
@@ -2289,9 +2322,10 @@ gates are satisfied: | |||||||||||||||||||
| <li> | ||||||||||||||||||||
| <strong>Tool Provider Opt-In ({{ModelContextRegisterToolOptions/exposedTo}})</strong>: A | ||||||||||||||||||||
| {{Document}} registering a tool must explicitly opt in to cross-origin exposure by specifying | ||||||||||||||||||||
| the permitted caller [=origins=] in {{ModelContextRegisterToolOptions/exposedTo}}. Each listed | ||||||||||||||||||||
| [=origin=] must be a valid, [$is origin potentially trustworthy?|potentially trustworthy$] | ||||||||||||||||||||
| [=origin=]. During both discovery ({{ModelContext/getTools()}}) and invocation | ||||||||||||||||||||
| the permitted caller [=origins=] in | ||||||||||||||||||||
| {{ModelContextRegisterToolOptions/exposedTo}}. Each entry | ||||||||||||||||||||
| must be a valid, [$is origin potentially trustworthy?|potentially trustworthy$] [=origin=]. | ||||||||||||||||||||
| During both discovery ({{ModelContext/getTools()}}) and invocation | ||||||||||||||||||||
| ({{ModelContext/executeTool()}}), the [=user agent=] evaluates the [=tool is exposed to an | ||||||||||||||||||||
| origin=] algorithm, ensuring that only callers whose [=Document/origin=] is [=same origin=] with | ||||||||||||||||||||
| the tool owner or explicitly listed in {{ModelContextRegisterToolOptions/exposedTo}} can access | ||||||||||||||||||||
|
|
@@ -2303,14 +2337,15 @@ gates are satisfied: | |||||||||||||||||||
| a tool to its parent [=origin=] via {{ModelContextRegisterToolOptions/exposedTo}}, | ||||||||||||||||||||
| {{ModelContext/getTools()}} only returns tools from [=same origin=] {{Document}}s by default. To | ||||||||||||||||||||
| discover tools from a cross-origin descendant [=navigable=], the calling {{Document}} must also | ||||||||||||||||||||
| explicitly list the target [=origin=] in {{ModelContextGetToolOptions/fromOrigins}}. | ||||||||||||||||||||
| explicitly list the target [=origin=] or the [=origin wildcard=] in | ||||||||||||||||||||
| {{ModelContextGetToolOptions/fromOrigins}}. | ||||||||||||||||||||
| </li> | ||||||||||||||||||||
| </ol> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| **Why Two-Sided Opt-In Matters**: Requiring mutual consent from both the tool provider | ||||||||||||||||||||
| **Why Two-Sided Opt-In Matters**: Requiring opt-in from both the tool provider | ||||||||||||||||||||
| ({{ModelContextRegisterToolOptions/exposedTo}}) and the tool consumer | ||||||||||||||||||||
| ({{ModelContextGetToolOptions/fromOrigins}}) prevents both unauthorized cross-origin actuation and | ||||||||||||||||||||
| unsolicited tool-list pollution. Without provider opt-in | ||||||||||||||||||||
| ({{ModelContextGetToolOptions/fromOrigins}}) lets each restrict the origins involved in discovery. | ||||||||||||||||||||
| Provider opt-in also protects against unauthorized cross-origin actuation. Without provider opt-in | ||||||||||||||||||||
| ({{ModelContextRegisterToolOptions/exposedTo}}), a malicious parent page could invoke internal tools | ||||||||||||||||||||
| inside an embedded third-party widget that were intended only for [=same origin=] use. Conversely, | ||||||||||||||||||||
| without consumer opt-in ({{ModelContextGetToolOptions/fromOrigins}}), a compromised or untrusted | ||||||||||||||||||||
|
|
@@ -2341,14 +2376,20 @@ await document.modelContext.registerTool( | |||||||||||||||||||
| ); | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The [=origin wildcard=] opts into all origins in the document's tree, not only origins trusted by | ||||||||||||||||||||
| the author. Authors should prefer explicit origin lists when possible. In particular, a consumer | ||||||||||||||||||||
| using the [=origin wildcard=] accepts tools exposed to it by any eligible document in that tree. | ||||||||||||||||||||
| The provider's {{ModelContextRegisterToolOptions/exposedTo}} origin list and the "{{tools}}" | ||||||||||||||||||||
| Permissions Policy still apply. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <h5 id="same-origin-residual-risks">Residual Risks</h5> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Even when cross-origin access is governed by the mechanisms above, two categories of residual risk | ||||||||||||||||||||
| remain: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <ul> | ||||||||||||||||||||
| <li> | ||||||||||||||||||||
| <strong>Direct Cross-Origin Exposure</strong>: Even when two [=origins=] mutually opt in via | ||||||||||||||||||||
| <strong>Direct Cross-Origin Exposure</strong>: Even when the provider and consumer opt in via | ||||||||||||||||||||
| {{ModelContextRegisterToolOptions/exposedTo}} and {{ModelContextGetToolOptions/fromOrigins}}, | ||||||||||||||||||||
| they remain separate trust domains: tool providers must still treat caller-supplied arguments as | ||||||||||||||||||||
| untrusted input, and callers must treat cross-origin tool descriptions and return values as | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,8 @@ The feature is gated by the [`"tools"`](https://webmachinelearning.github.io/web | |
|
|
||
| Additionally, tools can specify [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) to control which origins can discover them. Whether tool authors in cross origin iframes can explicitly control exposure to the browser's built in agent, for example through a `native-agent` keyword, is an open design question tracked under [Built-in agent exposure by default](https://github.com/webmachinelearning/webmcp/blob/main/README.md#built-in-agent-default-exposure) in the README. | ||
|
|
||
| Consumers can use the origin wildcard `"*"` in [`fromOrigins`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextgettooloptions-fromorigins) to query all origins in the document's tree, including opaque origins. The API is restricted to secure contexts, which can include opaque-origin documents. The wildcard does not bypass Permissions Policy or the provider's `exposedTo` origin list. A wildcard accepts any eligible origin rather than a specific trusted party; explicit origin lists are preferable when possible. | ||
|
|
||
| > 15. How do the features in this specification work in the context of a browser's Private Browsing or Incognito mode? | ||
|
|
||
| We do not anticipate any differences, but implementers should be aware of how to safely handle private browsing modes. See [Interaction with Private Browsing Modes](https://webmachinelearning.github.io/webmcp/#interaction-with-private-browsing). | ||
|
|
@@ -101,7 +103,7 @@ Note: this behavior is not yet spec'd but is the intended direction. | |
|
|
||
| > 20. Does your spec define when and how new kinds of errors should be raised? | ||
|
|
||
| Yes. `registerTool()` throws `InvalidStateError` for inactive documents, duplicate names, or invalid name/description; `NotAllowedError` when the `"tools"` Permissions Policy is disallowed; `SecurityError` for non-trustworthy [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) origins; and `TypeError` when `inputSchema` or `outputSchema` serialization fails. These errors only reflect the page's own state and inputs, so they do not leak new information. | ||
| Yes. `registerTool()` throws `InvalidStateError` for inactive documents, duplicate names, or invalid name/description; `NotAllowedError` when the `"tools"` Permissions Policy is disallowed; `SecurityError` for invalid or non-trustworthy [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) entries; and `TypeError` when `inputSchema` or `outputSchema` serialization fails. `getTools()` likewise rejects with `SecurityError` for invalid or non-trustworthy `fromOrigins` entries other than `"*"`. All non-wildcard `fromOrigins` entries are validated even when `"*"` is present. These errors only reflect the page's own state and inputs, so they do not leak new information. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs the same update for the sole-entry rule: replace "All non-wildcard |
||
|
|
||
| > 21. Does your feature allow sites to learn about the user's use of assistive technology? | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The API's secure-context restriction still applies." reads oddly right after "including opaque origins". Either explain the connection (secure contexts can still have opaque origins) or drop the sentence. Also, please mention that
"*"must be the only entry.