Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_upload_file

Upload files to web page file input elements using CSS selectors and local file paths for browser automation tasks.

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

  • Defines the tool name, description, and input schema for 'playwright_upload_file'.
    {
      name: "playwright_upload_file",
      description: "Upload a file to an input[type='file'] element on the page",
      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"],
      },
    },
  • The UploadFileTool class implements the core logic for uploading a file using Playwright's setInputFiles method on the specified selector.
    export class UploadFileTool extends BrowserToolBase {
      /**
       * Execute the upload file tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
            await page.waitForSelector(args.selector);
            await page.setInputFiles(args.selector, args.filePath);
            return createSuccessResponse(`Uploaded file '${args.filePath}' to '${args.selector}'`);
        });
      }
    }
  • Dispatches the tool call to the UploadFileTool's execute method in the main tool handler switch statement.
    case "playwright_upload_file":
      return await uploadFileTool.execute(args, context);
  • Instantiates the UploadFileTool instance during tool initialization.
    if (!uploadFileTool) uploadFileTool = new UploadFileTool(server);
  • src/tools.ts:459-459 (registration)
    Lists 'playwright_upload_file' in the BROWSER_TOOLS array for conditional browser launching.
    "playwright_upload_file",

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/devskido/customed-playwright'

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