uploadFiles
Upload files to web forms using a file input element. Specify a selector and file paths to automate file uploads in browser interactions.
Instructions
Upload files through a file input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePaths | Yes | Array of absolute file paths to upload | |
| selector | Yes |
Implementation Reference
- src/controllers/playwright.ts:801-814 (handler)Core implementation of the uploadFiles tool using Playwright's setInputFiles on the file input element locator.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:913-924 (handler)MCP server request handler that validates input and delegates to the Playwright controller's uploadFiles method.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" }] }; }
- src/server.ts:411-426 (schema)Defines the tool schema with input parameters for selector (CSS selector for file input) and filePaths (array of absolute paths).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:514-552 (registration)Registers the uploadFiles tool in the tools dictionary passed to MCP server capabilities.const tools = { openBrowser: OPEN_BROWSER_TOOL, navigate: NAVIGATE_TOOL, type: TYPE_TOOL, click: CLICK_TOOL, moveMouse: MOVE_MOUSE_TOOL, scroll: SCROLL_TOOL, screenshot: SCREENSHOT_TOOL, getPageSource: GET_PAGE_SOURCE_TOOL, getPageText: GET_PAGE_TEXT_TOOL, getPageTitle: GET_PAGE_TITLE_TOOL, getPageUrl: GET_PAGE_URL_TOOL, getScripts: GET_SCRIPTS_TOOL, getStylesheets: GET_STYLESHEETS_TOOL, getMetaTags: GET_META_TAGS_TOOL, getLinks: GET_LINKS_TOOL, getImages: GET_IMAGES_TOOL, getForms: GET_FORMS_TOOL, getElementContent: GET_ELEMENT_CONTENT_TOOL, getElementHierarchy: GET_ELEMENT_HIERARCHY_TOOL, executeJavaScript: EXECUTE_JAVASCRIPT_TOOL, goForward: GO_FORWARD_TOOL, hover: HOVER_TOOL, dragAndDrop: DRAG_AND_DROP_TOOL, selectOption: SELECT_OPTION_TOOL, pressKey: PRESS_KEY_TOOL, waitForText: WAIT_FOR_TEXT_TOOL, waitForSelector: WAIT_FOR_SELECTOR_TOOL, resize: RESIZE_TOOL, handleDialog: HANDLE_DIALOG_TOOL, getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL, getNetworkRequests: GET_NETWORK_REQUESTS_TOOL, uploadFiles: UPLOAD_FILES_TOOL, evaluateWithReturn: EVALUATE_WITH_RETURN_TOOL, takeScreenshot: TAKE_SCREENSHOT_TOOL, mouseMove: MOUSE_MOVE_TOOL, mouseClick: MOUSE_CLICK_TOOL, mouseDrag: MOUSE_DRAG_TOOL, closeBrowser: CLOSE_BROWSER_TOOL