Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_screenshot

Capture screenshots of web pages or specific elements using CSS selectors for documentation, testing, or visual verification 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 the 'playwright_screenshot' tool: checks for active session, locates element or full page, takes screenshot, base64 encodes it, and returns 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")]
  • JSON Schema definition for the tool's input parameters returned by list_tools(): requires 'name', optional '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, which is used by the @server.call_tool() handler to dispatch tool calls.
    tool_handlers = {
        "playwright_navigate": NavigateToolHandler(),
        "playwright_screenshot": ScreenshotToolHandler(),
        "playwright_click": ClickToolHandler(),
        "playwright_fill": FillToolHandler(),
        "playwright_evaluate": EvaluateToolHandler(),
        "playwright_click_text": ClickTextToolHandler(),
        "playwright_get_text_content": GetTextContentToolHandler(),
        "playwright_get_html_content": GetHtmlContentToolHandler(),
        "playwright_new_session":NewSessionToolHandler(),
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action but doesn't describe what happens after the screenshot is taken (e.g., where it's saved, format, size limits), whether it requires specific page states, or potential side effects like pausing execution. This leaves significant gaps for a mutation-like operation.

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, efficient sentence with zero waste. It's front-loaded with the core action and immediately specifies the scope, making it easy to parse quickly.

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?

For a tool with no annotations, no output schema, and incomplete parameter documentation, the description is inadequate. It doesn't cover behavioral aspects like output handling (e.g., file paths, errors), usage context, or differentiation from siblings, leaving the agent with insufficient information for reliable use.

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 minimal value beyond the schema by implying 'name' is for the screenshot and 'selector' targets elements, but it doesn't clarify 'name' usage (e.g., filename prefix) or provide examples. With low schema coverage, this doesn't fully compensate.

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 target ('current page or a specific element'), providing a specific verb+resource. However, it doesn't explicitly differentiate from sibling tools like playwright_get_html_content or playwright_get_text_content, which also capture page content but in different formats.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention when to use playwright_screenshot instead of playwright_get_html_content for capturing visual vs. structural content, nor does it specify prerequisites like requiring a page to be loaded first.

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/blackwhite084/playwright-plus-python-mcp'

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