Skip to main content
Glama

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
NameRequiredDescriptionDefault
codeYes
contextNo

Implementation Reference

  • 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); } }
  • 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'], }, },
  • 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>;
  • TypeScript interface for the DownloadResponse output containing array of downloaded files.
    export interface DownloadResponse { files: Array<{ name: string; data: Buffer; type: string; }>; }

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/Lizzard-Solutions/browserless-mcp'

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