Skip to main content
Glama

attach

Connect to an existing Chrome browser instance to retrieve the active tab URL and total tab count. Essential first step for interacting with pages and detecting handoff triggers.

Instructions

Connect to a running Chrome instance (must be launched with --remote-debugging-port). Returns the active tab URL and total tab count. Always call this first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portNoCDP port; default 9222

Implementation Reference

  • The handler function for the 'attach' tool. Connects to a Chrome instance via CDP on the specified port (default 9222), creates or picks an active tab, and returns status, URL, title, and tab count.
    async function attach(args: { port?: number }) {
      const port = args.port ?? 9222;
      if (browser) {
        return {
          status: 'already attached',
          url: page?.url() ?? null,
        };
      }
      try {
        browser = await chromium.connectOverCDP(`http://localhost:${port}`);
      } catch (e) {
        return {
          error: `Could not connect to Chrome on port ${port}. ` +
            `Launch Chrome with: open -a "Google Chrome" --args --remote-debugging-port=${port} --user-data-dir=$HOME/.chrome-pilot`,
          details: (e as Error).message,
        };
      }
      const contexts = browser.contexts();
      if (contexts.length === 0) {
        return { error: 'Browser has no contexts. Open at least one tab.' };
      }
      const ctx = contexts[0];
      const pages = ctx.pages();
      if (pages.length === 0) {
        page = await ctx.newPage();
      } else {
        // Pick the most recently active-looking tab: prefer non-blank, non-chrome:// URLs.
        page = pages.find(p => {
          const u = p.url();
          return u && !u.startsWith('chrome://') && u !== 'about:blank';
        }) ?? pages[0];
      }
      return {
        status: 'attached',
        url: page.url(),
        title: await page.title().catch(() => '(unavailable)'),
        tabCount: pages.length,
      };
    }
  • Tool registration metadata for 'attach', defining its name, description, and input schema (optional port parameter).
    {
      name: 'attach',
      description:
        'Connect to a running Chrome instance (must be launched with --remote-debugging-port). ' +
        'Returns the active tab URL and total tab count. Always call this first.',
      inputSchema: {
        type: 'object',
        properties: { port: { type: 'number', description: 'CDP port; default 9222' } },
      },
    },
  • src/index.ts:461-461 (registration)
    The request handler switch-case that dispatches the 'attach' tool name to the attach function.
    case 'attach':       result = await attach(args as { port?: number }); break;
  • Helper function that throws an error referencing attach if no page is active, used by other tools to ensure attach was called first.
    function requirePage(): Page {
      if (!page) {
        throw new Error(
          'Not attached. Call `attach` first (Chrome must be running with --remote-debugging-port=9222).'
        );
      }
      return page;
Behavior3/5

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

Describes return values but lacks details on error handling, side effects, or behavior when connection fails. No annotations to supplement, so description carries full burden but is incomplete.

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 efficient sentences with no waste. Critical info (precondition, return values, usage order) is front-loaded.

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

Completeness4/5

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

Covers purpose, return value, precondition. Lacks error behavior and output format, but these are minor for a simple initialization tool with one optional parameter.

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 provides full coverage of the single parameter (port with default). Description adds no extra meaning beyond schema, so baseline 3 is appropriate.

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?

Description clearly states action (connect to Chrome instance), resource (running Chrome with specific flag), and return values (active tab URL, tab count). It distinguishes from siblings by being the first call.

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

Usage Guidelines5/5

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

Explicitly states prerequisite (must be launched with --remote-debugging-port) and ordering (always call this first). Provides clear when-to-use guidance.

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/flying-pisces/mcp-helm'

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