Skip to main content
Glama
webdriverio

WebDriverIO MCP Server

Official

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
NameRequiredDescriptionDefault
nameNoOptional cookie name to retrieve a specific cookie. If not provided, returns all cookies

Implementation Reference

  • 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}` }],
        };
      }
    };
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/webdriverio/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server