Skip to main content
Glama

get_cookies

Retrieve browser cookies from the current page or specified URLs to enable session management and authentication for automated web interactions.

Instructions

Get cookies for the current page or specified URLs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlsNoURLs to get cookies for (uses current page URL if not specified)
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • The handler function for the get_cookies tool. It retrieves the page for the given tabId, fetches cookies using Puppeteer's page.cookies() method for specified URLs or current page, maps the cookies to a standardized output format, and handles errors appropriately.
    async ({ urls, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { const cookies = await page.cookies(...(urls ?? [])); return handleResult(ok({ cookies: cookies.map((cookie) => ({ name: cookie.name, value: cookie.value, domain: cookie.domain, path: cookie.path, expires: cookie.expires, httpOnly: cookie.httpOnly, secure: cookie.secure, sameSite: cookie.sameSite, })), })); } catch (error) { return handleResult(err(normalizeError(error))); }
  • Zod schema defining the input parameters for the get_cookies tool: optional array of URLs and optional tabId.
    export const getCookiesSchema = z.object({ urls: z.array(z.string().url()).optional().describe('URLs to get cookies for (uses current page URL if not specified)'), tabId: tabIdSchema, });
  • Registers the get_cookies tool on the MCP server, providing the tool name, description, input schema, and handler function.
    server.tool( 'get_cookies', 'Get cookies for the current page or specified URLs', getCookiesSchema.shape, async ({ urls, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { const cookies = await page.cookies(...(urls ?? [])); return handleResult(ok({ cookies: cookies.map((cookie) => ({ name: cookie.name, value: cookie.value, domain: cookie.domain, path: cookie.path, expires: cookie.expires, httpOnly: cookie.httpOnly, secure: cookie.secure, sameSite: cookie.sameSite, })), })); } catch (error) { return handleResult(err(normalizeError(error))); } } );
  • src/server.ts:28-28 (registration)
    Calls registerCookiesTools to register the cookies tools including get_cookies on the main MCP server instance.
    registerCookiesTools(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