Skip to main content
Glama
widjis
by widjis

ssh_list_files

List files and directories on local or remote servers via SSH connections. Specify a directory path to view its contents, with options to include hidden files.

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

  • Main handler function that executes the ssh_list_files tool: lists files locally with fs.readdir (filtering hidden if not specified) or remotely via SSH 'ls -l(a)' command.
    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 used to parse and validate input arguments for the ssh_list_files tool.
    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)
    Tool definition registered in the ListTools response, specifying name, description, and input schema.
      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 in CallToolRequest handler switch statement that routes to the tool's 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?

With no annotations provided, the description carries full burden but reveals little about behavior. It doesn't disclose what permissions are needed, whether it's read-only (implied but not stated), what format the output takes (list vs tree vs details), error conditions, or rate limits. The mention of 'local or remote' is helpful context but insufficient for a mutation-free tool.

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 with zero waste. It's front-loaded with the core purpose and includes the key scope detail ('local or remote server'). Every word earns its place.

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?

For a tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the output looks like (file list format, metadata included), error behavior, or dependencies on other tools (like ssh_connect). Given the sibling tool complexity, more context about when this is the right choice would be valuable.

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 fully documents all three parameters. The description adds no additional parameter semantics beyond what's in the schema (like explaining 'local' special value for connectionId or path conventions). Baseline 3 is appropriate when schema does the heavy lifting.

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 the resources 'files and directories', and specifies the scope 'on local or remote server'. However, it doesn't explicitly differentiate from sibling tools like ssh_file_info (which gets metadata for a specific file) or ssh_execute (which could also list files via command execution).

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. It doesn't mention prerequisites (like needing an established SSH connection first), nor does it compare to sibling tools like ssh_execute (which could run 'ls' commands) or ssh_file_info (for single file details).

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

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