Skip to main content
Glama
andytango
by andytango

navigate

Directs a browser to load a specific webpage, allowing automation of web navigation tasks with configurable loading conditions and timeouts.

Instructions

Navigate to a URL in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to navigate to
waitUntilNoWhen to consider navigation complete
timeoutNoTimeout in milliseconds
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • The handler function for the 'navigate' tool. It retrieves the page for the given tabId, navigates to the URL using page.goto(), handles navigation responses, errors like timeouts and failed HTTP statuses, and returns the final URL, title, and status.
    async ({ url, waitUntil, timeout, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const timeoutMs = timeout ?? getDefaultTimeout(); try { const response = await page.goto(url, { waitUntil: (waitUntil ?? 'load') as WaitUntilOption, timeout: timeoutMs, }); if (!response) { return handleResult(err(navigationFailed(url, 'No response received'))); } const status = response.status(); if (status >= 400) { return handleResult(err(navigationFailed(url, `HTTP ${status}`))); } return handleResult(ok({ url: page.url(), title: await page.title(), status, })); } catch (error) { if (error instanceof Error && error.message.includes('timeout')) { return handleResult(err(navigationTimeout(url, timeoutMs))); } return handleResult(err(normalizeError(error))); } }
  • Zod schema defining the input parameters for the 'navigate' tool: required URL, optional waitUntil, timeout, and tabId.
    export const navigateSchema = z.object({ url: z.string().url().describe('URL to navigate to'), waitUntil: waitUntilSchema.describe('When to consider navigation complete'), timeout: timeoutSchema, tabId: tabIdSchema, });
  • Registration of the 'navigate' tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool( 'navigate', 'Navigate to a URL in the browser', navigateSchema.shape, async ({ url, waitUntil, timeout, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const timeoutMs = timeout ?? getDefaultTimeout(); try { const response = await page.goto(url, { waitUntil: (waitUntil ?? 'load') as WaitUntilOption, timeout: timeoutMs, }); if (!response) { return handleResult(err(navigationFailed(url, 'No response received'))); } const status = response.status(); if (status >= 400) { return handleResult(err(navigationFailed(url, `HTTP ${status}`))); } return handleResult(ok({ url: page.url(), title: await page.title(), status, })); } catch (error) { if (error instanceof Error && error.message.includes('timeout')) { return handleResult(err(navigationTimeout(url, timeoutMs))); } return handleResult(err(normalizeError(error))); } } );
  • src/server.ts:23-23 (registration)
    High-level registration call that includes the 'navigate' tool among navigation tools.
    registerNavigationTools(server);

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/andytango/puppeteer-mcp'

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