Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

getLinks

Extract all hyperlinks from a webpage to collect URLs for analysis, navigation, or data gathering during browser automation tasks.

Instructions

Get all links from the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the getLinks tool in PlaywrightController. Extracts all anchor links (a[href]) from the page, returning array of {href, text, title?} using page.evaluate.
    async getLinks(): Promise<Array<{href: string, text: string, title?: string}>> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page links'); const links = await this.state.page?.evaluate(() => { const linkElements = Array.from(document.querySelectorAll('a[href]')); return linkElements.map(link => ({ href: (link as HTMLAnchorElement).href, text: link.textContent?.trim() || '', title: link.getAttribute('title') || undefined })); }); this.log('Links retrieved:', links?.length); return links || []; } catch (error: any) { console.error('Get links error:', error); throw new BrowserError('Failed to get links', 'Check if the page is loaded'); } }
  • Tool schema definition for getLinks, specifying no input parameters required.
    const GET_LINKS_TOOL: Tool = { name: "getLinks", description: "Get all links from the current page", inputSchema: { type: "object", properties: {}, required: [] } };
  • src/server.ts:529-529 (registration)
    Registration of the getLinks tool in the server's tools object for MCP capabilities.
    getLinks: GET_LINKS_TOOL,
  • src/server.ts:726-731 (registration)
    MCP tool call dispatch in server request handler that calls the controller's getLinks and returns JSON serialized results.
    case 'getLinks': { const links = await playwrightController.getLinks(); return { content: [{ type: "text", text: JSON.stringify(links, null, 2) }] }; }

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/jomon003/PlayMCP'

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