Skip to main content
Glama

pilot_import_cookies

Import browser cookies from Chrome, Edge, Brave, Arc, or Comet into headless sessions for automated testing and authentication.

Instructions

Import cookies from a real Chromium browser (Chrome, Arc, Brave, Edge, Comet). Decrypts from browser cookie database and adds to the headless browser session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
browserNoBrowser name (chrome, arc, brave, edge, comet). Auto-detects if omitted.
domainsYesCookie domains to import (e.g. [".github.com", ".google.com"])
profileNoBrowser profile name (default: "Default")
list_browsersNoList installed browsers instead of importing
list_profilesNoList available profiles for the specified browser
list_domainsNoList cookie domains available in the browser

Implementation Reference

  • The tool handler for pilot_import_cookies in src/tools/settings.ts. It handles listing browsers, profiles, domains, and the actual cookie import.
    async ({ browser, domains, profile, list_browsers, list_profiles, list_domains: listDom }) => {
      try {
        if (list_browsers) {
          const installed = findInstalledBrowsers();
          if (installed.length === 0) {
            return { content: [{ type: 'text' as const, text: `No Chromium browsers found. Supported: ${listSupportedBrowserNames().join(', ')}` }] };
          }
          return { content: [{ type: 'text' as const, text: `Installed browsers:\n${installed.map(b => `  - ${b.name}`).join('\n')}` }] };
        }
    
        if (list_profiles && browser) {
          const profiles = listProfiles(browser);
          if (profiles.length === 0) {
            return { content: [{ type: 'text' as const, text: `No profiles found for ${browser}` }] };
          }
          return { content: [{ type: 'text' as const, text: `Profiles for ${browser}:\n${profiles.map(p => `  - ${p.name} (${p.displayName})`).join('\n')}` }] };
        }
    
        if (listDom && browser) {
          const result = listDomains(browser, profile || 'Default');
          const top = result.domains.slice(0, 50);
          return { content: [{ type: 'text' as const, text: `Cookie domains in ${result.browser} (top ${top.length}):\n${top.map(d => `  ${d.domain} (${d.count} cookies)`).join('\n')}` }] };
        }
    
        // Import mode
        await bm.ensureBrowser();
        const browserName = browser || 'chrome';
        const result = await importCookies(browserName, domains, profile || 'Default');
    
        if (result.cookies.length > 0) {
          await bm.getContext().addCookies(result.cookies as any);
        }
    
        const msg = [`Imported ${result.count} cookies from ${browserName}`];
        if (result.failed > 0) msg.push(`(${result.failed} failed to decrypt)`);
        if (Object.keys(result.domainCounts).length > 0) {
          msg.push('\nPer domain:');
          for (const [domain, count] of Object.entries(result.domainCounts)) {
            msg.push(`  ${domain}: ${count}`);
          }
        }
        return { content: [{ type: 'text' as const, text: msg.join('\n') }] };
      } catch (err) {
        return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true };
      }
    }
  • The core logic function importCookies in src/cookie-import.ts, which performs the database query, decryption, and formatting of cookies for Playwright.
    export async function importCookies(
      browserName: string,
      domains: string[],
      profile = 'Default',
    ): Promise<ImportResult> {
      if (domains.length === 0) return { cookies: [], count: 0, failed: 0, domainCounts: {} };
    
      const browser = resolveBrowser(browserName);
      const match = getBrowserMatch(browser, profile);
      const derivedKeys = await getDerivedKeys(match);
      const db = openDb(match.dbPath, browser.name);
    
      try {
        const now = chromiumNow();
        const placeholders = domains.map(() => '?').join(',');
        const stmt = db.prepare(
          `SELECT host_key, name, value, encrypted_value, path, expires_utc,
                  is_secure, is_httponly, has_expires, samesite
           FROM cookies
           WHERE host_key IN (${placeholders})
             AND (has_expires = 0 OR expires_utc > ?)
           ORDER BY host_key, name`
        );
        const rows = stmt.all(...domains, now.toString()) as RawCookie[];
    
        const cookies: PlaywrightCookie[] = [];
        let failed = 0;
        const domainCounts: Record<string, number> = {};
    
        for (const row of rows) {
          try {
            const value = decryptCookieValue(row, derivedKeys);
            const cookie = toPlaywrightCookie(row, value);
            cookies.push(cookie);
            domainCounts[row.host_key] = (domainCounts[row.host_key] || 0) + 1;
          } catch {
            failed++;
          }
        }
    
        return { cookies, count: cookies.length, failed, domainCounts };
      } finally {
        db.close();
      }
    }
  • Registration of the 'pilot_import_cookies' tool with its schema definition in src/tools/settings.ts.
    server.tool(
      'pilot_import_cookies',
      'Import cookies from a real Chromium browser (Chrome, Arc, Brave, Edge, Comet). Decrypts from browser cookie database and adds to the headless browser session.',
      {
        browser: z.string().optional().describe('Browser name (chrome, arc, brave, edge, comet). Auto-detects if omitted.'),
        domains: z.array(z.string()).describe('Cookie domains to import (e.g. [".github.com", ".google.com"])'),
        profile: z.string().optional().describe('Browser profile name (default: "Default")'),
        list_browsers: z.boolean().optional().describe('List installed browsers instead of importing'),
        list_profiles: z.boolean().optional().describe('List available profiles for the specified browser'),
        list_domains: z.boolean().optional().describe('List cookie domains available in the browser'),
      },
      async ({ browser, domains, profile, list_browsers, list_profiles, list_domains: listDom }) => {
        try {
          if (list_browsers) {
            const installed = findInstalledBrowsers();
            if (installed.length === 0) {
              return { content: [{ type: 'text' as const, text: `No Chromium browsers found. Supported: ${listSupportedBrowserNames().join(', ')}` }] };
            }
            return { content: [{ type: 'text' as const, text: `Installed browsers:\n${installed.map(b => `  - ${b.name}`).join('\n')}` }] };
          }
    
          if (list_profiles && browser) {
            const profiles = listProfiles(browser);
            if (profiles.length === 0) {
              return { content: [{ type: 'text' as const, text: `No profiles found for ${browser}` }] };
            }
            return { content: [{ type: 'text' as const, text: `Profiles for ${browser}:\n${profiles.map(p => `  - ${p.name} (${p.displayName})`).join('\n')}` }] };
          }
    
          if (listDom && browser) {
            const result = listDomains(browser, profile || 'Default');
            const top = result.domains.slice(0, 50);
            return { content: [{ type: 'text' as const, text: `Cookie domains in ${result.browser} (top ${top.length}):\n${top.map(d => `  ${d.domain} (${d.count} cookies)`).join('\n')}` }] };
          }
    
          // Import mode
          await bm.ensureBrowser();
          const browserName = browser || 'chrome';
          const result = await importCookies(browserName, domains, profile || 'Default');
    
          if (result.cookies.length > 0) {
            await bm.getContext().addCookies(result.cookies as any);
          }
    
          const msg = [`Imported ${result.count} cookies from ${browserName}`];
          if (result.failed > 0) msg.push(`(${result.failed} failed to decrypt)`);
          if (Object.keys(result.domainCounts).length > 0) {
            msg.push('\nPer domain:');
            for (const [domain, count] of Object.entries(result.domainCounts)) {
              msg.push(`  ${domain}: ${count}`);
            }
          }
          return { content: [{ type: 'text' as const, text: msg.join('\n') }] };
        } catch (err) {
          return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true };
        }
      }
    );
Behavior3/5

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

No annotations provided, so description carries full burden. Mentions critical behavior 'Decrypts from browser cookie database' and target destination ('headless browser session'), but omits file system permissions required, OS keychain access needs, and error conditions (e.g., browser not installed).

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 dense sentences with zero waste. First sentence establishes what/where from; second explains how/where to. Front-loaded with essential information, appropriately sized for the complexity.

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?

With 6 parameters (including 3 alternative listing modes), zero annotations, and no output schema, the tool demands operational context. Schema documents parameters well, but description should explain the list-vs-import modes and disclose file system access requirements for a complete picture.

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 coverage is 100%, establishing baseline 3. Description adds semantic value by enumerating supported browser values (Chrome, Arc, etc.) confirming the browser parameter expectations, but doesn't explain the boolean listing flags (list_browsers, list_profiles, list_domains) or their relationship to the import operation.

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?

Excellent specificity: states 'Import cookies from a real Chromium browser' with explicit examples (Chrome, Arc, Brave, Edge, Comet), distinguishes from sibling cookie tools (pilot_cookies, pilot_set_cookie) by emphasizing external browser import vs session manipulation.

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

Usage Guidelines3/5

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

Provides implied usage context (importing from real browsers) but lacks explicit when-to-use guidance or comparison with pilot_set_cookie/pilot_cookies alternatives, and doesn't explain the mutually exclusive listing modes (list_browsers, list_profiles).

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/TacosyHorchata/Pilot'

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