download_files
Download files from web pages using browser automation. Ideal for extracting content, generating PDFs, or saving media files directly through the Browserless MCP Server.
Instructions
Handle file downloads
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| context | No |
Implementation Reference
- src/index.ts:391-414 (handler)MCP tool handler for 'download_files': validates args, calls client.downloadFiles, constructs MCP response with text summary and binary file contents.case 'download_files': { if (!args) throw new Error('Arguments are required'); const result = await this.client!.downloadFiles(args as any); if (result.success && result.data) { const content = [ { type: 'text', text: `Downloaded ${result.data.files.length} files successfully.`, }, ]; for (const file of result.data.files) { content.push({ type: 'binary', mimeType: file.type, data: file.data.toString('base64'), } as any); } return { content }; } else { throw new Error(result.error || 'Failed to download files'); } }
- src/index.ts:147-158 (registration)Registration of the 'download_files' tool in the ListTools response, including name, description, and input schema.{ name: 'download_files', description: 'Handle file downloads', inputSchema: { type: 'object', properties: { code: { type: 'string' }, context: { type: 'object' }, }, required: ['code'], }, },
- src/client.ts:149-164 (handler)BrowserlessClient.downloadFiles method: HTTP POST to '/download' endpoint, handles response and errors.async downloadFiles(request: DownloadRequest): Promise<BrowserlessResponse<DownloadResponse>> { try { const response: AxiosResponse<DownloadResponse> = await this.httpClient.post('/download', request, { headers: { 'Content-Type': 'application/javascript', }, }); return { success: true, data: response.data, }; } catch (error) { return this.handleError(error); } }
- src/types.ts:177-182 (schema)Zod schema and TypeScript type definition for DownloadRequest (input validation for download_files).export const DownloadRequestSchema = z.object({ code: z.string(), context: z.record(z.any()).optional(), }); export type DownloadRequest = z.infer<typeof DownloadRequestSchema>;
- src/types.ts:276-282 (schema)TypeScript interface for DownloadResponse (output structure from download_files).export interface DownloadResponse { files: Array<{ name: string; data: Buffer; type: string; }>; }