Skip to main content
Glama

browser_set_cookie_object

Set browser cookies programmatically to manage user sessions, authentication states, or testing scenarios during web automation.

Instructions

Set a cookie in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cookieYesCookie string to set, e.g. 'name=value; Path=/; HttpOnly'

Implementation Reference

  • Registers the 'browser_set_cookie_object' MCP tool with input schema and handler function that instantiates CookieService and calls setCookie.
    server.tool(
      'browser_set_cookie_object',
      'Set a cookie in the browser',
      {
        cookie: z.string().min(1).max(4096).describe("Cookie string to set, e.g. 'name=value; Path=/; HttpOnly'"),
      },
      async ({ cookie }) => {
        const driver = stateManager.getDriver();
        const cookieService = new CookieService(driver);
        await cookieService.setCookie(cookie);
        return {
          content: [{ type: 'text', text: `Set cookie: ${cookie}` }],
        };
      }
    );
  • Implements the core logic for setting a cookie by parsing the string format into a cookie object and adding it via Selenium WebDriver.
    async setCookie(cookie: string): Promise<void> {
      // Parse cookie string into an object
      const [nameValue, ...attributes] = cookie.split(';').map(part => part.trim());
      let name = '';
      let value = '';
      if (nameValue) {
        const parts = nameValue.split('=');
        name = parts[0] ?? '';
        value = parts[1] ?? '';
      }
      const cookieObj: any = { name, value };
    
      attributes.forEach(attr => {
        const parts = attr.split('=');
        const attrName = parts[0];
        const attrValue = parts[1];
        if (!attrName) return;
        switch (attrName.toLowerCase()) {
          case 'name':
            cookieObj.name = attrValue;
            break;
          case 'domain':
            cookieObj.domain = attrValue;
            break;
          case 'path':
            cookieObj.path = attrValue;
            break;
          case 'expires':
            if (attrValue !== undefined) {
              cookieObj.expiry = Math.floor(new Date(attrValue).getTime() / 1000);
            }
            break;
          case 'secure':
            cookieObj.secure = true;
            break;
          case 'httponly':
            cookieObj.httpOnly = true;
            break;
        }
      });
    
      await this.driver.manage().addCookie(cookieObj);
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Set a cookie' implies a write/mutation operation, the description doesn't address important behavioral aspects like whether this requires specific browser state, what happens if the cookie already exists, whether this affects browser sessions, or any error conditions.

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 extremely concise - a single, clear sentence that states exactly what the tool does. There's no wasted words or unnecessary elaboration, making it easy to understand at a glance.

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 and no output schema, the description is insufficient. It doesn't explain what happens after setting the cookie, what the tool returns, or important behavioral context. Given the complexity of browser cookie operations and the lack of structured metadata, more descriptive context is needed.

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?

The schema description coverage is 100%, with the single parameter 'cookie' well-documented in the schema. The description doesn't add any parameter semantics beyond what the schema already provides, so it meets the baseline of 3 for high schema coverage.

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 clearly states the action ('Set a cookie') and resource ('in the browser'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'browser_add_cookie_by_name' - both appear to set cookies but with different parameter approaches.

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. There's no mention of when to choose this over 'browser_add_cookie_by_name' or other cookie-related tools, nor any context about prerequisites or appropriate situations for cookie setting.

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/pshivapr/selenium-mcp'

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