Skip to content

Update stale examples and references to the current modelContext API - #284

Merged
domfarolino merged 2 commits into
webmachinelearning:mainfrom
lazizbekravshanov:update-modelcontext-examples
Sep 4, 2026
Merged

domfarolino merged 2 commits into
webmachinelearning:mainfrom
lazizbekravshanov:update-modelcontext-examples

Conversation

@lazizbekravshanov

Copy link
Copy Markdown
Contributor

The service worker doc and the declarative explainer still show the old API surface. provideContext and the global agent object are gone from the spec, registration now goes through modelContext.registerTool, and the execute callback's second parameter is an options dictionary carrying an AbortSignal, not an agent object.

The README also links the caller side executeTool signal anchor for the signal the execute callback receives, which is a different dictionary per the spec's execute steps (ToolExecuteCallbackOptions). This updates all four spots to match the current IDL.

The clientInfo parameter in the service worker example is kept as is, since the session id is that doc's own proposal rather than drift.

Copilot AI lite review requested due to automatic review settings September 2, 2026 13:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated service worker example still conflicts with the current execute-callback IDL shape and should await registerTool() and use ToolExecuteCallbackOptions for the second parameter to avoid publishing a misleading snippet.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates documentation/examples to match the current WebMCP modelContext API surface (removing references to the deprecated provideContext/global agent, and aligning execute-callback parameters and spec anchors).

Changes:

  • Update README to link the execute callback’s options.signal to the correct ToolExecuteCallbackOptions anchor.
  • Update the service worker explainer to describe modelContext as the global entry point and to use modelContext.registerTool(...) in the example.
  • Update the declarative API explainer example to use options (not agent) as the execute callback’s second parameter.
File summaries
File Description
README.md Fixes options.signal link to point at the execute-callback options dictionary member anchor.
docs/service-workers.md Replaces stale global agent references with modelContext and updates the registration example.
declarative-api-explainer.md Updates execute callback example signature to (…, options) to match current IDL.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/service-workers.md Outdated
Comment on lines 224 to 233
self.modelContext.registerTool({
name: "add-to-cart",
description: "Add an item to the user's shopping cart.",
inputSchema: { /* ... */ },
async execute(params, clientInfo) {
// fetch shopping cart for this session.
const cart = carts.get(clientInfo.sessionId);
cart.add(params.itemId);
}
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Took the options rename and the semicolon in f4135de. On awaiting registerTool: this snippet sits at the top level of a classic service worker script, where top level await is not available, and the spec's own examples call registerTool without awaiting. Happy to wrap the example in an activate handler with event.waitUntil if the editors prefer that shape.

@domfarolino domfarolino left a comment

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.

The sw doc is quite stale at this point, but the changes here are a strict improvement to it if we ever revisit it. And the correction in README.md is appreciated, thanks.

@domfarolino
domfarolino merged commit 16861c6 into webmachinelearning:main Sep 4, 2026
1 of 2 checks passed
github-actions Bot added a commit that referenced this pull request Sep 4, 2026
…284)

SHA: 16861c6
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants