Skip to main content
Glama

drag

Drag a specified element to a target location using CSS selectors. Simplifies UI testing by automating drag-and-drop interactions.

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

  • The execute method that performs the drag operation: finds source and target elements via CSS selectors, gets their bounding boxes, and uses Playwright's mouse API (move, down, move, up) to simulate a drag from source to target.
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        this.recordInteraction();
        return this.safeExecute(context, async (page) => {
          // Use standard element selection with error on multiple matches
          const sourceLocator = await this.createScopedLocator(page, args.sourceSelector);
          const { element: sourceElement } = await this.selectPreferredLocator(sourceLocator, {
            errorOnMultiple: true,
            originalSelector: args.sourceSelector,
          });
    
          const targetLocator = await this.createScopedLocator(page, args.targetSelector);
          const { element: targetElement } = await this.selectPreferredLocator(targetLocator, {
            errorOnMultiple: true,
            originalSelector: 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 for the drag tool: requires sourceSelector and targetSelector (both strings) to define the element to drag and where to drag it.
      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"],
      },
    };
  • Registration of DragTool in the BROWSER_TOOL_CLASSES array, which makes it available as an MCP tool.
    DragTool,
    PressKeyTool,
  • Import statement for DragTool from the interaction/drag module.
    import { DragTool } from './interaction/drag.js';
  • Re-export of DragTool from the interaction barrel index.
    export { DragTool } from './drag.js';
    export { PressKeyTool } from './press_key.js';
Behavior2/5

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

Annotations already indicate mutation (readOnlyHint=false) and non-idempotency (idempotentHint=false). The description adds minimal behavioral context, not disclosing side effects or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no wasted words. However, it lacks additional structural elements that could improve clarity.

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?

For a simple tool with two string parameters and no output schema, the description is functional but incomplete. It could mention success/error behavior or return value expectations.

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% with clear parameter descriptions (CSS selectors). The tool description does not add any further semantics beyond the schema, so baseline score applies.

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 an element to a target location') and the resource (CSS selectors). It is distinct from sibling tools like click or hover, but could be more specific about the drag-and-drop nature.

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?

No guidance is provided on when to use this tool versus alternatives, nor are prerequisites or limitations mentioned (e.g., element visibility, potential failure conditions).

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/antonzherdev/mcp-web-inspector'

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