Skip to main content
Glama
random-robbie

MCP Web Browser Server

get_page_links

Extract all hyperlinks from a webpage to analyze connections, gather URLs, or process web content systematically.

Instructions

Extract all links from the current page.

Args:
    context: Optional context object for logging (ignored)

Returns:
    List of links found on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_page_links' tool. It uses Playwright to evaluate JavaScript on the current page to extract all href attributes from 'a' elements and returns them as a list of strings. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def get_page_links(context: Optional[Any] = None) -> list[str]:
        """
        Extract all links from the current page.
        
        Args:
            context: Optional context object for logging (ignored)
        
        Returns:
            List of links found on the page
        """
        global _current_page
        
        if not _current_page:
            raise ValueError("No page is currently loaded. Use browse_to first.")
        
        try:
            # Use JavaScript to extract all links
            links = await _current_page.evaluate("""
                () => {
                    const links = document.querySelectorAll('a');
                    return Array.from(links).map(link => link.href);
                }
            """)
            
            print(f"Extracted {len(links)} links from the page", file=sys.stderr)
            
            return links
        
        except Exception as e:
            print(f"Error extracting links: {e}", file=sys.stderr)
            raise ValueError(f"Error extracting links: {e}")

Tool Definition Quality

Score is being calculated. Check back soon.

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