Skip to main content
Glama

set_cookies

Configure browser cookies to manage authentication, sessions, and user preferences during automated web interactions.

Instructions

Set cookies in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cookiesYes
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • Handler function that implements the set_cookies tool logic: gets the page, defaults cookie domain/path from current URL, normalizes cookies, calls page.setCookie(), handles errors, returns success with count and names.
    async ({ cookies, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { // Get the current page URL for domain defaulting const pageUrl = new URL(page.url()); const cookiesToSet = cookies.map((cookie: CookieParam) => ({ name: cookie.name, value: cookie.value, domain: cookie.domain ?? pageUrl.hostname, path: cookie.path ?? '/', expires: cookie.expires, httpOnly: cookie.httpOnly, secure: cookie.secure, sameSite: cookie.sameSite as 'Strict' | 'Lax' | 'None' | undefined, })); await page.setCookie(...cookiesToSet); return handleResult(ok({ set: cookies.length, cookies: cookiesToSet.map((c) => c.name), })); } catch (error) { return handleResult(err(normalizeError(error))); } }
  • Zod schema defining the input parameters for the set_cookies tool, including required cookies array and optional tabId.
    export const setCookiesSchema = z.object({ cookies: z.array(z.object({ name: z.string(), value: z.string(), domain: z.string().optional(), path: z.string().optional().default('/'), expires: z.number().optional().describe('Unix timestamp when cookie expires'), httpOnly: z.boolean().optional(), secure: z.boolean().optional(), sameSite: z.enum(['Strict', 'Lax', 'None']).optional(), })).min(1), tabId: tabIdSchema, });
  • Registration of the set_cookies tool on the MCP server within registerCookiesTools, specifying name, description, input schema shape, and handler function.
    server.tool( 'set_cookies', 'Set cookies in the browser', setCookiesSchema.shape, async ({ cookies, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { // Get the current page URL for domain defaulting const pageUrl = new URL(page.url()); const cookiesToSet = cookies.map((cookie: CookieParam) => ({ name: cookie.name, value: cookie.value, domain: cookie.domain ?? pageUrl.hostname, path: cookie.path ?? '/', expires: cookie.expires, httpOnly: cookie.httpOnly, secure: cookie.secure, sameSite: cookie.sameSite as 'Strict' | 'Lax' | 'None' | undefined, })); await page.setCookie(...cookiesToSet); return handleResult(ok({ set: cookies.length, cookies: cookiesToSet.map((c) => c.name), })); } catch (error) { return handleResult(err(normalizeError(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/andytango/puppeteer-mcp'

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