Skip to main content
Glama

ssh_list_files

List files and directories on local or remote servers via SSH connections to browse directory contents and manage file systems.

Instructions

List files and directories on local or remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID (use "local" for local files)
remotePathYesDirectory path to list
showHiddenNoShow hidden files

Implementation Reference

  • The handler function that implements the core logic for the 'ssh_list_files' tool. It parses input parameters, handles local file listing using Node.js fs.readdir (with optional hidden file filtering), and remote listing via SSH execCommand with 'ls -l' or 'ls -la'. Returns formatted file listings or throws MCP errors on failure.
    private async handleSSHListFiles(args: unknown) {
      const params = ListFilesSchema.parse(args);
      
      try {
        if (params.connectionId === 'local') {
          // List local files
          const files = await fs.readdir(params.remotePath, { withFileTypes: true });
          const fileList = files
            .filter((file) => params.showHidden || !file.name.startsWith('.'))
            .map((file) => ({
              name: file.name,
              type: file.isDirectory() ? 'directory' : 'file',
              path: path.join(params.remotePath, file.name)
            }));
    
          return {
            content: [
              {
                type: 'text',
                text: `Files in ${params.remotePath}:\n${JSON.stringify(fileList, null, 2)}`,
              },
            ],
          };
        } else {
          // List remote files
          const ssh = connectionPool.get(params.connectionId);
          if (!ssh) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Connection ID '${params.connectionId}' not found`
            );
          }
    
          const lsCommand = params.showHidden ? 'ls -la' : 'ls -l';
          const result = await ssh.execCommand(`${lsCommand} "${params.remotePath}"`);
          
          if (result.code !== 0) {
            throw new Error(`ls command failed: ${result.stderr}`);
          }
    
          return {
            content: [
              {
                type: 'text',
                text: `Files in ${params.connectionId}:${params.remotePath}:\n${result.stdout}`,
              },
            ],
          };
        }
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `List files failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema defining the input parameters for the 'ssh_list_files' tool: connectionId (string, required), remotePath (string, required), showHidden (boolean, optional with default false).
    const ListFilesSchema = z.object({
      connectionId: z.string().describe('SSH connection ID (use "local" for local files)'),
      remotePath: z.string().describe('Directory path to list'),
      showHidden: z.boolean().default(false).describe('Show hidden files')
    });
  • src/index.ts:295-306 (registration)
    Registration of the 'ssh_list_files' tool metadata in the ListToolsRequestSchema handler, including name, description, and inputSchema definition for tool discovery.
      name: 'ssh_list_files',
      description: 'List files and directories on local or remote server',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: { type: 'string', description: 'SSH connection ID (use "local" for local files)' },
          remotePath: { type: 'string', description: 'Directory path to list' },
          showHidden: { type: 'boolean', default: false, description: 'Show hidden files' }
        },
        required: ['connectionId', 'remotePath']
      },
    },
  • src/index.ts:493-495 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that routes 'ssh_list_files' calls to the handleSSHListFiles handler function.
    case 'ssh_list_files':
      return await this.handleSSHListFiles(args);
    case 'ssh_file_info':
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It mentions the action ('List') but doesn't cover critical aspects like permissions needed, error handling (e.g., for invalid paths), output format, or whether it's a read-only operation. This is a significant gap for a tool that interacts with file systems.

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 front-loads the core purpose without unnecessary words. Every part earns its place by specifying the action, resource, and scope concisely.

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 no annotations and no output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., list format, error responses), behavioral traits like safety or permissions, or how it differs from siblings. For a file-listing tool in an SSH context, this leaves too many gaps for effective agent use.

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 the schema already documents all parameters fully. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't clarify path formats or connectionId usage). Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 verb ('List') and resource ('files and directories'), and specifies the scope ('on local or remote server'), which is helpful. However, it doesn't explicitly differentiate from sibling tools like 'ssh_file_info' (which might get metadata for a single file) or 'ssh_get_working_directory' (which might list the current directory), so it misses full sibling distinction.

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 like 'ssh_file_info' for single-file details or 'ssh_get_working_directory' for current directory listing. It lacks explicit when/when-not instructions or named alternatives, leaving usage context implied at best.

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/mahathirmuh/mcp-ssh-server'

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