Skip to main content
Glama

drag_by_uid_to_uid

Simulate HTML5 drag-and-drop interactions between web elements using unique identifiers for browser automation and testing.

Instructions

Drag element to another (HTML5 drag events).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromUidYesSource element UID
toUidYesTarget element UID

Implementation Reference

  • MCP tool handler: validates input arguments, retrieves Firefox instance, performs drag operation via firefox.dragByUidToUid, handles UID staleness errors
    export async function handleDragByUidToUid(args: unknown): Promise<McpToolResponse> {
      try {
        const { fromUid, toUid } = args as { fromUid: string; toUid: string };
    
        if (!fromUid || typeof fromUid !== 'string') {
          throw new Error('fromUid parameter is required and must be a string');
        }
    
        if (!toUid || typeof toUid !== 'string') {
          throw new Error('toUid parameter is required and must be a string');
        }
    
        const { getFirefox } = await import('../index.js');
        const firefox = await getFirefox();
    
        try {
          await firefox.dragByUidToUid(fromUid, toUid);
          return successResponse(`✅ drag ${fromUid}→${toUid}`);
        } catch (error) {
          // Check both UIDs for staleness
          const errorMsg = (error as Error).message;
          if (errorMsg.includes('stale') || errorMsg.includes('Snapshot') || errorMsg.includes('UID')) {
            throw new Error(`UIDs stale/invalid. Call take_snapshot first.`);
          }
          throw error;
        }
      } catch (error) {
        return errorResponse(error as Error);
      }
    }
  • Tool schema definition including input validation for fromUid and toUid parameters
    export const dragByUidToUidTool = {
      name: 'drag_by_uid_to_uid',
      description: 'Drag element to another (HTML5 drag events).',
      inputSchema: {
        type: 'object',
        properties: {
          fromUid: {
            type: 'string',
            description: 'Source element UID',
          },
          toUid: {
            type: 'string',
            description: 'Target element UID',
          },
        },
        required: ['fromUid', 'toUid'],
      },
    };
  • src/index.ts:103-147 (registration)
    Main MCP server registration: maps tool name 'drag_by_uid_to_uid' to its handler function
    const toolHandlers = new Map<
      string,
      (input: unknown) => Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }>
    >([
      // Pages
      ['list_pages', tools.handleListPages],
      ['new_page', tools.handleNewPage],
      ['navigate_page', tools.handleNavigatePage],
      ['select_page', tools.handleSelectPage],
      ['close_page', tools.handleClosePage],
    
      // Script evaluation - DISABLED (see docs/future-features.md)
      // ['evaluate_script', tools.handleEvaluateScript],
    
      // Console
      ['list_console_messages', tools.handleListConsoleMessages],
      ['clear_console_messages', tools.handleClearConsoleMessages],
    
      // Network
      ['list_network_requests', tools.handleListNetworkRequests],
      ['get_network_request', tools.handleGetNetworkRequest],
    
      // Snapshot
      ['take_snapshot', tools.handleTakeSnapshot],
      ['resolve_uid_to_selector', tools.handleResolveUidToSelector],
      ['clear_snapshot', tools.handleClearSnapshot],
    
      // Input
      ['click_by_uid', tools.handleClickByUid],
      ['hover_by_uid', tools.handleHoverByUid],
      ['fill_by_uid', tools.handleFillByUid],
      ['drag_by_uid_to_uid', tools.handleDragByUidToUid],
      ['fill_form_by_uid', tools.handleFillFormByUid],
      ['upload_file_by_uid', tools.handleUploadFileByUid],
    
      // Screenshot
      ['screenshot_page', tools.handleScreenshotPage],
      ['screenshot_by_uid', tools.handleScreenshotByUid],
    
      // Utilities
      ['accept_dialog', tools.handleAcceptDialog],
      ['dismiss_dialog', tools.handleDismissDialog],
      ['navigate_history', tools.handleNavigateHistory],
      ['set_viewport_size', tools.handleSetViewportSize],
    ]);
  • src/index.ts:150-191 (registration)
    MCP server tool list registration: includes dragByUidToUidTool for listTools endpoint
    const allTools = [
      // Pages
      tools.listPagesTool,
      tools.newPageTool,
      tools.navigatePageTool,
      tools.selectPageTool,
      tools.closePageTool,
    
      // Script evaluation - DISABLED (see docs/future-features.md)
      // tools.evaluateScriptTool,
    
      // Console
      tools.listConsoleMessagesTool,
      tools.clearConsoleMessagesTool,
    
      // Network
      tools.listNetworkRequestsTool,
      tools.getNetworkRequestTool,
    
      // Snapshot
      tools.takeSnapshotTool,
      tools.resolveUidToSelectorTool,
      tools.clearSnapshotTool,
    
      // Input
      tools.clickByUidTool,
      tools.hoverByUidTool,
      tools.fillByUidTool,
      tools.dragByUidToUidTool,
      tools.fillFormByUidTool,
      tools.uploadFileByUidTool,
    
      // Screenshot
      tools.screenshotPageTool,
      tools.screenshotByUidTool,
    
      // Utilities
      tools.acceptDialogTool,
      tools.dismissDialogTool,
      tools.navigateHistoryTool,
      tools.setViewportSizeTool,
    ];
  • Core implementation: resolves UIDs to elements, dispatches HTML5 DragEvents (dragstart, dragenter, etc.) via executeScript for drag-and-drop
    async dragByUidToUid(fromUid: string, toUid: string): Promise<void> {
      if (!this.resolveUid) {
        throw new Error(
          'dragByUidToUid: resolveUid callback not set. Ensure snapshot is initialized.'
        );
      }
    
      const fromEl = await this.resolveUid(fromUid);
      const toEl = await this.resolveUid(toUid);
    
      // Use JS drag events fallback for compatibility (Actions DnD not used)
      await this.driver.executeScript(
        (srcEl: Element, tgtEl: Element) => {
          if (!srcEl || !tgtEl) {
            throw new Error('dragAndDrop: element not found');
          }
    
          function dispatch(type: string, target: Element, dataTransfer?: DataTransfer) {
            const evt = new DragEvent(type, {
              bubbles: true,
              cancelable: true,
              dataTransfer,
            } as DragEventInit);
            return target.dispatchEvent(evt);
          }
    
          // Create DataTransfer if available
          const dt = typeof DataTransfer !== 'undefined' ? new DataTransfer() : undefined;
          dispatch('dragstart', srcEl, dt);
          dispatch('dragenter', tgtEl, dt);
          dispatch('dragover', tgtEl, dt);
          dispatch('drop', tgtEl, dt);
          dispatch('dragend', srcEl, dt);
        },
        fromEl,
        toEl
      );
    
      // Wait for events to propagate
      await this.waitForEventsAfterAction();
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the action involves HTML5 drag events, hinting at browser-based interaction, but doesn't disclose critical traits like whether it simulates full drag-and-drop sequences, error handling, performance implications, or what happens if elements aren't draggable. This leaves significant gaps for a mutation tool.

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 with zero waste—'Drag element to another (HTML5 drag events)'—front-loading the core action and providing technical context parenthetically. Every word earns its place, making it appropriately sized for the tool's complexity.

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 (a mutation action with no annotations or output schema), the description is incomplete. It lacks details on behavioral outcomes, error cases, dependencies (e.g., page state), and return values, leaving the agent with insufficient context to use it reliably beyond basic parameter mapping.

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 ('Source element UID', 'Target element UID'), so the schema does the heavy lifting. The description adds no additional meaning beyond implying a drag action between these UIDs, meeting the baseline for high schema coverage without extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Drag element to another (HTML5 drag events)' specifies the action (drag) and resource (element), but is vague about scope and doesn't distinguish from siblings like 'click_by_uid' or 'hover_by_uid'. It mentions HTML5 drag events for context, but lacks specificity about what 'drag' entails in this implementation.

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. It doesn't mention prerequisites (e.g., elements must be draggable), exclusions, or how it differs from other interaction tools in the sibling list, leaving usage context implied at best.

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/mozilla/firefox-devtools-mcp'

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