screenshot
Capture a PNG screenshot of the current browser view and return it as base64 encoded data for integration into automation workflows.
Instructions
Return a PNG screenshot as base64.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/server.py:189-192 (registration)The 'screenshot' tool is registered as an MCP tool via @mcp.tool() decorator. The handler function calls browser.screenshot() via the _run helper.
@mcp.tool() def screenshot() -> dict[str, str]: """Return a PNG screenshot as base64.""" return _run("screenshot", browser.screenshot) - Actual implementation of the screenshot logic in BrowserManager.screenshot(). Takes a PNG screenshot via Selenium's get_screenshot_as_png() and returns it as a base64-encoded string wrapped in a ScreenshotResult model.
def screenshot(self) -> ScreenshotResult: with self._lock: png = self._require_driver().get_screenshot_as_png() return ScreenshotResult(base64_png=base64.b64encode(png).decode("ascii")) - ScreenshotResult Pydantic model defining the return type: mime_type (default 'image/png') and base64_png (the base64-encoded screenshot data).
class ScreenshotResult(BaseModel): mime_type: str = "image/png" base64_png: str - The _run helper function used by all tool handlers to execute browser actions, convert results via _as_dict, and handle exceptions.
def _run(action: str, func: Any, *args: Any, **kwargs: Any) -> Any: try: return _as_dict(func(*args, **kwargs)) except BrowserError: logger.exception("Browser action failed: %s", action) raise except Exception as exc: logger.exception("Unexpected Selenium MCP error during %s", action) raise BrowserError(f"{action} failed: {exc}") from exc - The 'save_screenshot' tool - a related tool that saves the screenshot to a server-local file path rather than returning base64 data.
@mcp.tool() def save_screenshot(path: str) -> dict[str, str]: """Save a PNG screenshot to a server-local path and return the path.""" return _run("save_screenshot", browser.save_screenshot, path)