download_files
Handle file downloads from web pages using browser automation. This tool processes download requests to save files locally during web scraping or automation tasks.
Instructions
Handle file downloads
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| context | No |
Implementation Reference
- src/client.ts:149-164 (handler)Core handler implementation that sends a POST request to the Browserless '/download' endpoint with the provided request and handles the response containing downloaded files.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/index.ts:391-414 (handler)MCP tool handler for 'download_files' that calls the client.downloadFiles method, processes the result, and returns MCP-formatted content with binary file data.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/types.ts:177-182 (schema)Zod schema and TypeScript type definition for the DownloadRequest input.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 the DownloadResponse output containing array of downloaded files.export interface DownloadResponse { files: Array<{ name: string; data: Buffer; type: string; }>; }