Skip to content

Replace document.modelContext.getTools() with window.getTools() - #408

Draft
beaufortfrancois wants to merge 2 commits into
webmachinelearning:mainfrom
beaufortfrancois:window-getTools
Draft

beaufortfrancois wants to merge 2 commits into
webmachinelearning:mainfrom
beaufortfrancois:window-getTools

Conversation

@beaufortfrancois

@beaufortfrancois beaufortfrancois commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #236. Implements the window.getTools() portion of generalized-tool-calling.md (#375), focusing only on tool discovery via window.getTools() (leaving ToolManager, ToolObserver, Tool.execute(), and permissions policy updates for ModelContext to follow-up PRs).

Note: This PR was drafted with AI assistance and reviewed by me.

Spec changes (index.bs)

  • Moved getTools() from ModelContext to partial interface Window ([SecureContext]) and renamed ModelContextGetToolOptions to GetToolsOptions.
  • Extended HTML's CrossOriginProperties, cross-origin accessible window property name, and CrossOriginGetOwnPropertyHelper for "getTools" when the current settings object is a secure context.
  • Scoped window.getTools() to this's associated Document (resolving to [] if not fully active), dropped the "tools" Permissions Policy check, and ensured the returned promise, errors, and Tool objects are always created in the incumbent realm (queued on the incumbent global object).
  • Updated Permissions policy integration and Interaction with the Same-Origin Policy accordingly.

Documentation updates

  • Updated README.md, declarative-api-explainer.md, and generalized-tool-calling.md for window.getTools() and GetToolsOptions.fromOrigins.

Preview | Diff

Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs
property descriptor's `[[Value]]` is set to an anonymous built-in function, created in the
[=current realm=], that performs the same steps as the {{Window/getTools()}} operation on |O|,
even if |O|'s [=relevant settings object=] is not a [=secure context=] (and therefore
`originalDesc` is undefined).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, but curious if there is any policy or dictate that mentions this is required for all new properties we add here? Going to cc @camillelamy here in case she has opinions on this.

Comment thread index.bs Resolved
Comment thread index.bs
<div algorithm>
The <dfn method for=Window>getTools(<var>options</var>)</dfn> method steps are:

1. Let |callerSettings| be the [=incumbent settings object=].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://html.spec.whatwg.org/C#concept-incumbent-everything (the warning). Is there any way around this? I guess this is the same problem that motivated our switch to ToolObserver, although it's a little less bad if we avoid "incumbent" here, and instead construct Tool objects in the target realm?

That'd match how window.open() works:

const w = window.open("https://example.com");
console.log(w instanceof Window); // false! Interesting, huh?

and I don't think there's an issue with that (the fact that the returned Window is almost never an instance of the caller's Window constructor). Since WebMCP doesn't otherwise require knowlege of the "source" (the incumbent) here, I think it might be best to avoid incumbent altogether, and swallow the fact that the Tool objects are constructed in the "other" realm.

Let me loop in @jakearchibald here, and I'd be remiss if I didn't /cc @annevk for posterity who might have a quick opinion about this too, since it's such a core part of HTML.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants