uploadFiles
Upload files to web forms using file input elements. Specify a CSS selector and file paths to automate file uploads in browser automation workflows.
Instructions
Upload files through a file input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | ||
| filePaths | Yes | Array of absolute file paths to upload |
Implementation Reference
- src/controllers/playwright.ts:801-814 (handler)The core handler function that executes the file upload logic using Playwright's locator.setInputFiles method.async uploadFiles(selector: string, filePaths: string[]): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Uploading files', { selector, filePaths }); const locator = this.state.page.locator(selector); await locator.setInputFiles(filePaths); this.log('File upload complete'); } catch (error: any) { console.error('File upload error:', error); throw new BrowserError('Failed to upload files', 'Check if selector is a file input and files exist'); } }
- src/server.ts:411-426 (schema)Defines the Tool object including name, description, and input schema for validation.const UPLOAD_FILES_TOOL: Tool = { name: "uploadFiles", description: "Upload files through a file input element", inputSchema: { type: "object", properties: { selector: { type: "string" }, filePaths: { type: "array", items: { type: "string" }, description: "Array of absolute file paths to upload" } }, required: ["selector", "filePaths"] } };
- src/server.ts:546-546 (registration)Registers the uploadFiles tool in the MCP server's tools capabilities map.uploadFiles: UPLOAD_FILES_TOOL,
- src/server.ts:913-924 (handler)MCP server request handler case that validates inputs and delegates to the Playwright controller for execution.case 'uploadFiles': { if (!args.selector || !args.filePaths) { return { content: [{ type: "text", text: "Selector and file paths are required" }], isError: true }; } await playwrightController.uploadFiles(args.selector as string, args.filePaths as string[]); return { content: [{ type: "text", text: "Files uploaded successfully" }] }; }