Skip to content

chore: in-page tool output: stash DOM elements and preprocess for serialization#1877

Merged
wolfib merged 9 commits intomainfrom
element-output-2
Apr 22, 2026
Merged

chore: in-page tool output: stash DOM elements and preprocess for serialization#1877
wolfib merged 9 commits intomainfrom
element-output-2

Conversation

@wolfib
Copy link
Copy Markdown
Contributor

@wolfib wolfib commented Apr 16, 2026

Improvements for handling in-page tool responses. In order to successfully pass an in-page tool response from the page context to the MCP server, the response needs to be serializable. The code walks the response object an performs the following changes:

  • DOM elements are stashed onto the window object and replaced with an ID. On the MCP server side this ID is used to map back to the corresponding UID in the page snapshot generated from the accessibility tree.
  • Circular references are replaced with a string.
  • Class instances (which can be complex or non-serializable) are replaced with a string.
  • Functions are replaced with a string.

If the in-page tool response contains DOM elements which are not part of the page snapshot, a new snapshot is created add the missing elements are added explicitly.

@wolfib wolfib requested a review from OrKoN April 16, 2026 14:37
Comment thread src/tools/inPage.ts Outdated
Comment thread src/tools/inPage.ts Outdated
Comment thread src/McpContext.ts Outdated
Comment thread src/tools/inPage.ts Outdated
@wolfib wolfib force-pushed the element-output-2 branch from 83b53db to 7119995 Compare April 20, 2026 09:57
@OrKoN OrKoN self-requested a review April 21, 2026 11:34
@wolfib wolfib force-pushed the element-output-2 branch from 7119995 to 5ee5e30 Compare April 22, 2026 13:48
Comment thread src/McpPage.ts
Comment thread src/TextSnapshot.ts
@wolfib wolfib force-pushed the element-output-2 branch from 4535086 to e963f17 Compare April 22, 2026 14:31
@wolfib wolfib added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit e046c23 Apr 22, 2026
20 checks passed
@wolfib wolfib deleted the element-output-2 branch April 22, 2026 14:59
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