Skip to main content
Glama
webdriverio

WebDriverIO MCP Server

Official

drag_and_drop

Drag a source element to a target element or to specified x,y offsets on mobile devices. Requires source selector; optionally specify target selector or coordinates.

Instructions

Drags an element to another element or to relative x/y offsets. x and y are offsets from the source element, not absolute screen coordinates (unlike tap_element). Provide targetSelector OR both x and y. Mobile-only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceSelectorYesSource element selector to drag
targetSelectorNoTarget element selector to drop onto
xNoTarget X offset (if no targetSelector)
yNoTarget Y offset (if no targetSelector)
durationNoDrag duration in milliseconds

Implementation Reference

  • The main handler function (dragAndDropAction) that executes the drag and drop logic. It uses WebDriverIO's browser.$ to locate elements, and calls element.dragAndDrop() with either a target element or x/y offsets.
    export const dragAndDropAction = async (args: {
      sourceSelector: string;
      targetSelector?: string;
      x?: number;
      y?: number;
      duration?: number;
    }): Promise<CallToolResult> => {
      try {
        const browser = getBrowser();
        const { sourceSelector, targetSelector, x, y, duration } = args;
    
        const sourceElement = await browser.$(sourceSelector);
    
        if (targetSelector) {
          const targetElement = await browser.$(targetSelector);
          await sourceElement.dragAndDrop(targetElement, { duration });
          return {
            content: [{ type: 'text', text: `Dragged ${sourceSelector} to ${targetSelector}` }],
          };
        } else if (x !== undefined && y !== undefined) {
          await sourceElement.dragAndDrop({ x, y }, { duration });
          return {
            content: [{ type: 'text', text: `Dragged ${sourceSelector} by (${x}, ${y})` }],
          };
        }
    
        return {
          isError: true,
          content: [{ type: 'text', text: 'Error: Must provide either targetSelector or x,y coordinates' }],
        };
      } catch (e) {
        return {
          isError: true,
          content: [{ type: 'text', text: `Error dragging: ${e}` }],
        };
      }
    };
  • The ToolCallback wrapper (dragAndDropTool) that delegates to dragAndDropAction.
    export const dragAndDropTool: ToolCallback = async (args: {
      sourceSelector: string;
      targetSelector?: string;
      x?: number;
      y?: number;
      duration?: number;
    }): Promise<CallToolResult> => dragAndDropAction(args);
  • Input schema and tool definition for drag_and_drop, defining required sourceSelector, optional targetSelector/x/y/duration with Zod validation.
    export const dragAndDropToolDefinition: ToolDefinition = {
      name: 'drag_and_drop',
      description: 'Drags an element to another element or to relative x/y offsets. x and y are offsets from the source element, not absolute screen coordinates (unlike tap_element). Provide targetSelector OR both x and y. Mobile-only.',
      annotations: { title: 'Drag and Drop', destructiveHint: false },
      inputSchema: {
        sourceSelector: z.string().describe('Source element selector to drag'),
        targetSelector: z.string().optional().describe('Target element selector to drop onto'),
        x: z.number().optional().describe('Target X offset (if no targetSelector)'),
        y: z.number().optional().describe('Target Y offset (if no targetSelector)'),
        duration: z.number().min(100).max(5000).optional().describe('Drag duration in milliseconds'),
      },
    };
  • src/server.ts:142-142 (registration)
    Registration of the drag_and_drop tool on the MCP server, wrapping it with recording functionality.
    registerTool(dragAndDropToolDefinition, withRecording('drag_and_drop', dragAndDropTool));
  • Code generator for drag_and_drop that outputs WebDriverIO-style dragAndDrop calls when replaying recorded sessions.
    case 'drag_and_drop':
      if (p.targetSelector !== undefined) {
        return `await browser.$('${escapeStr(p.sourceSelector)}').dragAndDrop(browser.$('${escapeStr(p.targetSelector)}'));`;
      }
      return `await browser.$('${escapeStr(p.sourceSelector)}').dragAndDrop({ x: ${p.x}, y: ${p.y} });`;
Behavior4/5

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

Annotations only provide destructiveHint=false and title. Description adds critical behavioral context: x/y offsets are relative to source (not absolute), enabling correct agent interpretation. Also specifies mobile-only. No contradictions.

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 sentences: first states purpose, second clarifies coordinate system and usage rules. No extraneous words, highly efficient.

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 essential usage details (mutual exclusivity, coordinate semantics, mobile-only). Minor omission: no mention of default duration or behavior when drag target is not found, but schema covers duration bounds. Adequate for a tool with no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% (baseline 3). Description adds value by clarifying that x/y are offsets from the source and that targetSelector is mutually exclusive with x/y, beyond schema descriptions.

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?

The description clearly states 'Drags an element to another element or to relative x/y offsets.' It specifies the action, resource, and distinguishes from siblings like tap_element by noting coordinate differences and mobile-only context.

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 'Provide targetSelector OR both x and y,' giving a clear conditional for use. Also notes 'Mobile-only,' limiting platform context. Distinguishes from tap_element with coordinate semantics.

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/webdriverio/mcp'

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