Skip to main content
Glama
williamvd4

Playwright Server

by williamvd4

playwright_get_html_content

Extract HTML content from web pages using CSS selectors for data scraping, content analysis, or automated testing purposes.

Instructions

Get the HTML content of the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element

Implementation Reference

  • The GetHtmlContentToolHandler class provides the core implementation for retrieving the HTML content of a page element using Playwright's locator.inner_html() method.
    class GetHtmlContentToolHandler(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"]
            selector = arguments.get("selector")
            html_content = await page.locator(selector).inner_html()
            return [types.TextContent(type="text", text=f"HTML content of element with selector {selector}: {html_content}")]
  • The input schema definition for the tool, specifying a required 'selector' parameter as a CSS selector string.
    types.Tool(
        name="playwright_get_html_content",
        description="Get the HTML content of the page",
         inputSchema={
            "type": "object",
            "properties": {
                "selector": {"type": "string", "description": "CSS selector for the element"}
            },
            "required": ["selector"]
        }
    )
  • Registration of tool handlers in a dictionary, including the instance for 'playwright_get_html_content' which is used by the call_tool handler.
    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 but offers minimal behavioral insight. It states what the tool does but doesn't disclose important traits like whether it waits for elements to load, handles errors if the selector isn't found, returns full HTML or just outerHTML, or if it's safe for repeated use. The description adds little beyond the basic action.

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 essential information and doesn't include any unnecessary elaboration. Every word earns its place in communicating the core functionality.

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 the tool has no annotations and no output schema, the description is insufficiently complete. It doesn't explain what format the HTML content returns in, whether it includes the entire page or just the selected element, or any error conditions. For a tool interacting with web pages, more context about behavior and output is needed.

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?

The input schema has 100% description coverage, with the 'selector' parameter clearly documented as 'CSS selector for the element'. The description doesn't add any additional meaning about the parameter beyond what the schema already provides, such as selector syntax examples or special cases. The baseline score of 3 is appropriate given the schema does the heavy lifting.

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 ('Get') and resource ('HTML content of the page'), making the purpose immediately understandable. It distinguishes from sibling tools like 'playwright_get_text_content' by specifying HTML rather than text content. However, it doesn't explicitly contrast with other siblings like 'playwright_evaluate' which might also retrieve content.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose this over 'playwright_get_text_content' for text-only needs, or 'playwright_evaluate' for more complex DOM interactions. There's no context about 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/williamvd4/playwright-plus-python-mcp'

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