Skip to main content
Glama
zibdie
by zibdie

ssh_list_files

List files and directories on a remote server via SSH, with an option to show detailed information like permissions and file sizes.

Instructions

List files and directories on the remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathNoRemote directory path to list.
connectionIdNoConnection ID to usedefault
detailedNoShow detailed file information (permissions, size, etc.)

Implementation Reference

  • The `handleSSHListFiles` async function that executes the tool logic. It accepts remotePath, connectionId, and detailed args, establishes an SFTP connection, reads the remote directory, and formats output in either detailed (permissions/size/modified time) or simple (directories/files) format.
    async handleSSHListFiles(args) {
      const { remotePath = '.', connectionId = 'default', detailed = false } = args;
    
      const conn = this.connections.get(connectionId);
      if (!conn) {
        throw new Error(`No active connection found for ID: ${connectionId}`);
      }
    
      try {
        const sftp = await new Promise((resolve, reject) => {
          conn.sftp((err, sftp) => {
            if (err) {
              return reject(new Error(`SFTP error: ${err.message}`));
            }
            resolve(sftp);
          });
        });
    
        const list = await new Promise((resolve, reject) => {
          sftp.readdir(remotePath, (err, list) => {
            if (err) {
              return reject(new Error(`Failed to list directory: ${err.message}`));
            }
            resolve(list);
          });
        });
    
        let output = `Directory listing for: ${remotePath}\n\n`;
    
        if (detailed) {
          output += 'Permissions  Size     Modified                Name\n';
          output += '-'.repeat(60) + '\n';
          
          list.forEach(item => {
            const isDir = item.attrs.isDirectory() ? 'd' : '-';
            const perms = item.attrs.mode ? (item.attrs.mode & parseInt('777', 8)).toString(8).padStart(3, '0') : '???';
            const size = item.attrs.size ? item.attrs.size.toString().padStart(8) : '???';
            const mtime = item.attrs.mtime ? new Date(item.attrs.mtime * 1000).toISOString() : 'Unknown';
            
            output += `${isDir}${perms}      ${size}   ${mtime}  ${item.filename}\n`;
          });
        } else {
          const dirs = list.filter(item => item.attrs.isDirectory()).map(item => item.filename + '/');
          const files = list.filter(item => !item.attrs.isDirectory()).map(item => item.filename);
          
          if (dirs.length > 0) {
            output += 'Directories:\n';
            dirs.forEach(dir => output += `  ${dir}\n`);
            output += '\n';
          }
          
          if (files.length > 0) {
            output += 'Files:\n';
            files.forEach(file => output += `  ${file}\n`);
          }
          
          if (dirs.length === 0 && files.length === 0) {
            output += 'Directory is empty';
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: output,
            },
          ],
        };
      } catch (error) {
        throw error;
      }
    }
  • Tool registration entry defining inputSchema for ssh_list_files with three optional properties: remotePath (string, default '.'), connectionId (string, default 'default'), and detailed (boolean, default false).
    {
      name: 'ssh_list_files',
      description: 'List files and directories on the remote server',
      inputSchema: {
        type: 'object',
        properties: {
          remotePath: {
            type: 'string',
            description: 'Remote directory path to list',
            default: '.',
          },
          connectionId: {
            type: 'string',
            description: 'Connection ID to use',
            default: 'default',
          },
          detailed: {
            type: 'boolean',
            description: 'Show detailed file information (permissions, size, etc.)',
            default: false,
          },
        },
      },
    },
  • index.js:302-305 (registration)
    The case statement in the CallToolRequestSchema handler that routes the 'ssh_list_files' tool name to the handleSSHListFiles method.
    case 'ssh_list_files':
      return await this.handleSSHListFiles(args);
    default:
      throw new Error(`Unknown tool: ${name}`);
Behavior2/5

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

With no annotations, the description is the only source of behavioral info. It does not disclose traits like read-only nature, error handling, or recursion behavior.

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

Conciseness4/5

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

Single sentence is concise and front-loaded, but could benefit from additional succinct details.

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?

No output schema or description of return format. Missing details on output handling and error conditions.

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 is 3. The description adds no extra meaning beyond what the schema already provides.

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?

The description clearly states the action ('List') and resource ('files and directories on the remote server'), distinguishing it from sibling tools like ssh_execute or ssh_upload_file.

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

Usage Guidelines3/5

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

No explicit guidance on when to use this tool versus alternatives, but the context is clear for a basic listing operation.

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