Skip to main content
Glama

upload_file_by_uid

Upload local files to web forms by targeting specific file input elements using their unique identifiers. This tool enables automated file submission in browser testing and automation workflows.

Instructions

Upload file to file input by UID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesFile input UID from snapshot
filePathYesLocal file path

Implementation Reference

  • MCP tool handler: validates uid and filePath args, gets Firefox instance, calls underlying uploadFileByUid, handles UID staleness, file input validation, and visibility errors.
    export async function handleUploadFileByUid(args: unknown): Promise<McpToolResponse> {
      try {
        const { uid, filePath } = args as { uid: string; filePath: string };
    
        if (!uid || typeof uid !== 'string') {
          throw new Error('uid parameter is required and must be a string');
        }
    
        if (!filePath || typeof filePath !== 'string') {
          throw new Error('filePath parameter is required and must be a string');
        }
    
        const { getFirefox } = await import('../index.js');
        const firefox = await getFirefox();
    
        try {
          await firefox.uploadFileByUid(uid, filePath);
          return successResponse(`✅ upload ${uid}`);
        } catch (error) {
          const errorMsg = (error as Error).message;
    
          // Check for UID staleness
          if (errorMsg.includes('stale') || errorMsg.includes('Snapshot') || errorMsg.includes('UID')) {
            throw handleUidError(error as Error, uid);
          }
    
          // Check for file input specific errors
          if (errorMsg.includes('not a file input') || errorMsg.includes('type="file"')) {
            throw new Error(`${uid} is not a file input`);
          }
    
          if (errorMsg.includes('hidden') || errorMsg.includes('not visible')) {
            throw new Error(`${uid} is hidden/not interactable`);
          }
    
          throw error;
        }
      } catch (error) {
        return errorResponse(error as Error);
      }
    }
  • Tool schema defining the input parameters: uid (element UID from snapshot) and filePath (absolute local path to the file to upload).
    export const uploadFileByUidTool = {
      name: 'upload_file_by_uid',
      description: 'Upload file to file input by UID.',
      inputSchema: {
        type: 'object',
        properties: {
          uid: {
            type: 'string',
            description: 'File input UID from snapshot',
          },
          filePath: {
            type: 'string',
            description: 'Local file path',
          },
        },
        required: ['uid', 'filePath'],
      },
    };
  • src/index.ts:103-147 (registration)
    Registration of the tool handler in the central toolHandlers Map used by the MCP server to dispatch tool calls.
    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)
    Inclusion of the tool definition in the allTools array returned by listTools MCP request.
    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 DOM helper implementation: resolves UID to WebElement, validates it's a file input, temporarily unhides it via JS styling, sends the filePath using Selenium sendKeys, and waits for events.
    async uploadFileByUid(uid: string, filePath: string): Promise<void> {
      if (!this.resolveUid) {
        throw new Error(
          'uploadFileByUid: resolveUid callback not set. Ensure snapshot is initialized.'
        );
      }
    
      const el = await this.resolveUid(uid);
    
      // Ensure it's an <input type=file>; if hidden, unhide via JS
      await this.driver.executeScript((element: Element) => {
        if (!element) {
          throw new Error('uploadFile: element not found');
        }
        if (element.tagName !== 'INPUT' || (element as HTMLInputElement).type !== 'file') {
          throw new Error('uploadFile: element must be <input type=file>');
        }
        const style = window.getComputedStyle(element);
        if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') {
          const s = (element as HTMLElement).style;
          s.display = 'block';
          s.visibility = 'visible';
          s.opacity = '1';
          s.position = 'fixed';
          s.left = '0px';
          s.top = '0px';
          s.zIndex = '2147483647';
        }
      }, el);
    
      await el.sendKeys(filePath);
    
      // Wait for events to propagate
      await this.waitForEventsAfterAction();
    }
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. It states the action ('Upload file') but doesn't disclose behavioral traits such as permissions required, whether it overwrites existing files, error handling, or response format. This leaves critical gaps for a mutation tool, making it minimally transparent.

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. It's front-loaded with the core action and target, making it easy to parse quickly. Every word earns its place, achieving optimal conciseness for such a brief statement.

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 with 2 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects, error cases, or return values, leaving the agent with insufficient context to use it effectively beyond basic parameter passing.

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%, so the schema fully documents both parameters ('uid' and 'filePath'). The description adds no meaning beyond this, as it doesn't explain parameter relationships or usage nuances. With high schema coverage, the baseline score of 3 is appropriate, but no extra value is provided.

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 states the action ('Upload file') and target ('to file input by UID'), which is clear but basic. It distinguishes from siblings like 'fill_by_uid' or 'screenshot_by_uid' by focusing on file uploads, but lacks specificity about what a 'file input' is or the upload's scope (e.g., web form, API). This makes it vague compared to more detailed alternatives.

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., needing a snapshot for UID), exclusions, or related tools like 'fill_by_uid' for text inputs. The agent must infer usage from the name and context alone, which is insufficient for optimal selection.

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