fix: report the tab id in the get_tab_id response#2372
Open
serhiizghama wants to merge 3 commits into
Open
Conversation
get_tab_id only wrote the tab id into structuredContent, which the tool handler attaches to the result exclusively when --experimental-structured-content is set. The tool itself is gated behind --experimental-interop-tools, so enabling just the interop tools returned an empty response for every page.
The existing test stubbed _tabId and called response.handle() directly, bypassing the tool handler where structured content is gated, so it passed while the tool returned nothing in practice.
| }); | ||
|
|
||
| it('reports the tab id when structured content is disabled', async () => { | ||
| await withMcpContext(async (_response, context) => { |
Collaborator
There was a problem hiding this comment.
You should be able to pass
withMcpContext(cb(), {
experimentalInteropTools: true,
experimentalStructuredContent: false,
})That will remove the need for the setup.
Contributor
Author
There was a problem hiding this comment.
Good call — dropped the ToolHandler setup and pass the flags through withMcpContext instead. Went with the third args param since that's where the ParsedArguments overrides land.
Lightning00Blade
left a comment
Collaborator
There was a problem hiding this comment.
Looks good with one comment for the test setup.
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.
Follow-up to the
get_tab_idside-thread in #2366. This doesn't look like a Puppeteer regression — I checked_tabIdagainst the pinned puppeteer-core 25.3.0 on real Chrome (launch and connect,browser.pages(),pages(true),newPage(), withhandleDevToolsAsPage: true) and it came back populated every time.What actually happens is that the handler only calls
response.setTabId(), so the id rides instructuredContentand nowhere else — andToolHandlerattachesstructuredContentto the result only when--experimental-structured-contentis set (ToolHandler.ts:287). The tool itself is gated behind--experimental-interop-tools, so turning on just the interop tools gives you an empty response for every page.src/bin/chrome-devtools.tsputs--experimentalStructuredContentin its default args, which is why it looks fine over the CLI but not when the server is driven over MCP.That's also why it passes in our test: it stubs
_tabIdand callsresponse.handle()directly, skipping the handler where the gate lives, then assertsresponseLinesis empty — which pins the missing output as expected behaviour.So the id now goes into the response text like every other tool, and
setTabIdstays for structured consumers. Reverting just the handler change fails the new test withexpected the tab id in the response, got:and an empty string — the reported symptom. I also handled the empty string Puppeteer documents as "unknown" rather than emitting a bareTab ID:.pages suite is green (50 tests), ToolHandler suite too.