Skip to main content
Glama
williamvd4

Playwright Server

by williamvd4

playwright_screenshot

Capture screenshots of web pages or specific elements using browser automation for documentation, testing, or monitoring purposes.

Instructions

Take a screenshot of the current page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
selectorNoCSS selector for element to screenshot,null is full page

Implementation Reference

  • Implements the core logic for taking screenshots of the current page or a specific element using Playwright, encoding the image as base64 and returning it as ImageContent.
    class ScreenshotToolHandler(ToolHandler):
        async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            if not self._sessions:
                return [types.TextContent(type="text", text="No active session. Please create a new session first.")]
            session_id = list(self._sessions.keys())[-1]
            page = self._sessions[session_id]["page"]
            name = arguments.get("name")
            selector = arguments.get("selector")
            # full_page = arguments.get("fullPage", False)
            if selector:
                element = await page.locator(selector)
                await element.screenshot(path=f"{name}.png")
            else:
                await page.screenshot(path=f"{name}.png", full_page=True)
            with open(f"{name}.png", "rb") as image_file:
                encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
            os.remove(f"{name}.png")
            return [types.ImageContent(type="image", data=encoded_string, mimeType="image/png")]
  • Defines the JSON schema for the tool's input parameters: 'name' (required, string for filename) and 'selector' (optional CSS selector).
    types.Tool(
        name="playwright_screenshot",
        description="Take a screenshot of the current page or a specific element",
        inputSchema={
            "type": "object",
            "properties": {
                "name": {"type": "string"},
                "selector": {"type": "string", "description": "CSS selector for element to screenshot,null is full page"},
            },
            "required": ["name"]
        }
    ),
  • Registers the ScreenshotToolHandler instance in the tool_handlers dictionary for dispatching tool calls.
    "playwright_screenshot": ScreenshotToolHandler(),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states what the tool does but doesn't disclose critical traits like whether it requires an active browser session, if it saves files locally/remotely, error handling, or performance implications. The description is functional but lacks transparency about operational behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's front-loaded with the core action and efficiently specifies the scope ('current page or a specific element'), making it easy to parse and understand immediately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and incomplete parameter documentation (50% schema coverage), the description is inadequate. It doesn't explain what the tool returns (e.g., file path, base64 data), error conditions, or dependencies on other tools like playwright_navigate. For a screenshot tool with behavioral complexity, this leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50% (only 'selector' has a description). The description adds no parameter-specific semantics beyond implying 'name' might be for the screenshot file and 'selector' for element targeting. It doesn't clarify format for 'name' (e.g., file path/extension) or default behavior when 'selector' is omitted, leaving gaps despite some schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Take a screenshot') and the target ('current page or a specific element'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from potential screenshot-related siblings (none exist in the provided list), so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description offers no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a page loaded), exclusions, or comparisons with other tools like playwright_get_html_content for content capture. This leaves the agent without contextual usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/williamvd4/playwright-plus-python-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server