browser_get_cookie_by_name
Retrieve specific browser cookies by name to access authentication tokens, session data, or user preferences during web automation tasks.
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:22-29 (handler)The handler function for the 'browser_get_cookie_by_name' tool. It gets the WebDriver from stateManager, creates a CookieService instance, calls getCookieByName on it, and returns the result as text content.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 input schema defining the 'name' parameter as a required string.{ name: z.string().describe('Name of the cookie to get'), },
- src/tools/cookieTools.ts:16-30 (registration)Registration of the 'browser_get_cookie_by_name' tool on the MCP server using server.tool(), including description, schema, and handler.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/services/cookieService.ts:11-14 (helper)Core helper method in CookieService class that retrieves a cookie by name using Selenium WebDriver's getCookie method and returns an object with name and value 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; }