Adapt to the latest WebMCP spec#5
Merged
igrigorik merged 1 commit intoigrigorik:mainfrom Jan 28, 2026
Merged
Conversation
igrigorik
reviewed
Jan 28, 2026
| '@types': path.resolve(__dirname, './src/types'), | ||
| // Use CSP-safe Ajv shim - real Ajv uses new Function() which violates extension CSP | ||
| // Also fixes ESM import issue (ajv doesn't have default export in ESM) | ||
| ajv: path.resolve(__dirname, 'src/lib/ajv-csp-safe.js'), |
beaufortfrancois
left a comment
There was a problem hiding this comment.
Nice! I've tried it locally and it works great!
| name: 'my_tool', | ||
| description: 'Does something useful', | ||
| inputSchema: { type: 'object', properties: {} }, | ||
| execute: async (args, agent) => { |
There was a problem hiding this comment.
Nit: async is optional there.
| - `unregisterTool(name)` - Remove a tool by name | ||
| - `clearContext()` - Remove all tools | ||
| - `listTools()` - Get current tool definitions (without execute functions) | ||
| - `callTool(name, args)` - Invoke a tool (used by the agent, not typically by tools) |
There was a problem hiding this comment.
Should it be renamed to executeTool?
| // Create agent context for this tool execution | ||
| const agentContext = createAgentContext(); | ||
| // Per WebMCP spec: execute(params, agent) | ||
| return await Promise.resolve(tool.execute(params, agentContext)); |
There was a problem hiding this comment.
Naive question: Why not return await tool.execute(params, agentContext); only?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Align WebMCP polyfill with Chrome Canary's native implementation
Tested in 146.0.7652.0 canary
Separated page-side and agent-side APIs to match Chrome's WebMCP spec:
navigator.modelContextfor pages to register tools (registerTool,unregisterTool,provideContext,clearContext) andnavigator.modelContextTestingfor agents to discover/execute tools (listTools,executeTool,registerToolsChangedCallback)Fixed Chrome native API compatibility:
executeTool()now accepts args as JSON string (Chrome's format), andinputSchemareturned fromlistTools()is automatically parsed from JSON string to object inlifecycle.tsAdded CSP-safe Ajv shim (
src/lib/ajv-csp-safe.js) to replace real Ajv which usesnew Function()that violates Chrome extension CSP, also fixing the ESM default export issueUpdated page-bridge.js to use spec-aligned method names (
executeTool,registerToolsChangedCallback) and removed dead fallback code that referenced non-existent methods on the separated APIsMaintained backward compatibility via
window.agentwhich combines both page-side and agent-side methods for existing scripts, while new code should use the separatedmodelContext/modelContextTestingAPIs