get_cookies
Retrieve cookies for the current page or any specified URL, with optional filtering by cookie name.
Instructions
Get cookies for the current page or a specific URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | URL to get cookies for (defaults to current page URL) | |
| name | No | Filter by cookie name | |
| apiKey | No | API key for authentication |
Implementation Reference
- src/tools/devtools-storage.ts:7-20 (handler)Handler function for the 'get_cookies' tool that sends a command via WebSocket bridge to get cookies for the current page or a specific URL, with optional name filter.
server.tool( 'get_cookies', 'Get cookies for the current page or a specific URL', { url: z.string().optional().describe('URL to get cookies for (defaults to current page URL)'), name: z.string().optional().describe('Filter by cookie name'), apiKey: z.string().optional().describe('API key for authentication'), }, async ({ url, name, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_cookies', params: { url, name }, apiKey }); if (!result.success) return { content: [{ type: 'text' as const, text: `Error: ${result.error?.message}` }], isError: true }; return { content: [{ type: 'text' as const, text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/devtools-storage.ts:10-14 (schema)Input schema for the 'get_cookies' tool with optional url, name, and apiKey parameters using Zod validation.
{ url: z.string().optional().describe('URL to get cookies for (defaults to current page URL)'), name: z.string().optional().describe('Filter by cookie name'), apiKey: z.string().optional().describe('API key for authentication'), }, - src/tools/devtools-storage.ts:7-20 (registration)Registration of the 'get_cookies' tool on the MCP server via server.tool() call in the registerDevtoolsStorageTools function.
server.tool( 'get_cookies', 'Get cookies for the current page or a specific URL', { url: z.string().optional().describe('URL to get cookies for (defaults to current page URL)'), name: z.string().optional().describe('Filter by cookie name'), apiKey: z.string().optional().describe('API key for authentication'), }, async ({ url, name, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_cookies', params: { url, name }, apiKey }); if (!result.success) return { content: [{ type: 'text' as const, text: `Error: ${result.error?.message}` }], isError: true }; return { content: [{ type: 'text' as const, text: JSON.stringify(result.data, null, 2) }] }; } ); - src/websocket-bridge.ts:63-103 (helper)The sendCommand helper on WebSocketBridge that sends the 'get_cookies' command (with params, apiKey) to the Chrome extension over WebSocket and returns the response.
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)); }); }