fix(mcp): avoid inline screenshot blobs in tool results
browser_get_state and browser_screenshot were returning inline PNG blobs in MCP tool results. Clients that replay tool history back through Anthropic can trip Could not process image on every later turn once that screenshot payload lands in the conversation.
This stores MCP screenshots as temporary PNG files and returns the local path in the JSON payload instead of inlining base64 image data. I also taught the in-repo MCP client to lift image blocks into ActionResult.images so MCP image results still flow through the browser-use message pipeline without getting stringified into prompt text.
Tests:
pytest tests/ci/test_mcp_screenshot_results.py -qpytest tests/ci/test_file_system_llm_integration.py -q -k "image_stored_in_message_manager or agent_message_prompt_includes_images or image_end_to_end"
Fixes #4742
Summary by cubic
Stop inlining screenshot base64 in MCP tool results. Screenshots are saved to temp files, returned as local paths, and cleaned up on successful session close to avoid Anthropic “Could not process image” errors when replaying tool history. Fixes #4742.
- Bug Fixes
browser_get_stateandbrowser_screenshotwrite PNGs to a temp dir and returnscreenshot_pathin JSON; no base64 inlined.- Server stores screenshots in a dedicated temp dir, deletes them on successful close (warns if a file can’t be removed), and preserves files/state if close fails for retry.
- Updated tool descriptions to reflect path-based screenshot results.
- MCP client lifts
types.ImageContentintoActionResult.images(with correct extensions) and keeps text inextracted_content. - Added tests for file-backed screenshots, cleanup on close, preservation on close failure, and client image extraction.