pilot_set_cookie
Set a cookie on the current page's domain for authentication, testing, or session management. Specify cookie name and value to manually configure browser state.
Instructions
Set a cookie on the current page's domain with a given name and value. Use when the user wants to manually set a cookie for authentication, testing, or session management. The cookie is set on the domain of the currently active page. For bulk cookie import from a real browser, use pilot_import_cookies.
Parameters:
name: Cookie name (e.g., "session_id", "theme")
value: Cookie value (e.g., "abc123", "dark")
Returns: Confirmation with the cookie name (value is redacted for security).
Errors:
"Cannot set cookie without a page": Navigate to a URL first with pilot_navigate.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Cookie name | |
| value | Yes | Cookie value |
Implementation Reference
- src/tools/settings.ts:14-75 (registration)Registration function registerSettingsTools that registers 'pilot_set_cookie' (and 'pilot_resize') on the MCP server. The registration is at line 42-75.
export function registerSettingsTools(server: McpServer, bm: BrowserManager) { server.tool( 'pilot_resize', `Set the browser viewport size in pixels to simulate different screen resolutions. Use when the user wants to test responsive layouts, simulate a mobile or tablet screen, or change the visible area of the page. For multi-viewport screenshots, use pilot_responsive instead. Parameters: - width: Viewport width in pixels (e.g., 1280 for desktop, 375 for mobile) - height: Viewport height in pixels (e.g., 720 for desktop, 812 for mobile) Returns: Confirmation with the new viewport dimensions. Errors: None — any valid pixel dimensions are accepted.`, { width: z.number().describe('Viewport width in pixels'), height: z.number().describe('Viewport height in pixels'), }, async ({ width, height }) => { await bm.ensureBrowser(); try { await bm.setViewport(width, height); return { content: [{ type: 'text' as const, text: `Viewport set to ${width}x${height}` }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } ); server.tool( 'pilot_set_cookie', `Set a cookie on the current page's domain with a given name and value. Use when the user wants to manually set a cookie for authentication, testing, or session management. The cookie is set on the domain of the currently active page. For bulk cookie import from a real browser, use pilot_import_cookies. Parameters: - name: Cookie name (e.g., "session_id", "theme") - value: Cookie value (e.g., "abc123", "dark") Returns: Confirmation with the cookie name (value is redacted for security). Errors: - "Cannot set cookie without a page": Navigate to a URL first with pilot_navigate.`, { name: z.string().describe('Cookie name'), value: z.string().describe('Cookie value'), }, async ({ name, value }) => { await bm.ensureBrowser(); try { const page = bm.getPage(); const url = new URL(page.url()); await page.context().addCookies([{ name, value, domain: url.hostname, path: '/', }]); return { content: [{ type: 'text' as const, text: `Cookie set: ${name}=****` }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } ); - src/tools/settings.ts:59-74 (handler)The handler function for pilot_set_cookie. It gets the current page, extracts the hostname from the URL, and uses Playwright's page.context().addCookies() to set the cookie with name, value, domain (current hostname), and path '/'.
async ({ name, value }) => { await bm.ensureBrowser(); try { const page = bm.getPage(); const url = new URL(page.url()); await page.context().addCookies([{ name, value, domain: url.hostname, path: '/', }]); return { content: [{ type: 'text' as const, text: `Cookie set: ${name}=****` }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } - src/tools/settings.ts:55-58 (schema)Zod schema for pilot_set_cookie inputs: 'name' (z.string) and 'value' (z.string).
{ name: z.string().describe('Cookie name'), value: z.string().describe('Cookie value'), }, - src/tools/register.ts:84-84 (registration)Where registerSettingsTools is called to register the tool on the server.
registerSettingsTools(effectiveServer, bm);