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
| Name | Required | Description | Default |
|---|---|---|---|
| context | No |
Implementation Reference
- src/mcp_web_browser/server.py:245-277 (handler)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}")
- src/mcp_web_browser/server.py:245-245 (registration)The @mcp.tool() decorator registers the get_page_links function as an MCP tool.@mcp.tool()