browser_file_upload
Upload single or multiple files to a web page using Playwright MCP. Specify absolute file paths to enable browser automation for file inputs without screenshots.
Instructions
Upload one or multiple files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | The absolute paths to the files to upload. Can be a single file or multiple files. |
Implementation Reference
- src/tools/files.ts:20-53 (registration)Full tool definition and export of the 'browser_file_upload' tool using defineTabTool, including schema, handler, and registration for export.const uploadFile = defineTabTool({ capability: 'core', schema: { name: 'browser_file_upload', title: 'Upload files', description: 'Upload one or multiple files', inputSchema: z.object({ paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'), }), type: 'destructive', }, handle: async (tab, params, response) => { response.setIncludeSnapshot(); const modalState = tab.modalStates().find(state => state.type === 'fileChooser'); if (!modalState) throw new Error('No file chooser visible'); response.addCode(`// Select files for upload`); response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); }, clearsModalState: 'fileChooser', }); export default [ uploadFile, ];
- src/tools/files.ts:33-47 (handler)The core handler function that implements the file upload logic by setting files in the fileChooser modal and waiting for completion.handle: async (tab, params, response) => { response.setIncludeSnapshot(); const modalState = tab.modalStates().find(state => state.type === 'fileChooser'); if (!modalState) throw new Error('No file chooser visible'); response.addCode(`// Select files for upload`); response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); },
- src/tools/files.ts:23-31 (schema)Input schema definition using Zod for validating the paths parameter, along with tool metadata.schema: { name: 'browser_file_upload', title: 'Upload files', description: 'Upload one or multiple files', inputSchema: z.object({ paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'), }), type: 'destructive', },
- src/tools.ts:21-41 (registration)Higher-level registration where the files.ts module (including browser_file_upload) is imported and spread into the allTools array for global tool registry.import files from './tools/files.js'; import install from './tools/install.js'; import keyboard from './tools/keyboard.js'; import navigate from './tools/navigate.js'; import network from './tools/network.js'; import pdf from './tools/pdf.js'; import snapshot from './tools/snapshot.js'; import tabs from './tools/tabs.js'; import screenshot from './tools/screenshot.js'; import wait from './tools/wait.js'; import mouse from './tools/mouse.js'; import type { Tool } from './tools/tool.js'; import type { FullConfig } from './config.js'; export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files,