get_cookies
Retrieve browser cookies from automated web sessions to manage authentication, track user state, or extract session data during testing and automation workflows.
Instructions
gets all cookies or a specific cookie by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Optional cookie name to retrieve a specific cookie. If not provided, returns all cookies |
Implementation Reference
- src/tools/cookies.tool.ts:17-50 (handler)The handler function that executes the 'get_cookies' tool logic. It interacts with the browser instance to retrieve either a specific cookie or all cookies.
export const getCookiesTool: ToolCallback = async ({ name}: { name?: string }): Promise<CallToolResult> => { try { const browser = getBrowser(); if (name) { // Get specific cookie by name const cookie = await browser.getCookies([name]); if (cookie.length === 0) { return { content: [{ type: 'text', text: `Cookie "${name}" not found` }], }; } return { content: [{ type: 'text', text: JSON.stringify(cookie[0], null, 2) }], }; } // Get all cookies const cookies = await browser.getCookies(); if (cookies.length === 0) { return { content: [{ type: 'text', text: 'No cookies found' }], }; } return { content: [{ type: 'text', text: JSON.stringify(cookies, null, 2) }], }; } catch (e) { return { isError: true, content: [{ type: 'text', text: `Error getting cookies: ${e}` }], }; } }; - src/tools/cookies.tool.ts:9-15 (schema)The schema definition for the 'get_cookies' tool, including its name, description, and input parameters.
export const getCookiesToolDefinition: ToolDefinition = { name: 'get_cookies', description: 'gets all cookies or a specific cookie by name', inputSchema: { name: z.string().optional().describe('Optional cookie name to retrieve a specific cookie. If not provided, returns all cookies'), }, }; - src/server.ts:119-119 (registration)Registration of the 'get_cookies' tool in the server application.
registerTool(getCookiesToolDefinition, getCookiesTool);