feat: enableWebMCP registers the editor operations as WebMCP tools on the host page - #47
Open
bendersej wants to merge 8 commits into
Open
feat: enableWebMCP registers the editor operations as WebMCP tools on the host page#47bendersej wants to merge 8 commits into
bendersej wants to merge 8 commits into
Conversation
…, validated exclude, page-level tool names
…the model context per lifecycle transition
…nding, one lazy-chunk table
…he model-context host list; retry after a failed chunk load
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.
Background
SimplePDF's entry for the OpenAI WebMCP Challenge (Aug 25 – Sep 3, 2026). This PR is the SDK half of the entry; the demo app builds on it.
An in-browser agent (ChatGPT's browser, Chrome with WebMCP) discovers tools on the page it is looking at, not inside iframes. The SimplePDF editor already registers its operations as WebMCP tools, but inside its own document, so every site that embeds the editor exposes nothing to the agent.
enableWebMCPlifts the editor's operations to the host page'sdocument.modelContextand forwards each call to the editor over the existing bridge: the PDF bytes stay in the tab and reach no SimplePDF server (what the agent reads, field values and extracted text, goes to the agent runtime the person attached), and the editor validates every call like any other request (editing, allowlisted origin, plan).Changes
createEmbed({ enableWebMCP })and<EmbedPDF enableWebMCP />:trueregisters every agentic operation,{ exclude: [...] }withholds some (for examplesubmit, so a person keeps the decision), off by default; a malformed value or a misspelled name throwsEmbedConfigErrorat construction@simplepdf/embed/tools; the two readers carry the specification'sreadOnlyHint+untrustedContentHint(their output is document-derived), every writer an explicit MCPdestructiveHint; each call returns the MCP tool-result envelope carrying the editor's Result (isErroron failure), the shape the editor's in-page tools already returninput_schema(camelCase keys) into its own generated module read only by the lazy WebMCP module, and the agentic tool names into a second tiny module the root validates against, so the root bundle stays within budgetbooting(an agent enumerating tools at page load cannot post into a listener-less iframe), probes for a model context on later transitions while none is usable, and lazy-loads the module only then;dispose()aborts the registration signal and unregisters every toolNotes
AGENTIC_TOOL_NAMESis not exported from the root (no consumer); the manifest descriptions that mentionget_fieldsare owned by the editor's contract; registering only the operations the tenant configuration allows needs anEDITOR_READYpayload change on the editor side (follow-up); no client-side cap on in-flight tool calls (a same-page script has the same power today).Review outcomes
readOnlyHint+untrustedContentHinton the two readers,destructiveHinton the writersexcludevalidated for shape and names at construction (required fix)EmbedConfigErrorbefore anything mountstool-input-schemas.ts(lazy) +agentic-tool-names.ts(root);/protocolunchanged in sizenormalizeWebMCPOptions(@internal) andmodelContextCandidatesin one shared root moduleLAZY_CHUNKStable drives budget + load guardexclude, off-states collapse, remount on real change, tests for both