Skip to content

Signaling tool stability to agents #328

Open

Description

@domfarolino

Unlike many MCP servers, where the available tool set is relatively stable for the lifetime of the server, WebMCP tools may change frequently as the user moves through a site:

  • Framework components mount and unmount
  • Async hydration completes after the page's load event
  • SPA navigations / route changes
  • Full-on MPA navigations
  • Changes in UI state that usher in new tools and unregister irrelevant ones

In our experience, agents operating web pages generally have a heuristic for deciding when a page has "loaded" or "settled" enough to create a page observation for the model, including the page's list of WebMCP tool.

The problem is that registration of all of a site's relevant tools might not be synchronized with the agent's page-stability heuristic. A page may "look ready" to the agent while an important batch of tools is still being registered, and an observation might then end up with a partial view of relevant tools designed for it.

Based on how we've seen agents being built, we anticipate this will be an issue, but we'd love feedback from other real-world browser-use agents to know if this problem statement resonates. We'd love to get a signal from at least the following folks:

Does your experience with browser agents resonate with the issue described above, whether related to WebMCP or beyond it? Would your agents benefit from letting developers provide input to existing page/tool stability heuristics?

We propose an API to let developers signal to any listening agents:

"My currently registered tools are still in flux. If you are about to take an initial or refreshed observation of my tools, please wait until I signal that this transition is complete."

We don't intend to standardize how page observations are taken. This is just about giving developers a way to provide a signal that agents can incorporate in their observation heuristics.

Example problem

Consider a page whose initial HTML becomes interactive before its WebMCP-specific code finishes loading:

// The page may already appear "loaded" or "settled" to an agent.

await import("./webmcp-tools.js");

document.modelContext.registerTool({
  name: "search_products",
  // ...
});

document.modelContext.registerTool({
  name: "issue_refund",
  // ...
});

document.modelContext.registerTool({
  name: "add_review",
  // ...
});

If the agent decides to observe the page between page readiness and completion of these registrations, the model may see only a partial tool set.

A similar issue can occur during SPA navigations, where a route transition causes one group of tools to disappear and another group to be registered asynchronously.

Strawman API proposal

One possible shape is an explicit begin/end signal:

const stability = document.modelContext.beginToolUpdate();

try {
  const tools = await import("./webmcp-tools.js");
  await tools.register();
} finally {
  stability.end();
}

While the tool-update scope is active, the page is indicating that its registered tool set should not yet be considered stable. The API could be nestable so that independent components can participate without coordinating through a single global promise:

const a = document.modelContext.beginToolUpdate();
const b = document.modelContext.beginToolUpdate();

a.end();
// Tool set is still unstable.

b.end();
// Tool set is now stable.

The browser should impose an upper bound on how long an outstanding stability signal can delay an observation, and agents will likely need their own preotections regardless. Both of these mreasures prevent a broken (or misbehaving) page from indefinitely blocking an agent.

(Disclaimer: the exact shape of the API above are only illustrative and are very up for debate).

SPA and dynamic transitions

One of the most common use cases for this API would be during SPA navigations, which are common on the web, and where agent page stability heuristics are likely to vary a lot:

async function navigate(path) {
  const update = document.modelContext.beginToolUpdate();

  try {
    await router.navigate(path);
    await registerToolsForRoute(path);
  } finally {
    update.end();
  }
}

Initial page load

To signal tool instability on initial page load, I think we have two options:

  1. Force developers to call beginToolUpdate() super early, in <head> JavaScript for example; or
  2. Provide a declarative, <meta> tag way to load a page with an immediate signal of tool instability, and make developers signal the end of that imperatively with JS
<meta name="tool-stability" content="pending">

<script>
  await App.slowHydration(); // Loads lots of tools asynchronously.
  document.modelContext.toolsAreStable();
</script>

Alternatives considered: "tool snapshot requested" event

Another possible design is for the browser to fire an event immediately before it intends to observe tools:

[SecureContext, Exposed=Window]
interface ToolObservationEvent : Event {
  undefined waitUntil(Promise<any> promise);
};

partial interface ModelContext {
  attribute EventHandler ontoolobservation;
};

A page could then delay the agent's observation with waitUntil(). This is attractive because it directly synchronizes the page with an observation attempt. But it assumes that agents have a discrete "tool snapshot" step that the browser can expose, and achieves the same thing as our above proposal, while unnecessarily exposing implementation details of the agent. It also gets confusing to developers when there are multiple agents driving a page.

The developer would likely use this API like this:

window.toolsAreStable = true;

async function loadMoreTools() {
  window.toolsAreStable = false;
  // Load more tools
  // ...
  window.toolsAreStable = true;
}

document.modelContext.ontoolsnapshotrequested = e => {
  if (!window.toolsAreStable) {
    e.waitUntil(/*some promise*/);
  }

  // Otherwise, do nothing.
}

In this case, the developer isn't interested in knowing when the agent is grabbing the list of tools, or how many agents are grabbing the list of tools. Instead, they're maintaining their own tool stability bookkeeping that simple gets surfaced to the agent through the event, making the event unimportant in the exchange.

Relationship to toolchange

Agents can still react incrementally to toolchange throughout the lifetime of the document, but since we've observed that an agent's heavy "page snapshot" / "page observation" infrastructure is unlikely to take place on every toolchange event, we still wind up with the page observation gap that motivates this issue.

Activity

  1. added
    Agenda+
    needs-agent-feedback
    on Sep 29, 2026
  2. sjdallst2 commented on Oct 1, 2026

    @sjdallst2
    Collaborator

    @domfarolino, for future communications, @bwalderman is working on multiple projects, and I am now the main point of contact for WebMCP dev at Microsoft.

    I like the idea of the proposal. Judging from the code we have, there is a clear information issue where we do not know when tools are available, and we have to guess when a page will be ready. And, like you said, page snapshots can be heavy.

    I like the idea of keeping everything within the websites control instead of the proposal where the agent sends an event that the page must respond to.

    Have you thought about having the modelContext be unstable by default (no declaration necessary), then adding something like an isFinal parameter for ModelContextRegisterToolOptions, or would that be confusing?

  3. dhrumil83 commented on Oct 1, 2026

    @dhrumil83

    One use case for this is progressive disclosure of tools through skills.
    For example, a page supports three skills and 20 tools across those skills. Initially, it exposes only a load_skill tool, with the three available skills as options.

    When the external agent loads a skill, the page returns its instructions and registers the eight tools needed for that workflow. The external agent then orchestrates those tools using its own model.

    A tool-stability signal would help the external agent know when all the skill’s tools are registered and ready to use.

  4. khushalsagar commented on Oct 13, 2026

    @khushalsagar
    Collaborator

    +1 to the idea here. Digging into the details:

    1. On the tool provider side, I agree it would be nice to allow different components to manage the delay for their own registration instead of a global hook. I like a promise based API instead of multiple begin/end APIs. Each component can call the API with their own promise and tools are in "not ready" state if there's any unresolved promises.

      const toolsReady = new Promise((resolve) => {
        // ... custom registration logic
        resolve();
      });
      
      document.modelContext.waitForToolsUntil(toolsReady);
      

      We might want to add a toolsReady boolean on modelContext for convenience so authors can read this state. Naming is tricky because modelContext.getTools technically provides tools from multiple frames and we can't synchronously provide this state for other frames. Maybe selfToolsReady or localToolsReady?

    2. For the initial page load case, this reminded me of the render blocking. The idea there was that the browser needed a signal to know when the page is ready to render for a human user and this is the same concept except for an agent. We expected other blocking cases to be added when the concept was introduced.

      We can start with keeping a Document in "new-page-loading-tools" until the body element is parsed. Observations are guaranteed to be blocked until then. After that, an observation is blocked based on whether there's any unresolved promises from waitForToolsUntil. This means authors need to use this API in a script in head.

      Going forward, we can add a tools or modelContext keyword to the blocking attribute so async scripts can be used to register tools:

       <script src="tools.js" async blocking="modelContext"></script>
      
    3. The user agent can timeout and take an observation even if the tools aren't ready (render-blocking does it too). I wasn't sure how much control non built-in tool consumers should have in configuring this timeout. Something like this, we can probably punt on this for now.

      await document.modelContext.getTools({fromOrigins: ['https://example.com'], timeout: 1000 });
      
    4. Tool consumers should have a way to at least know that the tools are incomplete. We don't have a good hook for this in the API right now. getTools returns a list of tools so we can't provide any metadata about the tool set itself. Since this state would be per window, maybe we could change the return type to the following and move window out of Registered Tool?

      dictionary WindowToolGroup {
        required Window window;
        required sequence<RegisteredTool> tools;
      };
      
      Promise<sequence<WindowToolGroup>> getTools(optional ModelContextGetToolOptions options = {});
      

      Or future proof it further with a wrapper struct that has a sequence<WindowToolGroup> so metadata about the complete observation can be added later.

  5. domfarolino commented on Oct 13, 2026

    @domfarolino
    CollaboratorAuthor

    Naming is tricky because modelContext.getTools technically provides tools from multiple frames and we can't synchronously provide this state for other frames. Maybe selfToolsReady or localToolsReady?

    I think we'll be moving document.modelContext => window.modelContext in service of #236 (see https://docs.google.com/document/d/1b2OfZcP2oEZ9JZi-DWN26VPCflNYSpue7-N76PxMAjQ/edit?tab=t.0#heading=h.7r7ujkqj2bm8) so I think toolsReady is nice.

    We can start with keeping a Document in "new-page-loading-tools" until the body element is parsed. Observations are guaranteed to be blocked until then.

    I suppose this makes sense, but the choice of unblocking observations after the <body> element feels a bit arbitrary. It requires developers to put promise-supplying script in <head> which is maybe good enough, but I'd be slightly worried about choosing <body> just because render blocking does. Render blocking understandably does because <head> does not render, while <body> does. But that distinction doesn't really mean anything for agents, right?

    Something like this, we can probably punt on this for now.
    await document.modelContext.getTools({fromOrigins: ['https://example.com'], timeout: 1000 });

    Agreed. That's probably close to the shape we might want to do if we had to, but for now IMO we should leave that bit out and see if it's needed later. We can always add it.

    Since this state would be per window, maybe we could change the return type to the following and move window out of Registered Tool?

    One alternative, given the fact that we're probably moving modelContext over to window, or something like that, would be to make modelContext.toolsReady be a method that returns a Promise<bool> that can be called on other window proxies. Thoughts?

  6. khushalsagar commented on Oct 14, 2026

    @khushalsagar
    Collaborator

    I think we'll be moving document.modelContext => window.modelContext in service of #236 so I think toolsReady is nice.

    \o/

    I suppose this makes sense, but the choice of unblocking observations after the element feels a bit arbitrary. It requires developers to put promise-supplying script in which is maybe good enough, but I'd be slightly worried about choosing just because render blocking does. Render blocking understandably does because does not render, while does. But that distinction doesn't really mean anything for agents, right?

    Fundamentally, we need to choose some point in the document lifecycle by when the author must signal whether observations should be blocked on tools. Delaying after body (on something like domContentLoaded) would unnecessarily block longer on pages which may not even have tools. The render blocking precedence also helps in that authors already set up relevant scripts (like A/B testing) to run before rendering is unblocked. Open to other ideas!

    One alternative, given the fact that we're probably moving modelContext over to window, or something like that, would be to make modelContext.toolsReady be a method that returns a Promise that can be called on other window proxies. Thoughts?

    A ontoolreadystatechanged event on window seems better. I skimmed through this. Assuming you're leaning towards option 2, other similar events like ontoolchange will also move to window? we can fire it with the current state the first time a handler is registered?

  7. khushalsagar commented on Oct 14, 2026

    @khushalsagar
    Collaborator

    Splitting the aspects of this issue so we can take them as separate resolutions:

    1. Tools ready state on Document
      Document has a tools-ready boolean to indicate that its registered tools are complete. Authors use the API below to control that state.

      const toolsReady = new Promise((resolve) => {
        // ... custom registration logic
        resolve();
      });
      
      document.modelContext.waitForToolsUntil(toolsReady);
      

      If there's any unresolved promises, tools-ready is false. How that influences the requests to read tools should be defined for each algorithm.

    2. Initial page load
      When a new Document commits, tools-ready starts as false. We need a point in the Document's lifecycle where it toggles to true if there are no unresolved promises. I propose that this should happen when the body element is parsed, so authors can reliably use script in head to use the API above.

    3. getTools Delay
      Script can call this method at any point. We'd likely need hooks to let tool consumers know when tools are ready or decide how long this call can block for tools to become ready. But let's pick a reasonable default: the user agent blocks this call for an implementation-defined timeout if tools-ready is false on any Document.

      Actually, maybe we shouldn't block reading tools from your own Document on tools-ready being true since its easy to get into a deadlock in that scenario? It's also not helpful since if you have access to the Document you can technically synchronously read this state.

    4. Page Observation Delay
      When the user agent makes a request to read the tool map via an Observation, it waits for an implementation-defined timeout if tools-ready is false on any Document.

    Punting on the hooks for 3) for now.

  8. markafoltz commented on Oct 15, 2026

    @markafoltz
    Collaborator
    1. Should we have the tool ready state be observable to script? (State names up for discussion, of course.)
    ModelContext.toolReadyState = "kLoading" | "kWaiting" | "kReady";
    

    Valid transitions:

    • kLoading => kWaiting if there is a pending Promise on load or async blocking script
    • kLoading => kReady if no pending Promise on load / async blocking script
    • kWaiting => kReady if Promise settles

    You could make this assignable as the signaling mechanism, instead of registering a Promise. But most developers will just trigger kWaiting => kReady via a Promise anyway, and there are invalid state transitions, so not really an improvement from an API ergonomics point of view.

    1. If there are multiple sets of tools per document, it should be possible to register a new Promise if the previous Promise has settled to signal a transition back into the kWaiting state. However, it should not delay an already-scheduled observation resulting from an existing Promise (settled or not).

    2. As a corollary to 2, pages can now signal re-observation an arbitrary number of times. Implementations may choose to cap this or have some backoff.

    3. Should we allow replacing an unsettled Promise with a different Promise? In principle I don't see an issue.

    4. Should we allow document.modelContext.waitForToolsUntil(null) to cancel a unsettled Promise registration?

  9. khushalsagar commented on Oct 15, 2026

    @khushalsagar
    Collaborator

    Should we have the tool ready state be observable to script? (State names up for discussion, of course.)

    • A readonly boolean to know whether the tools are in a stable state makes sense to me. But API wise, I think the promise based one is more ergonomic. It lets different components in the system block readiness on their own async operations instead of coordinating on flipping a global enum.
    • I'm combing the kLoading and kWaiting state into the toolsReady = false. Wasn't sure if its worth distinguishing these but not opposed to it.
    • kReady => kWaiting is also a valid transition (for SPAs in particular).

    If there are multiple sets of tools per document, it should be possible to register a new Promise if the previous Promise has settled to signal a transition back into the kWaiting state.

    Each time you call waitForToolsUntil, the promise gets added to a set and the presence of unresolved promises does a transition to kWaiting. So that should work in the proposal.

    it should not delay an already-scheduled observation resulting from an existing Promise (settled or not).

    This is a good subtlety to clarify. I am expecting the algorithm to go:

    a. When an observation is requested by the user-agent or getTools is called, check the ready state. If ready, schedule an observation.
    b. If not, start a timer and schedule an observation if a timeout occurs or the ready state toggles to true.

    So an already-scheduled observation isn't further delayed if a new promise is added once the timer has started. Does that align with what you had in mind?

    As a corollary to 2, pages can now signal re-observation an arbitrary number of times. Implementations may choose to cap this or have some backoff.

    Didn't follow this.

    Should we allow replacing an unsettled Promise with a different Promise? In principle I don't see an issue.

    If its a per-promise replace or clear then the author can just resolve that promise and set a new one. So doesn't seem that advantageous to me. But I could see the use-case for a forceToolsReady() API to clear all promises, for a site driven global timeout.

    Should we allow document.modelContext.waitForToolsUntil(null) to cancel a unsettled Promise registration?

    Eh maybe you're misunderstanding the API shape I'm proposing. waitForToolsUntil doesn't track a single promise but a set of promises. So passing null doesn't mean anything.

  10. kenchris commented on Oct 20, 2026

    @kenchris

    From the extension side, two things about the toolsReady direction, which we'd use.

    The wait in 3 and 4 (reading the tools waits for ready, with a timeout) needs to apply to extension callers too, and not only to the browser's own observation. We don't run inside the page, and today we re-list a tab's tools before every model turn because toolchange only fires in the page, so a tool registered late can be missed in between. Two things would help us: the same wait when an extension reads a tab's tools, and a way to tell whether the list we got is complete or was returned because the timeout ran out. Otherwise a partial list looks the same as a finished one, and we would act on it.

    The other reason a settled tool list matters is prompt caching. The tool list sits at the start of the prompt, and serving stacks only reuse work for the longest identical start, so every change to the list means everything after it is computed again. A signal lets the host take one snapshot of the list per turn once it has settled, instead of seeing the set half registered, which is a real difference in cost. I wrote up how hosts avoid this with lazy loading, and what it needs from WebMCP, in #357.

  11. markafoltz commented on Oct 20, 2026

    @markafoltz
    Collaborator

    Following up on the comment above. I didn't gather that the API allows the registration of multiple promises, so some of my questions/suggestions were irrelevant - sorry about that!

    I'm combing the kLoading and kWaiting state into the toolsReady = false

    The only advantage might be the developer would be able to tell if they are calling waitForToolsUntil early enough, in the kLoading state, to delay the first observation. I don't feel too strongly about this - there is probably a document lifecycle hook that they can use instead.

    So an already-scheduled observation isn't further delayed if a new promise is added once the timer has started. Does that align with what you had in mind?

    Sounds good.

    As a corollary to 2, pages can now signal re-observation an arbitrary number of times. Implementations may choose to cap this or have some backoff.

    Sorry if I wasn't clear. I was wondering if we care whether pages can toggle the toolsReady state an arbitrary number of times, and whether that forces an observation even when it might be unnecessary or unused. So, suggesting a note that toggling the state does not guarantee a new observation.

  12. khushalsagar commented on Oct 21, 2026

    @khushalsagar
    Collaborator

    I was wondering if we care whether pages can toggle the toolsReady state an arbitrary number of times, and whether that forces an observation even when it might be unnecessary or unused. So, suggesting a note that toggling the state does not guarantee a new observation.

    Makes sense. This is worth a note in the spec.

  13. khushalsagar commented on Oct 27, 2026

    @khushalsagar
    Collaborator

    Hallway discussion right after with liad and jake:

    • The API is sufficient for async scripts with something like this.

         {promise, resolve, reject} = Promise.withResolvers();
         window.tools.waitUntil(promise);
         window.toolsReady = resolve;
         
         // wait for relevant async scripts to be fetched
         window.toolsReady();
    • Still an open question on what lifecycle state to wait for, top contenders are body parsed or domContentLoaded.

  14. 10 remaining items

  15. DenisovAV commented on Nov 24, 2026

    @DenisovAV

    Agent feedback request noted, here's a site-side data point for the SPA case.

    We run three stores on one origin, split by path, each with its own tool set (3–4 tools bridged from a remote MCP server). Switching stores via client-side routing means aborting one set (AbortSignal) and registering the next asynchronously, because the new set comes from the server. We could not confirm that an agent mid-task would observe the new set rather than a partial or stale one, so we force a full page load on every store switch.

    A tools-ready state that we can hold false across the route transition (waitForToolsUntil() with the fetch-and-register promise) would cover exactly this and let us keep client-side navigation. It would also help if agents were expected to re-observe after a ready transition that follows a toolchange, not only on initial load.

  16. frostyhand commented on Nov 26, 2026

    @frostyhand

    Answering @beaufortfrancois's question from the preview list with data from sites that already ship WebMCP.

    My Agentic Web Census finds WebMCP on 4 home pages in the Tranco top 10k. I fetched each one today and looked at where the registration code actually runs:

    Site Where tools are registered Cutoff at end of <head> Cutoff at DOMContentLoaded
    monday.com inline classic script in <head> works works
    hostinger.com inline classic script in <head>; a Nuxt module bundle later aborts those tools and registers a fuller set works if the head script opens the promise and the bundle settles it works
    cloudflare.com inline <script type="module"> in <head> (Astro); re-registers on astro:page-load misses: module scripts run after the whole document is parsed works
    cookiebot.com external <script type="module"> in <body>; registers after await import(...) misses works if it calls waitForToolsUntil() before its first await

    With the <head> cutoff, 2 of the 4 would need a new classic inline stub (the Promise.withResolvers() pattern from the hallway discussion) just to hold agents. Both are module scripts emitted by their build setup (Astro and Vite). A module script placed in <head> looks like it meets a "script must be in the head" rule but runs too late, and I expect authors to hit that often. Neither site needs a change with DOMContentLoaded.

    So I prefer DOMContentLoaded. Two things I'd add if the group goes that way:

    1. DOMContentLoaded does not wait for a module's top-level await. In Chrome, a body module that awaits logs body module start | DCL | body module after await. Cookiebot's pattern (await import(), then register) would miss the cutoff unless it calls waitForToolsUntil() before the first await. That deserves a sentence in the spec note and in the developer docs.
    2. The cost falls on pages without tools. That is nearly every page today: 4 of 6,478 measured home pages register any. If the group picks the <head> cutoff to spare those pages the wait, I think blocking="modelContext" from @khushalsagar's earlier comment needs to ship at the same time, so module and deferred scripts have a way in. Without it, the most common modern setup misses the cutoff silently.

    The SPA case looks fine either way. Cloudflare already aborts on astro:before-swap and re-registers on astro:page-load, which maps directly onto the onRouteChange example. Wrapping that re-registration in waitForToolsUntil() is also what closes the gap @DenisovAV described.

    Caveats: home pages only, 4 sites, minified code read by hand. Once Chrome 160 is out I can add a census check for where waitForToolsUntil() is called (classic in head, module in head, module in body) so the group can see which placements authors actually use.

  17. BullRulez commented on Nov 26, 2026

    @BullRulez

    DOMContentLoaded is the better cutoff.
    Three practical reasons from shipping modern web apps:
    type="module" and defer are the default. Vite, Next.js, and standard ESM builds emit deferred module scripts—and many MPAs still load scripts at the bottom of . Cutting off at forces developers to either add a render-blocking script in (hurting FCP/LCP) or inline a bootstrap stub just to call waitForToolsUntil(), which breaks under strict CSP (script-src without 'unsafe-inline').
    Tool availability often depends on DOM/hydration state. Even in an MPA, deciding which tools to register frequently depends on reading serialized state or container elements in the body. Putting that logic inside isn't realistic without splitting registration into two places, which invites race conditions where agents silently miss tools.
    Minimal latency penalty vs. load. DOMContentLoaded already avoids waiting on images, fonts, and third-party subresources, so agents aren't stalled—and any page that genuinely wants to register earlier still can.
    If you want a fast path for pages with no tools or early tools, keeping the cutoff at DOMContentLoaded while letting pages optionally signal early readiness (e.g., an already-settled promise or declarative hint) gives the best of both worlds without breaking standard ESM bundling.

  18. aeroxy commented on Nov 26, 2026

    @aeroxy

    Prefer DOMContentLoaded, with an angle not yet in the thread: pages written by an LLM from a template.

    I run an app builder where a model writes each page as one HTML file from a skill's template. The template declares

    in the body and registers the other tools from an inline classic script right after it. With a head cutoff, every such page needs a head stub whose only job is to hold agents. A page that misses the cutoff fails silently: the agent reads a partial list and nothing errors. I can fix our template, but not pages that are already published or written by hand. With DOMContentLoaded the template works unchanged. The one pitfall, a module that awaits before calling waitForToolsUntil(), takes a sentence of docs, as @frostyhand wrote.

    On point 3, I also read tools from page-world code: an extension's MAIN-world script, and a same-origin host reading an embedded app's document.modelContext. #373 leaves getTools() unwired, so that code can't tell a complete list from one cut off by the timeout. +1 to @kenchris. A read-only ready flag would be enough.

  19. DanCanadian commented on Nov 26, 2026

    @DanCanadian

    I favor DOMContentLoaded for the initial cutoff. One case worth testing is a serial registration queue where the set of tools is itself asynchronous. If the first two registrations finish while a feature decision is pending, waiting for the queue's current tail can still give the observer a plausible but incomplete list.

    I built a framework-neutral fixture with two baseline tools and a third selected asynchronously. I ran its scripts in Node with an explicitly modeled document lifecycle and observer:

    First observation boundary When the page submitted the promise Tools in the first snapshot
    End of head Start of a module 0
    DOMContentLoaded Start of the same module 3
    DOMContentLoaded Application startup task after the event 0

    These counts describe the model. Native Chrome 160 agent observations and timeout behavior still need a browser test.

    For authors, I'd document passing a pending promise during the synchronous part of a deferred script or module, before awaiting hydration, configuration, or imports. That promise should cover selection and completion of the final registrations. A parser-executed head bootstrap can do the same under either cutoff. Feature-detecting the readiness method lets older browsers continue along the same registration path.

    For a same-document navigation, I'd submit a fresh promise when the transition starts, before aborting the previous registrations. A regression test could start a second navigation while the first one's configuration is pending, then resolve the stale request last and inspect the tools available to an observing agent.

    Could the browser tests pin down two boundaries explicitly: whether a call inside a DOMContentLoaded listener can still affect the first observation, and what an observer receives when the readiness deadline expires between the baseline and optional registrations?

  20. beaufortfrancois commented on Nov 27, 2026

    @beaufortfrancois
    Collaborator

    Posting on behalf of Francisco Angulo de Lafuente (ORCID 0009-0001-1634-7063), who sent this feedback by email after the preview-list announcement. He can't comment here directly right now. He works on EnigmAgent and PayPal Agentic Guardrail, which both keep three things separate: discovering operations, authorizing them, and running them through a broker.

    1. Initial-load cutoff

    He supports DOMContentLoaded. This builds on the module and deferred-script points @frostyhand raised above. He suggests:

    • Separating the deadline for announcing pending preparation (calling waitForToolsUntil()) from the deadline for finishing that work.
    • Saying in the docs that the readiness promise should be registered before the first await or other async work that might run past the cutoff.

    He agrees the <head> cutoff has a real latency advantage on some pages. He hasn't measured timing to compare the two.

    2. Relevance to broker-based tools

    PayPal Agentic Guardrail exposes list_payment_operations and run_payment_operation, and its policy-enforcing broker does the actual execution. EnigmAgent exposes named broker operations through MCP. For a possible WebMCP adapter, a readiness signal would help with discovery. But a tool being registered successfully must stay separate from authorizing it when it runs: "ready" shouldn't suggest "authorized."

    Francisco isn't claiming credit for lifecycle proposals already discussed here. Please credit him if any of this wording is used.

  21. jagreehal commented on Nov 27, 2026

    @jagreehal

    A data point from the library side, measured in Chrome Canary 160 with WebMCPTesting enabled. I maintain webmcpable, a small library over registerTool. I logged when DOMContentLoaded fired and when tools registered on two of its example pages:

    Page First registerTool
    React app, Vite production build, tools registered in useEffect after DOMContentLoaded
    Plain module script that waits on customElements.whenDefined() before registering after DOMContentLoaded

    Both miss a <head> cutoff, and both miss DOMContentLoaded too. React renders and runs effects in a later task, so registration lands after the event. The library calls waitForToolsUntil() at the start of each registration pass, but that call itself comes too late to hold the first observation. This is the same problem as a module's top-level await, noted above, but authors don't write the await themselves: the framework adds it.

    So framework apps need a classic inline stub under either cutoff. webmcpable now ships one as a string to inline in <head>, and its first registration pass resolves it:

    <script>
    try { document.modelContext?.waitForToolsUntil?.(new Promise(r => { window.__webmcpableReady = r })) } catch {}
    </script>

    With the stub, the React page logs: hold opened, DOMContentLoaded, tools registered, hold settled.

    What I'd take from this:

    1. DOMContentLoaded is still the better cutoff. It covers plain module and deferred scripts with no stub.
    2. Whichever ships, the developer docs should show the stub and say it must be a classic script. A type="module" script in <head> runs after parsing, so it looks right and still misses.
    3. The stub needs a hash or nonce under a strict CSP. blocking="modelContext" on an external script, or a declarative opt-in in markup, would let framework apps hold agents without inline script.
  22. DenisovAV commented on Nov 27, 2026

    @DenisovAV

    Data point, Chrome 160: our tools come from a tools/list fetch in a module script. At DOMContentLoaded getTools() is empty in every run; tools land 120–500 ms later, <head> or <body> alike. So a <head> cutoff misses us; DOMContentLoaded works with waitForToolsUntil() called before the first await.

  23. hyik007 commented on Nov 27, 2026

    @hyik007

    Strong vote for DOMContentLoaded as the cutoff.

    In real-world static/vanilla apps (for example, we just wired document.modelContext.registerTool + waitForToolsUntil(Promise.allSettled(...)) into MemBridge), tool registration depends on app state/DOM bindings initialized by scripts placed at the end of <body> or loaded with defer / type="module".

    Requiring a <head>-only script forces authors either to split tool registration away from the application bootstrap or to add an artificial inline stub in <head> just to call waitForToolsUntil() before the actual module executes. Waiting until DOMContentLoaded keeps defer and <script type="module"> working naturally without incurring the slow load event wait.

  24. johnrippy1980 commented on Nov 27, 2026

    @johnrippy1980

    Prefer DOMContentLoaded. Adding a WordPress data point, which the thread hasn't covered yet.

    We run a WordPress plugin on 13 small-business sites that turns their existing contact and quote forms into declarative tools. The forms come from the theme or a form builder (Elementor, WPForms, Gravity Forms), so the plugin can't put toolname in the markup. Its script adds toolname and tooldescription at DOMContentLoaded and loads at the end of <body>. On the sites I checked today, no served form carries toolname; the attributes only exist after the script runs.

    • Head cutoff: agents would read the page before the forms are even parsed. Holding them would mean an inline stub in <head> on every site, or a render-blocking script.
    • DOMContentLoaded: works as-is if the footer script calls waitForToolsUntil() before the event and settles it once the forms are annotated.

    One trap that applies to either cutoff: WordPress performance plugins with a "delay JavaScript until user interaction" setting (WP Rocket, LiteSpeed Cache, NitroPack) hold scripts until the first scroll, click or keypress. An agent does none of those, so a delayed tool script never runs, waitForToolsUntil() is never called, and the agent sees no tools with no signal as to why. We hit this on a live site (NitroPack) and now exclude our script from those optimizers. A note for CMS and optimizer authors in the spec or the developer docs would save others the same debugging.

  25. andreibesleaga commented on Nov 28, 2026

    @andreibesleaga

    A data point from an extension, in support of what @kenchris and @aeroxy wrote about getTools().

    WebAIAssist (I maintain with AI) reads a page's tools from a page-world script that it adds when the user opens the side panel, usually long after load. The initial cutoff does not reach it. It gets whatever getTools() returns at that moment.

    In Chrome 157 the first list of a test page came back empty, because the page registered its tools a moment later. The first fix was a guess: when the list is empty, list again after 1 s and after 3 s (code). A list with two of three tools is not empty, so it gets no second look, and the model plans without the third tool until a toolchange arrives.

    A readable tools-ready state, or the ready boolean on toolchange, would replace both timers with one wait. (not tried on Chrome 160 yet).

  26. SeCuReDmE-main-dev commented on Nov 28, 2026

    @SeCuReDmE-main-dev

    Another production data point in favor of DOMContentLoaded, from a static Astro MPA running under a strict CSP (https://formation.dev.securedme.ca — 27 static pages, a single-source catalog of 49 implemented tools, 39 of which are also served via JSON-RPC /mcp, scoped to 5–12 active tools per page state, with the Origin Trial active).

    Building on @frostyhand's Astro ESM observation and @jagreehal's CSP note:

    1. Reading page state from <body> under script-src 'self' (no 'unsafe-inline')

    Each compiled page declares its tool state on <body data-webmcp-state="..."> (home, beta, legal, composer:edit, etc.), and the shared layout emits an external <script type="module" src="/_astro/...">.

    With an end-of-<head> cutoff, we miss the window for two reasons at once:

    • Per the HTML spec, <script type="module"> is deferred until parsing completes.
    • Even if a script ran inside <head>, <body data-webmcp-state> has not been parsed yet.

    Adding a classic inline stub in <head> to hold a deferred promise conflicts with our strict script-src 'self' CSP (forcing per-build script hashes just for the workaround). With DOMContentLoaded, the external module reads document.body.dataset.webmcpState and calls waitForToolsUntil(Promise.allSettled(...)) synchronously before its first await, with zero inline scripts.

    2. Mid-task state transitions triggered inside a tool's execute() (re: @dhrumil83 & @DanCanadian)

    Our /beta page implements the progressive-disclosure pattern @dhrumil83 described: it loads read-only (5 tools, including a describe_page_skills door-handle). When an agent invokes describe_page_skills, the tool transitions the page to beta:apply (6 tools, exposing the submission tool with consequentialHint: true). Our multi-tab editor does the same across composer:edit → composer:structure → composer:review.

    On each transition we abort the previous AbortController and synchronously pass a Promise.allSettled(...) promise (with error handling contained inside .then() so a single rejected tool never releases waitForToolsUntil() prematurely or drops the other N - 1 tools):

    export async function registerTools(tools: WebMcpToolDefinition[]) {
      const controller = new AbortController();
      const mc = document.modelContext;
      if (!mc) return { unregister: () => controller.abort(), registered: 0, rejected: 0 };
    
      const settled = Promise.allSettled(
        tools.map(async (t) => {
          await mc.registerTool(t, { signal: controller.signal });
          return t.name;
        }),
      ).then((outcomes) => {
        let registered = 0, rejected = 0;
        outcomes.forEach((o, i) => o.status === 'fulfilled' ? registered++ : (rejected++, console.warn('[WebMCP][WARN]', tools[i]?.name, o.reason)));
        return { registered, rejected };
      });
    
      mc.waitForToolsUntil?.(settled); // called synchronously before the first await
      const counts = await settled;
      return { unregister: () => controller.abort(), ...counts };
    }

    One edge case worth pinning down in the spec: when an existing tool's execute() triggers abort() + waitForToolsUntil(nextBatch) before returning its result to the agent, it would help to state explicitly that the agent's next observation (and getTools() when wired) waits for that new promise to settle, so the model never observes an intermediate empty/partial tool list between abort() and re-registration.

    — Jean-Sébastien Beaulieu (https://orcid.org/0009-0007-2904-0443)

  27. Pacamaraprogress commented on Nov 28, 2026

    @Pacamaraprogress

    Another WordPress data point, this time for imperative tools (the one above covers declarative forms), in favour of DOMContentLoaded.

    We run small plugins on five production WordPress sites, 7 to 15 imperative tools each. Each plugin prints one inline script at the end of <body> (wp_footer, where WordPress plugins normally print scripts): the config, and a loader that injects the tools file only when document.modelContext exists, after load plus requestIdleCallback (2 s timeout). Browsers without WebMCP download nothing, and the tools file never competes with the page's own content.

    Measured on three of the sites (Chrome 158, desktop, cold profile, third-party requests blocked, so real visits are slower):

    DOMContentLoaded load last tool registered
    Site A (15 tools) 1.7 s 3.0 s 3.1 s
    Site B (11 tools) 1.2 s 2.1 s 2.3 s
    Site C (7 tools) 3.9 s 5.0 s 5.1 s

    Without a call, an agent that reads the tools at either cutoff finds none on all three.

    What the plugins do now (live on all five since 28 Nov, behind feature detection, tested with a stand-in method because our Chrome does not have it yet): the footer loader calls waitForToolsUntil() while the document is still loading, with a promise whose resolver it leaves on the config object. The tools file takes the resolver and resolves it after Promise.allSettled() over its registerTool() promises, including one tool that registers after a fetch. The injected script's load and error events resolve it if the file never takes it over (a 404, an old cached file). This works with a DOMContentLoaded cutoff and needs nothing in <head>.

    Why an end-of-<head> cutoff is harder here:

    1. The call has to move into <head>. For a plugin that means a second inline script in wp_head, only to call the method and keep the resolver, and that script then has to be kept away from the optimisation plugins that defer, combine, delay or move scripts.
    2. The spec text starts the timer at the call (the "in parallel, wait an implementation-defined amount of time" step). A call made in <head> spends the body parse and the whole load on that timer before the tools file is even requested. With Chrome's 10 seconds, a slow phone on a page with heavy third-party scripts could run out before the tools arrive. A DOMContentLoaded cutoff leaves more of the budget for the tools themselves.

    Questions:

    • Could the timeout start when an agent first asks for the tools (as proposed earlier in this thread), or at the cutoff, rather than at the call? Then an early call would not spend the budget on page load.
    • What happens to a call made after the cutoff? If it threw (InvalidStateError, say) or warned in the console, a page could find out in testing that it calls too late. This is close to DanCanadian's question about a call inside a DOMContentLoaded listener.
    • When the timer ends the wait before the tools register, will an agent that already looked look again after the later toolchange? The spec's note says that toggling tools ready does not by itself cause an observation.
  28. beaufortfrancois commented on Nov 30, 2026

    @beaufortfrancois
    Collaborator

    Thinking out loud, a ready read-only toolManager property that would return a promise with tools once waitForToolsUntil resolves could also be useful from an extension/3rd party perspective.

    const tools = await window.toolManager.ready;
  29. frostyhand commented on Nov 30, 2026

    @frostyhand

    +1. This is the read side that @kenchris, @aeroxy and @andreibesleaga asked for, and it would let extensions drop their relist timers.

    document.fonts.ready from CSS Font Loading is a close precedent. Three details from it that I think carry over:

    1. Hand out a new promise when tools go back to not ready. fonts.ready is replaced with a fresh pending promise when the font set goes from loaded back to loading. Tools need the same. After a route change calls waitForToolsUntil() again, ready should return a new pending promise. Otherwise a caller that awaits it mid-transition gets the old, already resolved promise with the previous route's tools, which is the partial list this issue is meant to prevent.
    2. Resolve only on a real ready transition, not when the wait times out. If ready also resolves when the implementation-defined timeout runs out, a caller can't tell a complete list from a cut-off one, the gap @kenchris raised. If it resolves only when tools are actually ready, resolution always means complete, and a caller that needs a bound can race it against its own timer. If the group would rather have it settle on timeout too, the value should say so, for example { tools, complete: false }.
    3. Say which documents it waits for. Tools ready is per Document, but a tool list spans frames. I'd match what an observation does: wait until tools ready is true on every document whose tools the list includes.

    The resolved array is a snapshot, so callers still need toolchange afterwards. The ready boolean on toolchange from @khushalsagar's earlier comment pairs well with this: the promise for the first read, the event for everything after.

    If this shape gets support, I'm happy to draft the spec text and a WPT for the route-change case: await ready during a transition, then check that the resolved list matches the new route's tools.

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

Metadata

Metadata

Assignees

Labels

Agenda+needs-agent-feedback

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions