Skip to main content
Glama

playwright_drag

Drag elements to target locations in browser automation using CSS selectors for source and destination.

Instructions

Drag an element to a target location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceSelectorYesCSS selector for the element to drag
targetSelectorYesCSS selector for the target location

Implementation Reference

  • Core handler implementation for 'playwright_drag' tool. Performs mouse-based drag from sourceSelector to targetSelector using Playwright API.
    export class DragTool extends BrowserToolBase {
      /**
       * Execute the drag tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          const sourceElement = await page.waitForSelector(args.sourceSelector);
          const targetElement = await page.waitForSelector(args.targetSelector);
    
          const sourceBound = await sourceElement.boundingBox();
          const targetBound = await targetElement.boundingBox();
    
          if (!sourceBound || !targetBound) {
            return createErrorResponse("Could not get element positions for drag operation");
          }
    
          await page.mouse.move(sourceBound.x + sourceBound.width / 2, sourceBound.y + sourceBound.height / 2);
          await page.mouse.down();
          await page.mouse.move(targetBound.x + targetBound.width / 2, targetBound.y + targetBound.height / 2);
          await page.mouse.up();
    
          return createSuccessResponse(`Dragged element from ${args.sourceSelector} to ${args.targetSelector}`);
        });
      }
    }
  • Input schema and metadata definition for the 'playwright_drag' tool, used for MCP tool registration.
      name: "playwright_drag",
      description: "Drag an element to a target location",
      inputSchema: {
        type: "object",
        properties: {
          sourceSelector: { type: "string", description: "CSS selector for the element to drag" },
          targetSelector: { type: "string", description: "CSS selector for the target location" },
        },
        required: ["sourceSelector", "targetSelector"],
      },
    },
  • Dispatch case in main tool handler switch statement that routes 'playwright_drag' calls to dragTool.execute().
    case "playwright_drag":
      return await dragTool.execute(args, context);
  • Lazy instantiation of DragTool instance during tool initialization.
    if (!dragTool) dragTool = new DragTool(server);
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 'drag' implies a UI interaction, it doesn't specify whether this requires the element to be visible, what happens if selectors are invalid, whether it waits for page stability, or any error conditions. This leaves significant gaps in understanding the tool's behavior.

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, efficient sentence that directly states the tool's function without unnecessary words. It's front-loaded with the core action and appropriately sized for a straightforward UI interaction tool.

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 UI interaction tool with no annotations and no output schema, the description is insufficient. It doesn't explain what constitutes success/failure, what the tool returns (if anything), or important behavioral aspects like timing, visibility requirements, or error handling that are critical for proper 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, clearly documenting both parameters as CSS selectors. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline for high schema coverage without compensating value.

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 ('drag') and the resource ('an element to a target location'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling interactions like 'playwright_click' or 'playwright_hover' beyond the specific drag action.

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?

The description provides no guidance on when to use this tool versus alternatives like 'playwright_click' for simple interactions or other playwright tools for different actions. It lacks context about prerequisites (e.g., whether the page must be loaded) or typical use 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/aakashH242/mcp-playwright'

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