Skip to main content
Glama

get_page_links

Extract all links from a webpage using the MCP Web Browser Server. Retrieve a list of URLs for navigation, analysis, or content scraping via API integration.

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

Implementation Reference

  • The main handler function for the 'get_page_links' tool. Decorated with @mcp.tool() which registers it with the FastMCP server. Extracts all hyperlinks (href attributes from <a> tags) from the currently loaded page using Playwright's evaluate method to run JavaScript.
    @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}")
  • The @mcp.tool() decorator registers the get_page_links function as an MCP tool.
    @mcp.tool()

Other Tools

Related 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