Skip to content

chore: DOM elements as inputs for in-page tools#1791

Merged
wolfib merged 2 commits intomainfrom
element-input
Apr 2, 2026
Merged

chore: DOM elements as inputs for in-page tools#1791
wolfib merged 2 commits intomainfrom
element-input

Conversation

@wolfib
Copy link
Copy Markdown
Contributor

@wolfib wolfib commented Apr 1, 2026

DOM elements are non-serializable and therefore cannot be directly sent between the inspected page and the MCP server. JSONSchema also has no native type for DOM elements.

If an in-page tool expects a DOM element as an input parameter, it should specify this in its input schema by adding 'x-mcp-type': 'HTMLElement' to the object it expects to be a DOM element.

The MCP server internally refers to DOM elements by a UID (UIDs are assigned when generating a page snapshot which is based on the page's accessibility tree).

This change provides the mapping between DOM element and UID in both directions:

  1. The tool's input schema is rewritten internally, adding a required UID attribute to objects with 'x-mcp-type': 'HTMLElement'. This allows the MCP server to call the in-page tool with UIDs where the tool expects DOM elements.
  2. In the page context, the UIDs are replaced with the corresponding DOM elements, before the actual in-page tool is called. This means that the in-page tool receives DOM elements as parameters where it expects them.

@wolfib wolfib requested a review from OrKoN April 2, 2026 07:31
@wolfib wolfib added this pull request to the merge queue Apr 2, 2026
Merged via the queue into main with commit 627ed68 Apr 2, 2026
32 of 34 checks passed
@wolfib wolfib deleted the element-input branch April 2, 2026 09:41
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