playwright_upload_file
Use this tool to upload a file to a web page's file input element by providing the CSS selector and the file's absolute path. Simplifies browser automation tasks in Playwright MCP Server.
Instructions
Upload a file to an input[type='file'] element on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the file to upload | |
| selector | Yes | CSS selector for the file input element |
Implementation Reference
- src/tools/browser/interaction.ts:139-150 (handler)The UploadFileTool.execute method implements the core logic for uploading a file using Playwright's page.setInputFiles after waiting for the 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}'`); }); } }
- src/tools.ts:185-195 (schema)Tool definition including name, description, and input schema for validation.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"], }, },
- src/toolHandler.ts:502-503 (registration)Dispatch in handleToolCall switch statement routes the tool call to the UploadFileTool instance.case "playwright_upload_file": return await uploadFileTool.execute(args, context);
- src/toolHandler.ts:327-327 (registration)Instantiation of the UploadFileTool class in initializeTools function.if (!uploadFileTool) uploadFileTool = new UploadFileTool(server);
- src/tools.ts:459-459 (helper)Listed in BROWSER_TOOLS array for conditional browser launch checks."playwright_upload_file",