Skip to main content
Glama
AdsPower

AdsPower LocalAPI MCP Server

Official

connect-browser-with-ws

Establish a WebSocket connection to an AdsPower browser instance using its WebSocket URL, enabling remote control and automation of browser profiles.

Instructions

Connect the browser with the ws url

Input Schema

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

Implementation Reference

  • The main handler function for the 'connect-browser-with-ws' tool. It receives the wsUrl parameter and delegates the connection to the browserBase instance, handling success/error responses.
    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()}`; } },
  • Zod schema defining input parameters for the tool: optional userId/serialNumber and required wsUrl.
    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(),
  • Registers the tool with the MCP server, specifying name, description, input schema, and the wrapped handler function.
    server.tool('connect-browser-with-ws', 'Connect the browser with the ws url', schemas.createAutomationSchema.shape, wrapHandler(automationHandlers.connectBrowserWithWs));
  • Supporting method in BrowserBase class that performs the actual WebSocket connection to an existing browser using Playwright's 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