browser_get_cookie_by_name
Retrieve specific browser cookies by name to access authentication tokens, session data, or user preferences during web automation and testing workflows.
Instructions
Get a cookie by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the cookie to get |
Implementation Reference
- src/tools/cookieTools.ts:16-30 (registration)Registers the 'browser_get_cookie_by_name' tool using McpServer.tool(), including description, input schema, and inline handler function.server.tool( 'browser_get_cookie_by_name', 'Get a cookie by name', { name: z.string().describe('Name of the cookie to get'), }, async ({ name }) => { const driver = stateManager.getDriver(); const cookieService = new CookieService(driver); const cookieValue = await cookieService.getCookieByName(name); return { content: [{ type: 'text', text: `Cookie: ${cookieValue}` }], }; } );
- src/tools/cookieTools.ts:22-29 (handler)The tool handler function that retrieves the browser driver, creates a CookieService instance, fetches the cookie value by name, and returns it in the MCP response format.async ({ name }) => { const driver = stateManager.getDriver(); const cookieService = new CookieService(driver); const cookieValue = await cookieService.getCookieByName(name); return { content: [{ type: 'text', text: `Cookie: ${cookieValue}` }], }; }
- src/tools/cookieTools.ts:19-21 (schema)Zod schema defining the input parameter 'name' as a required string.{ name: z.string().describe('Name of the cookie to get'), },
- src/services/cookieService.ts:11-14 (helper)Helper method in CookieService class that uses Selenium WebDriver's manage().getCookie() to retrieve a specific cookie by name and returns its name-value object or null.async getCookieByName(name: string): Promise<any | null> { const cookie = await this.driver.manage().getCookie(name); return cookie ? { name: cookie.name, value: cookie.value } : null; }
- src/tools/index.ts:12-12 (registration)Higher-level registration call to registerCookieTools within the registerAllTools function.registerCookieTools(server, stateManager);