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
| Name | Required | Description | Default |
|---|---|---|---|
| urls | No | URLs to get cookies for (uses current page URL if not specified) | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/cookies.ts:22-47 (handler)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))); }
- src/schemas.ts:172-175 (schema)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, });
- src/tools/cookies.ts:18-49 (registration)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);