Skip to content

Migrate WebMCP surface to document.modelContext (Promise registration, single-arg execute)#23

Merged
kashishhora merged 4 commits into
mainfrom
feat/document-model-context-migration
Jun 23, 2026
Merged

Migrate WebMCP surface to document.modelContext (Promise registration, single-arg execute)#23
kashishhora merged 4 commits into
mainfrom
feat/document-model-context-migration

Conversation

@kashishhora

Copy link
Copy Markdown
Member

Summary

First step of bringing the polyfill and hooks in line with the current WebMCP spec. This PR is the structural surface migration:

  • registerTool returns a Promise<undefined> that rejects on invalid input (empty / duplicate / over-128-char or illegal name, missing description or execute, non-serializable inputSchema, non–potentially-trustworthy exposedTo origin). Internal tool-change notifications now fan out to multiple listeners.
  • Unregistration is AbortSignal-only. The public unregisterTool is gone — pass { signal } to registerTool and abort it to remove the tool. useMcpTool wires this up on cleanup.
  • API moved from navigator.modelContext to document.modelContext (the spec moved the getter to Document). Native detection is document-only; the testing API stays on navigator.modelContextTesting.
  • execute / handler are single-argument. The ModelContextClient second argument (and requestUserInteraction) is removed.

These are breaking changes. The version bump, CHANGELOG, and doc updates land in a follow-up PR once the rest of the migration is in.

Test plan

  • pnpm typecheck — clean
  • pnpm lint — clean
  • pnpm test — 163 passing (Vitest + jsdom, incl. StrictMode)
  • pnpm build

@naji247

naji247 commented Jun 23, 2026

Copy link
Copy Markdown
Member

Version bump?

@kashishhora kashishhora merged commit 70dadbc into main Jun 23, 2026
3 checks passed
@kashishhora kashishhora deleted the feat/document-model-context-migration branch June 23, 2026 19:50
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