Update stale examples and references to the current modelContext API - #284
domfarolino merged 2 commits into
Conversation
There was a problem hiding this comment.
🟡 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.signalto the correctToolExecuteCallbackOptionsanchor. - Update the service worker explainer to describe
modelContextas the global entry point and to usemodelContext.registerTool(...)in the example. - Update the declarative API explainer example to use
options(notagent) 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.
| 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); | ||
| } | ||
| }) |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
The service worker doc and the declarative explainer still show the old API surface.
provideContextand the globalagentobject are gone from the spec, registration now goes throughmodelContext.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
executeToolsignal 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
clientInfoparameter in the service worker example is kept as is, since the session id is that doc's own proposal rather than drift.