Skip to main content
Glama

import_cookies

Import cookies as JSON array to restore authenticated login sessions without re-authentication. Requires userId for session isolation.

Instructions

Import cookies for authenticated sessions. Provide cookies in a JSON string array. Restores login sessions without re-auth. Requires userId.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdYesUser ID for session isolation
cookiesYesJSON string of cookie array to import
tabIdNoTab ID to target correct session (needed when using presets)

Implementation Reference

  • The actual cookie import handler in the CamofoxClient class. Sends cookies to the server via POST /sessions/{userId}/cookies, batching in chunks of 500 if needed.
    async importCookies(userId: string, cookies: unknown[], tabId?: string): Promise<void> {
      const MAX_COOKIES_PER_REQUEST = 500;
    
      if (cookies.length <= MAX_COOKIES_PER_REQUEST) {
        await this.requestNoContent(`/sessions/${encodeURIComponent(userId)}/cookies`, {
          method: "POST",
          body: JSON.stringify({ cookies, ...(tabId && { tabId }) }),
          requireApiKey: true
        });
        return;
      }
    
      for (let i = 0; i < cookies.length; i += MAX_COOKIES_PER_REQUEST) {
        const batch = cookies.slice(i, i + MAX_COOKIES_PER_REQUEST);
        await this.requestNoContent(`/sessions/${encodeURIComponent(userId)}/cookies`, {
          method: "POST",
          body: JSON.stringify({ cookies: batch, ...(tabId && { tabId }) }),
          requireApiKey: true
        });
      }
    }
  • The MCP tool handler that registers 'import_cookies' tool. Parses input (userId, cookies as JSON string, optional tabId), validates cookies is an array, then delegates to client.importCookies().
    export function registerSessionTools(server: McpServer, deps: ToolDeps): void {
      server.tool(
        "import_cookies",
        "Import cookies for authenticated sessions. Provide cookies in a JSON string array. Restores login sessions without re-auth. Requires userId.",
        {
          userId: z.string().min(1).describe("User ID for session isolation"),
          cookies: z.string().min(1).describe("JSON string of cookie array to import"),
          tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)")
        },
        async (input: unknown) => {
          try {
            const parsed = z
              .object({
                userId: z.string().min(1).describe("User ID for session isolation"),
                cookies: z.string().min(1).describe("JSON string of cookie array to import"),
                tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)")
              })
              .parse(input);
    
            let cookies: unknown;
            try {
              cookies = JSON.parse(parsed.cookies);
            } catch {
              throw new AppError("VALIDATION_ERROR", "cookies must be a JSON array");
            }
    
            if (!Array.isArray(cookies)) {
              throw new AppError("VALIDATION_ERROR", "cookies must be a JSON array");
            }
    
            await deps.client.importCookies(parsed.userId, cookies, parsed.tabId);
            return okResult({ success: true });
          } catch (error) {
            return toErrorResult(error);
          }
        }
      );
  • src/server.ts:49-49 (registration)
    Registration of the session tools (including import_cookies) in the MCP server via registerSessionTools().
    registerSessionTools(server, deps);
  • Input schema for import_cookies: userId (string), cookies (JSON string of cookie array), tabId (optional string).
    {
      userId: z.string().min(1).describe("User ID for session isolation"),
      cookies: z.string().min(1).describe("JSON string of cookie array to import"),
      tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)")
    },
  • Helper method requestNoContent used by importCookies to make the POST request without expecting JSON response.
    private async requestNoContent(path: string, init: RequestInit & { requireApiKey?: boolean }): Promise<void> {
      await this.request(path, init);
    }
Behavior3/5

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

Discloses that the tool imports cookies and restores sessions, implying a write operation, but does not detail whether it overwrites existing cookies, requires any special permissions, or has side effects. Given no annotations, the description provides moderate but incomplete behavioral insight.

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?

Two succinct sentences deliver the core purpose and parameter hints without redundancy. Every sentence contributes value.

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

Completeness3/5

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

Covers basic functionality and required parameters but omits what happens during import (e.g., merge vs. replace), error conditions, and absence of output schema leaves agents guessing about return values.

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 100%, so the description's mention of 'JSON string array' for cookies and 'userId' requirement adds no new information. It does not clarify the format of the cookie array or the purpose of 'tabId' beyond what the schema already states.

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

Purpose5/5

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

Explicitly states 'Import cookies for authenticated sessions' with a clear verb and resource, and further explains it restores login sessions without re-authentication. It is distinct from all sibling tools, none of which directly handle cookies.

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?

Lacks guidance on when to use this tool versus alternatives like 'load_profile' or manual authentication. No mention of prerequisites beyond 'Requires userId', and no exclusions or negative cases.

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/redf0x1/camofox-mcp'

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