Skip to main content
Glama

upload_file

Upload files to web pages by specifying a file input element and local file path for browser automation and testing.

Instructions

Upload a file through a provided element.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesThe uid of the file input element or an element that will open file chooser on the page from the page content snapshot
filePathYesThe local path of the file to upload

Implementation Reference

  • The handler function that implements the logic for the 'upload_file' tool. It uploads a file to the specified element (file input or clickable element triggering file chooser).
    handler: async (request, response, context) => {
      const {uid, filePath} = request.params;
      const handle = (await context.getElementByUid(
        uid,
      )) as ElementHandle<HTMLInputElement>;
      try {
        try {
          await handle.uploadFile(filePath);
        } catch {
          // Some sites use a proxy element to trigger file upload instead of
          // a type=file element. In this case, we want to default to
          // Page.waitForFileChooser() and upload the file this way.
          try {
            const page = context.getSelectedPage();
            const [fileChooser] = await Promise.all([
              page.waitForFileChooser({timeout: 3000}),
              handle.asLocator().click(),
            ]);
            await fileChooser.accept([filePath]);
          } catch {
            throw new Error(
              `Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`,
            );
          }
        }
        response.setIncludeSnapshot(true);
        response.appendResponseLine(`File uploaded from ${filePath}.`);
      } finally {
        void handle.dispose();
      }
    },
  • Input schema for the 'upload_file' tool using Zod, defining 'uid' and 'filePath' parameters.
    schema: {
      uid: z
        .string()
        .describe(
          'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot',
        ),
      filePath: z.string().describe('The local path of the file to upload'),
    },
  • src/main.ts:307-320 (registration)
    Registration of all tools, including 'upload_file' from inputTools (imported as * from './tools/input.js' on line 32), by collecting Object.values(inputTools) into the tools array and calling registerTool for each.
    const tools = [
      ...Object.values(consoleTools),
      ...Object.values(emulationTools),
      ...Object.values(inputTools),
      ...Object.values(networkTools),
      ...Object.values(pagesTools),
      ...Object.values(performanceTools),
      ...Object.values(screenshotTools),
      ...Object.values(scriptTools),
      ...Object.values(snapshotTools),
    ];
    for (const tool of tools) {
      registerTool(tool as unknown as ToolDefinition);
    }
Behavior3/5

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

Annotations indicate readOnlyHint=false, aligning with the 'upload' action implying mutation. The description adds minimal behavioral context beyond annotations, such as specifying the upload mechanism via an element, but does not cover aspects like error handling, file size limits, or authentication needs. No contradiction with annotations exists.

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 that directly states the tool's purpose without unnecessary details. It is front-loaded and wastes no words, making it highly concise and well-structured.

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?

Given the tool's complexity (file upload with 2 parameters) and lack of output schema, the description is minimally adequate but incomplete. It covers the basic action but omits details like return values, error cases, or interaction with sibling tools, leaving gaps for an agent to infer usage.

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 does not add meaning beyond the schema, such as explaining what an 'element that will open file chooser' entails or file path constraints, resulting in a baseline score.

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 ('upload a file') and the mechanism ('through a provided element'), which is specific and actionable. However, it does not explicitly differentiate from sibling tools like 'fill' or 'fill_form' that might also handle file inputs, missing full sibling distinction.

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?

The description provides no guidance on when to use this tool versus alternatives, such as 'fill' for text inputs or other file-handling methods. It lacks context about prerequisites, like needing a file input element on the page, and does not mention exclusions or best practices.

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/SHAY5555-gif/chrome-devtools-mcp'

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