Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_click_and_switch_tab

Click a link using a CSS selector and automatically switch to the newly opened browser tab for web automation tasks.

Instructions

Click a link and switch to the newly opened tab

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the link to click

Implementation Reference

  • Exact implementation of the playwright_click_and_switch_tab tool in ClickAndSwitchTabTool.execute: clicks selector, awaits new page on context, waits for load, sets global page to new tab.
    export class ClickAndSwitchTabTool extends BrowserToolBase {
      /**
       * Execute the click and switch tab tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        
        return this.safeExecute(context, async (page) => {
          // Listen for a new tab to open
          const [newPage] = await Promise.all([
            //context.browser.waitForEvent('page'), // Wait for a new page (tab) to open
            page.context().waitForEvent('page'),// Wait for a new page (tab) to open
            page.click(args.selector), // Click the link that opens the new tab
          ]);
    
          // Wait for the new page to load
          await newPage.waitForLoadState('domcontentloaded');
    
          // Switch control to the new tab
          setGlobalPage(newPage);
          //page= newPage; // Update the current page to the new tab
          //context.page = newPage;
          //context.page.bringToFront(); // Bring the new tab to the front
          return createSuccessResponse(`Clicked link and switched to new tab: ${newPage.url()}`);
          //return createSuccessResponse(`Clicked link and switched to new tab: ${context.page.url()}`);
        });
      }
    }
  • Input schema definition for the tool, requiring a CSS selector.
    {
      name: "playwright_click_and_switch_tab",
      description: "Click a link and switch to the newly opened tab",
      inputSchema: {
        type: "object",
        properties: {
          selector: { type: "string", description: "CSS selector for the link to click" },
        },
        required: ["selector"],
      },
    },
  • Registration and dispatch in handleToolCall switch statement routing to the tool handler.
    case "playwright_click_and_switch_tab":
      return await clickAndSwitchTabTool.execute(args, context);
  • Instantiation of ClickAndSwitchTabTool instance.
    if (!clickAndSwitchTabTool) clickAndSwitchTabTool = new ClickAndSwitchTabTool(server);
  • Import of the ClickAndSwitchTabTool class.
    import { ClickAndSwitchTabTool } from './tools/browser/interaction.js';
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the action and outcome but lacks details on error handling (e.g., if no new tab opens), performance (e.g., waiting for tab load), or side effects (e.g., closing old tabs). This is inadequate for a mutation tool with zero annotation coverage.

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, clear sentence that directly states the tool's function without unnecessary words. It is front-loaded and efficient, with every part contributing to understanding the purpose and outcome.

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?

Given the tool's complexity (involving tab management and interaction) and lack of annotations and output schema, the description is insufficient. It does not cover return values, error conditions, or behavioral nuances like waiting for the new tab to load, which are critical for effective use.

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 input schema has 100% description coverage, with the 'selector' parameter fully documented. The description does not add any semantic details beyond the schema, such as examples of valid selectors or how to handle dynamic content. Baseline score of 3 is appropriate as the schema does the heavy lifting.

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 ('click a link') and the outcome ('switch to the newly opened tab'), making the purpose evident. However, it does not explicitly differentiate from sibling tools like 'playwright_click' (which clicks without tab switching) or 'playwright_navigate' (which navigates within the same tab), missing full sibling distinction.

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?

The description implies usage when clicking a link that opens a new tab, but it does not provide explicit guidance on when to use this tool versus alternatives like 'playwright_click' (for same-tab clicks) or 'playwright_navigate' (for direct navigation). No exclusions or prerequisites are mentioned, leaving usage context partially implied.

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/devskido/customed-playwright'

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