Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

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
NameRequiredDescriptionDefault
selectorYes
filePathsYesArray of absolute file paths to upload

Implementation Reference

  • 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'); } }
  • 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,
  • 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" }] }; }

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/jomon003/PlayMCP'

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