Skip to main content
Glama
random-robbie

MCP Web Browser Server

extract_text_content

Extract text content from web pages using CSS selectors to target specific elements for data collection and analysis.

Instructions

Extract text content from the current page, optionally using a CSS selector.

Args:
    selector: Optional CSS selector to target specific elements
    context: Optional context object for logging (ignored)

Returns:
    Extracted text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorNo
contextNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'extract_text_content' tool. It is decorated with @mcp.tool(), which also handles registration and schema inference from the type hints and docstring. Extracts visible text content from the current Playwright page, either from the entire body or specific elements via CSS selector.
    @mcp.tool()
    async def extract_text_content(
        selector: Optional[str] = None, 
        context: Optional[Any] = None
    ) -> str:
        """
        Extract text content from the current page, optionally using a CSS selector.
        
        Args:
            selector: Optional CSS selector to target specific elements
            context: Optional context object for logging (ignored)
        
        Returns:
            Extracted text content
        """
        global _current_page
        
        if not _current_page:
            raise ValueError("No page is currently loaded. Use browse_to first.")
        
        try:
            if selector:
                # If selector is provided, extract text from matching elements
                elements = await _current_page.query_selector_all(selector)
                text_content = "\n".join([await el.inner_text() for el in elements])
                print(f"Extracted text from selector: {selector}", file=sys.stderr)
            else:
                # If no selector, extract all visible text from the page
                text_content = await _current_page.inner_text('body')
            
            return text_content
        
        except Exception as e:
            print(f"Error extracting text: {e}", file=sys.stderr)
            raise ValueError(f"Error extracting text: {e}")
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the tool extracts text and that 'context' is ignored, but lacks details on behavioral traits such as error handling (e.g., if selector fails), performance (e.g., timeouts), or output format specifics (though output schema exists). It doesn't disclose permissions, rate limits, or side effects.

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 front-loaded with the core purpose in the first sentence, followed by structured Args and Returns sections. Every sentence earns its place by explaining parameters and return value efficiently, with no redundant information.

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

Completeness4/5

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

Given 2 parameters with 0% schema coverage, no annotations, and an output schema (which handles return values), the description is mostly complete. It covers purpose and parameter semantics adequately but lacks behavioral details like error cases or performance constraints, which would be beneficial for a tool interacting with web pages.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining 'selector' as 'Optional CSS selector to target specific elements' and 'context' as 'Optional context object for logging (ignored)', which clarifies their purposes beyond the schema's basic types. However, it doesn't detail selector syntax or context structure.

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

Purpose5/5

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

The description clearly states the verb 'extract' and resource 'text content from the current page', specifying it can optionally use a CSS selector. This distinguishes it from siblings like browse_to (navigation), click_element (interaction), get_page_links (link extraction), get_page_screenshots (visual capture), and input_text (text entry).

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

Usage Guidelines3/5

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

The description implies usage by mentioning 'optionally using a CSS selector' and 'from the current page', suggesting it's for extracting text after navigation. However, it doesn't explicitly state when to use this versus alternatives like get_page_links (for links) or when not to use it (e.g., for non-text content). No explicit alternatives or exclusions are provided.

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/random-robbie/mcp-web-browser'

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