get_web_screenshots
Retrieve screenshots from web browsing sessions to review what AI agents saw and did during task execution.
Instructions
Retrieve screenshots captured during a web browsing session.
Each browsing session saves screenshots of the pages visited. Use this to
review what the AI agent saw and did during task execution.
Args:
session_id: Session ID returned from browse_web or check_web_task
Returns:
Dictionary containing:
- ok: Boolean indicating success
- screenshots: List of screenshot file paths
- session_id: The session identifier
- count: Number of screenshots found
- error: Error message (if session not found)
Example:
get_web_screenshots("20251017_143022_a1b2c3d4")
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes |
Implementation Reference
- server.py:90-143 (handler)The @mcp.tool() decorated handler function that implements the get_web_screenshots tool logic: constructs the session screenshot directory, checks existence, globs PNG files, sorts and returns their relative paths along with metadata.@mcp.tool() async def get_web_screenshots(session_id: str) -> dict[str, Any]: """ Retrieve screenshots captured during a web browsing session. Each browsing session saves screenshots of the pages visited. Use this to review what the AI agent saw and did during task execution. Args: session_id: Session ID returned from browse_web or check_web_task Returns: Dictionary containing: - ok: Boolean indicating success - screenshots: List of screenshot file paths - session_id: The session identifier - count: Number of screenshots found - error: Error message (if session not found) Example: get_web_screenshots("20251017_143022_a1b2c3d4") """ logger.info(f"Retrieving screenshot history for session: {session_id}") try: from browser_agent import SCREENSHOT_OUTPUT_DIR screenshot_dir = Path(SCREENSHOT_OUTPUT_DIR) / session_id if not screenshot_dir.exists(): return { "ok": False, "error": f"No screenshots found for session {session_id}" } screenshots = sorted([ str(p.relative_to(screenshot_dir.parent)) for p in screenshot_dir.glob("*.png") ]) return { "ok": True, "screenshots": screenshots, "session_id": session_id, "count": len(screenshots) } except Exception as e: logger.error(f"Error retrieving screenshots: {e}") return { "ok": False, "error": str(e) }
- server.py:92-111 (schema)The tool's docstring defines the input schema (session_id: str), output format (dict with ok, screenshots list, etc.), and usage example.""" Retrieve screenshots captured during a web browsing session. Each browsing session saves screenshots of the pages visited. Use this to review what the AI agent saw and did during task execution. Args: session_id: Session ID returned from browse_web or check_web_task Returns: Dictionary containing: - ok: Boolean indicating success - screenshots: List of screenshot file paths - session_id: The session identifier - count: Number of screenshots found - error: Error message (if session not found) Example: get_web_screenshots("20251017_143022_a1b2c3d4") """
- browser_agent.py:32-33 (helper)Constant SCREENSHOT_OUTPUT_DIR defines the base directory for storing screenshots, configurable via env var or defaulting to temp dir. Used by get_web_screenshots to locate session screenshots._default_screenshot_dir = os.path.join(tempfile.gettempdir(), "gemini-browser-agent", "output_screenshots") SCREENSHOT_OUTPUT_DIR = os.environ.get("SCREENSHOT_OUTPUT_DIR", _default_screenshot_dir)