delete_cookies
Remove specific browser cookies by name to manage privacy, clear session data, or reset authentication states during automated browser testing.
Instructions
Delete cookies by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| names | Yes | Cookie names to delete | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/cookies.ts:96-138 (handler)The handler function that implements the delete_cookies tool. It retrieves the current page's cookies, filters those matching the provided names, and deletes them by overwriting with an expired cookie (empty value, expires=0).async ({ names, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { // Get all cookies first const allCookies = await page.cookies(); // Find cookies to delete const cookiesToDelete = allCookies.filter((cookie) => names.includes(cookie.name) ); // Delete each matching cookie const browserResult = await getBrowser(); if (browserResult.success) { const context = browserResult.data.defaultBrowserContext(); for (const cookie of cookiesToDelete) { await context.clearPermissionOverrides(); // Delete by setting empty value and expired date await page.setCookie({ name: cookie.name, value: '', domain: cookie.domain, path: cookie.path, expires: 0, }); } } return handleResult(ok({ deleted: cookiesToDelete.length, names: cookiesToDelete.map((c) => c.name), })); } catch (error) { return handleResult(err(normalizeError(error))); } }
- src/tools/cookies.ts:92-95 (registration)The registration of the delete_cookies tool on the MCP server, specifying name, description, input schema, and handler function.server.tool( 'delete_cookies', 'Delete cookies by name', deleteCookiesSchema.shape,
- src/schemas.ts:191-194 (schema)Zod schema defining the input for delete_cookies tool: array of cookie names to delete and optional tabId.export const deleteCookiesSchema = z.object({ names: z.array(z.string()).min(1).describe('Cookie names to delete'), tabId: tabIdSchema, });