Skip to main content
Glama
andytango
by andytango

set_cookies

Configure browser cookies for web automation tasks, enabling session management and authentication during automated browsing sessions.

Instructions

Set cookies in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cookiesYes
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • The handler function for the 'set_cookies' tool. It gets the page for the operation, normalizes cookie parameters using the current page URL for defaults, sets the cookies using Puppeteer's page.setCookie method, and returns the number of cookies set and their names.
    async ({ cookies, tabId }) => {
      const pageResult = await getPageForOperation(tabId);
      if (!pageResult.success) {
        return handleResult(pageResult);
      }
    
      const page = pageResult.data;
    
      try {
        // Get the current page URL for domain defaulting
        const pageUrl = new URL(page.url());
    
        const cookiesToSet = cookies.map((cookie: CookieParam) => ({
          name: cookie.name,
          value: cookie.value,
          domain: cookie.domain ?? pageUrl.hostname,
          path: cookie.path ?? '/',
          expires: cookie.expires,
          httpOnly: cookie.httpOnly,
          secure: cookie.secure,
          sameSite: cookie.sameSite as 'Strict' | 'Lax' | 'None' | undefined,
        }));
    
        await page.setCookie(...cookiesToSet);
    
        return handleResult(ok({
          set: cookies.length,
          cookies: cookiesToSet.map((c) => c.name),
        }));
      } catch (error) {
        return handleResult(err(normalizeError(error)));
      }
    }
  • Zod schema defining the input parameters for the set_cookies tool, including an array of cookies with fields like name, value, domain, etc., and optional tabId.
    export const setCookiesSchema = z.object({
      cookies: z.array(z.object({
        name: z.string(),
        value: z.string(),
        domain: z.string().optional(),
        path: z.string().optional().default('/'),
        expires: z.number().optional().describe('Unix timestamp when cookie expires'),
        httpOnly: z.boolean().optional(),
        secure: z.boolean().optional(),
        sameSite: z.enum(['Strict', 'Lax', 'None']).optional(),
      })).min(1),
      tabId: tabIdSchema,
    });
  • Registers the 'set_cookies' tool on the MCP server using server.tool, providing name, description, input schema, and handler function.
    server.tool(
      'set_cookies',
      'Set cookies in the browser',
      setCookiesSchema.shape,
      async ({ cookies, tabId }) => {
        const pageResult = await getPageForOperation(tabId);
        if (!pageResult.success) {
          return handleResult(pageResult);
        }
    
        const page = pageResult.data;
    
        try {
          // Get the current page URL for domain defaulting
          const pageUrl = new URL(page.url());
    
          const cookiesToSet = cookies.map((cookie: CookieParam) => ({
            name: cookie.name,
            value: cookie.value,
            domain: cookie.domain ?? pageUrl.hostname,
            path: cookie.path ?? '/',
            expires: cookie.expires,
            httpOnly: cookie.httpOnly,
            secure: cookie.secure,
            sameSite: cookie.sameSite as 'Strict' | 'Lax' | 'None' | undefined,
          }));
    
          await page.setCookie(...cookiesToSet);
    
          return handleResult(ok({
            set: cookies.length,
            cookies: cookiesToSet.map((c) => c.name),
          }));
        } catch (error) {
          return handleResult(err(normalizeError(error)));
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It states the action is 'set' (implying mutation) but doesn't cover permission requirements, side effects (e.g., whether cookies persist across sessions), error conditions, or what happens if cookies already exist. This leaves significant behavioral gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable. Every word earns its place by conveying essential purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations, no output schema, and moderate schema coverage, the description is inadequate. It doesn't address behavioral aspects like side effects, error handling, or success indicators. Given the complexity of cookie management (multiple attributes, browser context), more context is needed to help an agent use this tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50% (only 'expires' and 'tabId' have descriptions). The description adds no parameter-specific information beyond implying cookies are set. It doesn't explain the structure of the cookies array, required vs optional fields, or the meaning of cookie attributes like 'sameSite' or 'httpOnly'. The baseline 3 reflects that schema coverage is moderate but description adds little compensatory value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Set cookies in the browser' clearly states the action (set) and target resource (cookies in browser), making the purpose immediately understandable. However, it doesn't differentiate from the sibling tool 'delete_cookies' beyond the verb, missing explicit contrast between setting and deleting operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing an active browser session), contrast with 'get_cookies' for reading cookies, or specify scenarios where setting cookies is appropriate versus other browser automation tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/andytango/puppeteer-mcp'

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