Skip to main content
Glama
zibdie
by zibdie

ssh_download_file

Download a file from a remote server to a local path via SFTP, with optional directory creation and connection selection.

Instructions

Download a file from the remote server via SFTP

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesRemote file path to download
localPathYesLocal destination path
connectionIdNoConnection ID to usedefault
createDirsNoCreate local directories if they don't exist

Implementation Reference

  • The handleSSHDownloadFile method that executes the ssh_download_file tool logic. It retrieves an SSH connection, opens an SFTP session, reads a remote file via createReadStream, and writes it to the local filesystem.
    async handleSSHDownloadFile(args) {
      const { remotePath, localPath, connectionId = 'default', createDirs = true } = args;
    
      const conn = this.connections.get(connectionId);
      if (!conn) {
        throw new Error(`No active connection found for ID: ${connectionId}`);
      }
    
      const absoluteLocalPath = resolve(localPath);
    
      return new Promise((resolve, reject) => {
        conn.sftp((err, sftp) => {
          if (err) {
            return reject(new Error(`SFTP error: ${err.message}`));
          }
    
          const downloadFile = () => {
            const readStream = sftp.createReadStream(remotePath);
            let fileContent = Buffer.alloc(0);
    
            readStream.on('data', (chunk) => {
              fileContent = Buffer.concat([fileContent, chunk]);
            });
    
            readStream.on('end', () => {
              try {
                writeFileSync(absoluteLocalPath, fileContent);
                resolve({
                  content: [
                    {
                      type: 'text',
                      text: `Successfully downloaded ${remotePath} to ${absoluteLocalPath}`,
                    },
                  ],
                });
              } catch (error) {
                reject(new Error(`Failed to write local file: ${error.message}`));
              }
            });
    
            readStream.on('error', (err) => {
              reject(new Error(`Download failed: ${err.message}`));
            });
          };
    
          if (createDirs) {
            const localDir = dirname(absoluteLocalPath);
            try {
              mkdirSync(localDir, { recursive: true });
            } catch (error) {
              // Ignore mkdir errors if directory already exists
            }
          }
    
          downloadFile();
        });
      });
    }
  • The input schema definition for ssh_download_file, specifying remotePath (string, required), localPath (string, required), connectionId (string, default 'default'), and createDirs (boolean, default true).
    {
      name: 'ssh_download_file',
      description: 'Download a file from the remote server via SFTP',
      inputSchema: {
        type: 'object',
        properties: {
          remotePath: {
            type: 'string',
            description: 'Remote file path to download',
          },
          localPath: {
            type: 'string',
            description: 'Local destination path',
          },
          connectionId: {
            type: 'string',
            description: 'Connection ID to use',
            default: 'default',
          },
          createDirs: {
            type: 'boolean',
            description: 'Create local directories if they don\'t exist',
            default: true,
          },
        },
        required: ['remotePath', 'localPath'],
      },
  • index.js:37-39 (registration)
    The tool is registered in setupToolHandlers() via ListToolsRequestSchema handler and in the CallToolRequestSchema switch-case at lines 300-301.
    setupToolHandlers() {
      this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: [
Behavior2/5

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

No annotations provided, so description must carry burden. Only states basic action; lacks disclosure on error handling, overwrite behavior, directory creation (though schema has default), or requirement for prior connection.

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?

Single clear sentence with no extraneous information. Front-loaded with verb and resource.

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 4 parameters and no output schema or annotations, the description is too minimal. It does not explain return type, errors, or connection lifecycle, leaving gaps for effective agent usage.

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?

Schema description coverage is 100%, so baseline 3. Description adds no parameter details beyond schema, but is not required to given full schema coverage.

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

Purpose5/5

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

Clearly states verb 'download', resource 'file', method 'SFTP', and location 'remote server'. Distinguishes from sibling tools like ssh_upload_file and ssh_execute.

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?

No guidance on when to use this tool vs alternatives. Does not mention prerequisites like needing an active SSH connection via ssh_connect or relationship to sibling tools.

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/zibdie/SSH-MCP-Server'

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