set_cookie
Set a browser cookie with specified name, value, domain, path, and security flags for session management or authentication.
Instructions
Set a cookie
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Cookie name | |
| value | Yes | Cookie value | |
| url | No | URL to associate the cookie with | |
| domain | No | Cookie domain | |
| path | No | Cookie path | |
| secure | No | Secure flag | |
| httpOnly | No | HttpOnly flag | |
| sameSite | No | SameSite attribute | |
| expirationDate | No | Expiration as Unix timestamp in seconds | |
| apiKey | No | API key for authentication |
Implementation Reference
- src/tools/devtools-storage.ts:20-22 (registration)The tool 'set_cookie' is registered with the MCP server via server.tool() in the registerDevtoolsStorageTools function.
); server.tool( - src/tools/devtools-storage.ts:37-42 (handler)The handler function for 'set_cookie' which sends a 'set_cookie' command via the WebSocket bridge and returns the result.
async ({ apiKey, ...params }) => { const result = await bridge.sendCommand({ command: 'set_cookie', params, apiKey }); if (!result.success) return { content: [{ type: 'text' as const, text: `Error: ${result.error?.message}` }], isError: true }; return { content: [{ type: 'text' as const, text: `Cookie "${params.name}" set` }] }; } ); - src/tools/devtools-storage.ts:25-35 (schema)Zod schema defining input parameters for the 'set_cookie' tool: name, value, url, domain, path, secure, httpOnly, sameSite, expirationDate, and apiKey.
{ name: z.string().describe('Cookie name'), value: z.string().describe('Cookie value'), url: z.string().optional().describe('URL to associate the cookie with'), domain: z.string().optional().describe('Cookie domain'), path: z.string().optional().describe('Cookie path'), secure: z.boolean().optional().describe('Secure flag'), httpOnly: z.boolean().optional().describe('HttpOnly flag'), sameSite: z.enum(['no_restriction', 'lax', 'strict']).optional().describe('SameSite attribute'), expirationDate: z.number().optional().describe('Expiration as Unix timestamp in seconds'), apiKey: z.string().optional().describe('API key for authentication'), - src/websocket-bridge.ts:63-103 (helper)The WebSocketBridge.sendCommand method is the helper that dispatches the 'set_cookie' command to the Chrome extension over WebSocket.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); } - src/tools/index.ts:42-55 (registration)The registration function that contains 'set_cookie' is invoked in registerAllTools, which is the central tool registration entry point.
registerDevtoolsStorageTools(server, bridge); registerDevtoolsConsoleTools(server, bridge); registerAccessibilityTools(server, bridge); registerEmulationTools(server, bridge); registerElementTools(server, bridge); registerAuditTools(server, bridge); registerInteractionTools(server, bridge); registerMonitoringTools(server, bridge); registerQaTools(server, bridge); registerGestureTools(server, bridge); registerMacroTools(server, bridge); registerVisualRegressionTools(server, bridge); }