Skip to main content
Glama
AdsPower

AdsPower LocalAPI MCP Server

Official

connect-browser-with-ws

Link a browser by establishing a WebSocket connection using its URL, enabling interaction through the AdsPower LocalAPI MCP Server for profile management and automation tasks.

Instructions

Connect the browser with the ws url

Input Schema

NameRequiredDescriptionDefault
serialNumberNoThe serial number of the browser to connect
userIdNoThe browser id of the browser to connect
wsUrlYesThe ws url of the browser, get from the open-browser tool content `ws.puppeteer`

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "serialNumber": { "description": "The serial number of the browser to connect", "type": "string" }, "userId": { "description": "The browser id of the browser to connect", "type": "string" }, "wsUrl": { "description": "The ws url of the browser, get from the open-browser tool content `ws.puppeteer`", "type": "string" } }, "required": [ "wsUrl" ], "type": "object" }

Implementation Reference

  • The handler function for the 'connect-browser-with-ws' tool. It takes wsUrl, connects using the browser utility, and returns success or error message.
    async connectBrowserWithWs({ wsUrl }: CreateAutomationParams) { try { await browser.connectBrowserWithWs(wsUrl); return `Browser connected successfully with: ${wsUrl}`; } catch (error) { return `Failed to connect browser with: ${error?.toString()}`; } },
  • Registration of the 'connect-browser-with-ws' tool on the MCP server, specifying name, description, input schema, and wrapped handler.
    server.tool('connect-browser-with-ws', 'Connect the browser with the ws url', schemas.createAutomationSchema.shape, wrapHandler(automationHandlers.connectBrowserWithWs));
  • Zod schema defining the input parameters for the connect-browser-with-ws tool, primarily wsUrl with optional userId and serialNumber.
    createAutomationSchema: z.object({ userId: z.string().optional().describe('The browser id of the browser to connect'), serialNumber: z.string().optional().describe('The serial number of the browser to connect'), wsUrl: z.string().describe('The ws url of the browser, get from the open-browser tool content `ws.puppeteer`') }).strict(),
  • Helper method in BrowserBase class that performs the actual WebSocket connection to the browser using Playwright's chromium.connectOverCDP.
    async connectBrowserWithWs(wsUrl: string) { this.browser = await chromium.connectOverCDP(wsUrl); const defaultContext = this.browser.contexts()[0]; this.page = defaultContext.pages()[0]; await this.page.bringToFront().catch((error) => { console.error('Failed to bring page to front', error); }); }

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/AdsPower/local-api-mcp-typescript'

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