Skip to main content
Glama

browser_file_upload

Upload files to web pages during browser automation. Specify file paths to simulate file selection in forms for testing or data entry workflows.

Instructions

Upload one or multiple files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathsYesThe absolute paths to the files to upload. Can be a single file or multiple files.

Implementation Reference

  • The core handler function implementing the browser_file_upload tool logic. It handles file upload by interacting with the file chooser modal state in the current tab, setting the files via Playwright API.
    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(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); },
  • Zod-based schema definition for the tool, specifying name, title, description, input parameters (array of file paths), and destructive type.
    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', },
  • Export of the defined tool (uploadFile) as default array for inclusion in higher-level tool lists.
    export default [ uploadFile, ];
  • src/tools.ts:36-52 (registration)
    Top-level registration where tools from files.ts (including browser_file_upload) are spread into the allTools array, imported at line 21.
    export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
  • Helper function defineTabTool used to wrap tab-specific tools, adding modal state validation before calling the custom handler.
    export function defineTabTool<Input extends z.Schema>(tool: TabTool<Input>): Tool<Input> { return { ...tool, handle: async (context, params, response) => { const tab = context.currentTabOrDie(); const modalStates = tab.modalStates().map(state => state.type); if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState)) response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` + tab.modalStatesMarkdown().join('\n')); else if (!tool.clearsModalState && modalStates.length) response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.\n` + tab.modalStatesMarkdown().join('\n')); else return tool.handle(tab, params, response); }, }; }

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/maywzh/playwright-mcp'

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