Skip to main content
Glama
rayss868

Web-curl MCP Server

download_file

Download files from any URL to a specified folder, enabling local storage of web content and resources.

Instructions

Download a file from a given URL to a specified folder.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL of the file to download.
destinationFolderYesThe destination folder (relative to the workspace directory) to save the file.

Implementation Reference

  • The core handler function that downloads the file from the given URL, ensures the destination folder exists, streams the content using fetch and pipeline, and returns the saved file path.
    private async downloadFile(url: string, destinationFolder: string): Promise<string> {
      const logsDir = path.join(process.cwd(), 'logs');
      try {
        // Ensure the destination folder exists
        const fullDestinationPath = path.resolve(process.cwd(), destinationFolder);
        if (!fs.existsSync(fullDestinationPath)) {
          fs.mkdirSync(fullDestinationPath, { recursive: true });
        }
    
        const response = await fetch(url);
        if (!response.ok) {
          throw new Error(`Failed to download file: ${response.statusText}`);
        }
    
        const filename = path.basename(new URL(url).pathname) || 'downloaded_file';
        const filePath = path.join(fullDestinationPath, filename);
    
        const fileStream = fs.createWriteStream(filePath);
        if (response.body) {
          // Convert Web ReadableStream to Node.js Readable stream
          // Convert Web ReadableStream to Node.js Readable stream
          // For Node.js 18+, response.body is a ReadableStream (Web Streams API)
          // For pipeline, it needs to be a Node.js Readable stream.
          // A common way to bridge this is to convert the Web ReadableStream to an AsyncIterable
          // and then use Readable.from. However, directly piping is often possible.
          // If response.body is indeed a Web ReadableStream, it can often be directly piped.
          // If not, it needs to be converted.
          // Assuming response.body is a WHATWG ReadableStream, which is generally compatible with Node.js streams.
          await pipeline(Readable.fromWeb(response.body as any), fileStream); // Use Readable.fromWeb for conversion
        } else {
          throw new Error('Response body is null.');
        }
    
        return filePath; // Return the path to the downloaded file
      } catch (error: any) {
        console.error('Error downloading file:', error);
        throw new Error(`Failed to download file: ${error.message}`);
      }
    }
  • src/index.ts:252-270 (registration)
    Registers the 'download_file' tool in the MCP ListTools handler, specifying its description and input schema for validation.
    {
      name: 'download_file',
      description: 'Download a file from a given URL to a specified folder.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The URL of the file to download.'
          },
          destinationFolder: {
            type: 'string',
            description: 'The destination folder (relative to the workspace directory) to save the file.'
          }
        },
        required: ['url', 'destinationFolder'],
        additionalProperties: false,
      },
    },
  • TypeScript interface defining the structure of arguments expected by the download_file tool.
    interface DownloadFileArgs {
      url: string;
      destinationFolder: string;
    }
  • Helper function (type guard) to validate that tool arguments conform to DownloadFileArgs interface.
    const isValidDownloadFileArgs = (args: any): args is DownloadFileArgs => {
      if (
        typeof args === 'object' &&
        args !== null &&
        typeof args.url === 'string' &&
        typeof args.destinationFolder === 'string'
      ) {
        // Accept relative paths; resolution is handled in downloadFile (resolved against process.cwd())
        return true;
      }
      return false;
    };
  • Dispatch handler in CallToolRequestSchema that validates arguments, invokes the downloadFile method, and returns success/error response in MCP format.
    } else if (toolName === 'download_file') {
      if (!isValidDownloadFileArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid download_file arguments');
      }
      const validatedArgs = args as DownloadFileArgs;
      try {
        const filePath = await this.downloadFile(validatedArgs.url, validatedArgs.destinationFolder);
        return {
          content: [{ type: 'text', text: `File downloaded successfully to: ${filePath}` }],
        };
      } catch (error: any) {
        console.error('Error calling download_file:', error);
        return {
          content: [{ type: 'text', text: `Error downloading file: ${error.message}` }],
          isError: true,
        };
      }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions downloading a file but fails to address critical aspects like authentication needs, rate limits, error handling, file size constraints, or network behavior. This leaves significant gaps in understanding the tool's operational traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without any unnecessary words. It is front-loaded and appropriately sized, making it easy to understand at a glance while avoiding redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a download operation with no annotations and no output schema, the description is insufficient. It lacks details on return values, error conditions, security considerations, and performance implications, which are crucial for effective tool invocation in an AI agent context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting both parameters ('url' and 'destinationFolder'). The description adds minimal value beyond the schema, as it only reiterates the purpose without providing additional syntax, format details, or constraints. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Download a file') and the target resource ('from a given URL to a specified folder'), which is specific and unambiguous. However, it does not explicitly differentiate from sibling tools like 'fetch_api' or 'fetch_webpage', which might have overlapping functionality, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'fetch_api' or 'fetch_webpage'. It lacks context about prerequisites, exclusions, or specific use cases, offering only a basic functional statement without comparative or situational advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/rayss868/MCP-Web-Curl'

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