curl_download
Download files from URLs using curl with options to specify output filenames, resume partial downloads, follow redirects, and set request timeouts.
Instructions
Download a file using curl
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| follow_redirects | No | Whether to follow redirects | |
| output_filename | No | Output filename (if not provided, will use remote filename) | |
| resume | No | Resume partial download if file exists | |
| timeout | No | Request timeout in seconds | |
| url | Yes | The URL of the file to download |
Implementation Reference
- src/index.ts:366-418 (handler)The handler function that executes the curl download logic by building safe curl arguments and invoking the shared executeCurl helper.async ({ url, output_filename, resume, follow_redirects, timeout }) => { const args = ['curl']; // Add the URL args.push(url); // Add output option if (output_filename) { args.push('-o', output_filename); } else { args.push('-O'); // Use remote filename } // Add resume option if (resume) { args.push('-C', '-'); } // Add follow redirects option if (follow_redirects) { args.push('-L'); } // Add timeout if provided if (timeout) { args.push('--max-time', timeout.toString()); } // Show progress args.push('--progress-bar'); try { const result = await executeCurl(args); return { content: [ { type: "text", text: `Exit Code: ${result.exitCode}\n\nDownload ${result.exitCode === 0 ? 'completed successfully' : 'failed'}:\n${result.stdout}${result.stderr ? `\n\nOutput:\n${result.stderr}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error executing curl: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:359-365 (schema)Zod input schema defining the parameters for the curl_download tool.{ url: z.string().describe("The URL of the file to download"), output_filename: z.string().optional().describe("Output filename (if not provided, will use remote filename)"), resume: z.boolean().optional().default(false).describe("Resume partial download if file exists"), follow_redirects: z.boolean().optional().default(true).describe("Whether to follow redirects"), timeout: z.number().optional().describe("Request timeout in seconds"), },
- src/index.ts:356-419 (registration)The server.tool registration for the curl_download tool, including description, schema, and handler reference."},{server.tool( "curl_download", "Download a file using curl", { url: z.string().describe("The URL of the file to download"), output_filename: z.string().optional().describe("Output filename (if not provided, will use remote filename)"), resume: z.boolean().optional().default(false).describe("Resume partial download if file exists"), follow_redirects: z.boolean().optional().default(true).describe("Whether to follow redirects"), timeout: z.number().optional().describe("Request timeout in seconds"), }, async ({ url, output_filename, resume, follow_redirects, timeout }) => { const args = ['curl']; // Add the URL args.push(url); // Add output option if (output_filename) { args.push('-o', output_filename); } else { args.push('-O'); // Use remote filename } // Add resume option if (resume) { args.push('-C', '-'); } // Add follow redirects option if (follow_redirects) { args.push('-L'); } // Add timeout if provided if (timeout) { args.push('--max-time', timeout.toString()); } // Show progress args.push('--progress-bar'); try { const result = await executeCurl(args); return { content: [ { type: "text", text: `Exit Code: ${result.exitCode}\n\nDownload ${result.exitCode === 0 ? 'completed successfully' : 'failed'}:\n${result.stdout}${result.stderr ? `\n\nOutput:\n${result.stderr}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error executing curl: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );