fix(patrol_mcp): pass device serial to screenshot command (fails with multiple devices attached)#3131
Merged
zoskar merged 2 commits intoJul 6, 2026
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Collaborator
|
@godzeit Thanks for the contribution! |
zoskar
approved these changes
Jul 6, 2026
zoskar
left a comment
Collaborator
There was a problem hiding this comment.
I pushed multi device support in general to TODO, thanks for contribution 💪
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.
Problem
The
screenshotMCP tool shells out to capture the device screen without ever targeting a specific device:adb exec-out screencap -p(no-s <serial>).xcrun simctl io booted screenshot ...(bootedinstead of the actual UDID).ScreenshotService.handleScreenshotRequest(Device? device)already receives thepatrol_cliDevicefor the active session, but only uses it to pick the platform (ScreenshotPlatform.fromDevice) — the device identity itself is discarded before the command is built.Repro (Android, 2+ devices/emulators attached — common when running parallel emulators)
With
-s <serial>both devices return a valid PNG; without it the tool call fails outright. On iOS the failure mode is worse — with 2+ booted simulators,bootedpicks whicheversimctlconsiders "the" booted device, which may silently be the wrong one instead of erroring.Verified live against
patrol_mcp0.1.4 while running Patrol against a production Flutter monorepo with parallel Android emulators.Fix
ScreenshotPlatformnow exposesargsFor(Device device)instead of a staticargslist, and builds the command with the device's identity:adb -s <device.id> exec-out screencap -pxcrun simctl io <device.id> screenshot --type=png /dev/stdout(Device.idis the simulator UDID on iOS, perios_test_backend.dart, which already doessimctl ... device.idinstead ofbooted)_captureScreenshotnow takes theDeviceand threads it through toargsFor.This aligns with how
patrol_cliitself already targets devices — e.g.android_test_backend.dartsets'ANDROID_SERIAL': device.idwhen running tests, andios_test_backend.dartpassesdevice.id(notbooted) tosimctl. The MCP screenshot tool was the odd one out.Related gap fixed in the same package:
native-treeWhile auditing
patrol_mcpfor the same class of bug,NativeTreeService._setupConnectioncallsAdb().forwardPorts(fromHost: port, toDevice: port)without adeviceargument. Theadbpackage'sforwardPortsalready accepts an optionaldeviceserial (seepackages/adb/lib/src/adb.dart) specifically to disambiguate when more than one device is attached. Passeddevice: device.idhere too, since it's the same root cause and a one-line fix in a file already touched by this class of bug.Changes
packages/patrol_mcp/lib/src/screenshot_service.dart— pass device serial/UDID toadb/simctl.packages/patrol_mcp/lib/src/native_tree_service.dart— pass device serial toAdb().forwardPorts.packages/patrol_mcp/CHANGELOG.md— unreleased entry.Verification
No
test/directory exists yet forpatrol_mcp, so no existing test coverage was touched; happy to add coverage if maintainers point me at the preferred pattern for exercisingProcess.startargs in this package.🤖 Generated with Claude Code