Skip to main content
Glama

upload_file

Specify a CSS selector and absolute file path to upload a file to a web page's file input element.

Instructions

Upload a file to an input[type='file'] element on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the file input element
filePathYesAbsolute path to the file to upload

Implementation Reference

  • The execute method of UploadFileTool that handles file upload logic. It creates a scoped locator, selects the element (erroring on multiple matches), and calls Playwright's setInputFiles to upload the file.
      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 locator = await this.createScopedLocator(page, args.selector);
          const { element } = await this.selectPreferredLocator(locator, {
            errorOnMultiple: true,
            originalSelector: args.selector,
          });
    
          await element.setInputFiles(args.filePath);
          return createSuccessResponse(`Uploaded file '${args.filePath}' to '${args.selector}'`);
        });
      }
    }
  • Input schema for upload_file tool. Defines required parameters: 'selector' (CSS selector for the file input element) and 'filePath' (absolute path to the file to upload).
    static getMetadata(sessionConfig?: SessionConfig): ToolMetadata {
      return {
        name: "upload_file",
        description: "Upload a file to an input[type='file'] element on the page",
        annotations: ANNOTATIONS.interaction,
        inputSchema: {
          type: "object",
          properties: {
            selector: { type: "string", description: "CSS selector for the file input element" },
            filePath: { type: "string", description: "Absolute path to the file to upload" }
          },
          required: ["selector", "filePath"],
        },
      };
  • UploadFileTool is included in the BROWSER_TOOL_CLASSES array which registers it as an available browser tool.
    UploadFileTool,
  • Import statement for UploadFileTool in the browser tool registration file.
    import { UploadFileTool } from './interaction/upload_file.js';
  • The safeExecute method from BrowserToolBase (parent class) that provides error handling, browser connection checks, and page closure checks wrapping the upload execution logic.
    protected async safeExecute(
      context: ToolContext,
      operation: (page: Page) => Promise<ToolResponse>
    ): Promise<ToolResponse> {
      const pageError = this.validatePageAvailable(context);
      if (pageError) return pageError;
    
      try {
        // Verify browser is connected before proceeding
Behavior3/5

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

Annotations already indicate this is mutative and non-idempotent. The description adds minimal behavioral context beyond the action itself, such as side effects like file selection state or potential need for subsequent actions.

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?

A single, concise sentence of 12 words that covers the essential purpose without any unnecessary elaboration or repetition.

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?

The description is functional but lacks important context such as prerequisites (element must be visible/interactable), behavior after upload (file is selected but not automatically submitted), and error conditions. Given the tool's simplicity, it is adequate but has clear gaps.

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 coverage is 100%, so the schema already describes the parameters. The description does not add extra meaning or usage details beyond the schema definitions.

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 the action (upload), the target (file input element), and distinguishes it from other interaction tools like click or fill. It is specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for file input elements but lacks explicit guidance on when to use this tool versus alternatives, such as when a submit action is needed after upload. No exclusions or context for when not to use it.

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