Skip to main content
Glama

ssh_list_files

List files in a directory on a remote server via SSH connection. Specify connection ID and remote path to view directory contents.

Instructions

List files in a directory on the remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesID of an active SSH connection
remotePathYesPath to the directory on the remote server

Implementation Reference

  • The main handler function that executes the ssh_list_files tool logic: validates the SSH connection, initializes SFTP client, lists directory contents using readdir, formats file information (name, type, size, modified time), and returns the result.
    private async handleSSHListFiles(params: any) {
      const { connectionId, remotePath } = params;
      
      // Check if the connection exists
      if (!this.connections.has(connectionId)) {
        return {
          content: [{ type: "text", text: `No active SSH connection with ID: ${connectionId}` }],
          isError: true
        };
      }
      
      const { conn } = this.connections.get(connectionId)!;
      
      try {
        // Get SFTP client
        const sftp: any = await new Promise((resolve, reject) => {
          conn.sftp((err: Error | undefined, sftp: any) => {
            if (err) {
              reject(new Error(`Failed to initialize SFTP: ${err.message}`));
            } else {
              resolve(sftp);
            }
          });
        });
        
        // List files
        const files: any = await new Promise((resolve, reject) => {
          sftp.readdir(remotePath, (err: Error | undefined, list: any[]) => {
            if (err) {
              reject(new Error(`Failed to list files: ${err.message}`));
            } else {
              resolve(list);
            }
          });
        });
        
        const fileList = files.map((file: any) => ({
          filename: file.filename,
          isDirectory: (file.attrs.mode & 16384) === 16384,
          size: file.attrs.size,
          lastModified: new Date(file.attrs.mtime * 1000).toISOString()
        }));
    
        return {
          content: [{ 
            type: "text", 
            text: `Files in ${remotePath}:\n\n${JSON.stringify(fileList, null, 2)}` 
          }]
        };
      } catch (error: any) {
        return {
          content: [{ type: "text", text: `Failed to list files: ${error.message}` }],
          isError: true
        };
      }
  • Input schema definition for the ssh_list_files tool in the server's capabilities declaration.
    ssh_list_files: {
      description: "List files in a directory on the remote server",
      inputSchema: {
        type: "object",
        properties: {
          connectionId: {
            type: "string",
            description: "ID of an active SSH connection"
          },
          remotePath: {
            type: "string",
            description: "Path to the directory on the remote server"
          }
        },
        required: ["connectionId", "remotePath"]
      }
    },
  • src/index.ts:284-285 (registration)
    Registration of the tool handler in the switch statement within the CallToolRequestSchema request handler, dispatching calls to handleSSHListFiles.
    case 'ssh_list_files':
      return this.handleSSHListFiles(request.params.arguments);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the basic function but lacks critical details: it doesn't specify what the output looks like (e.g., list format, error handling), whether it requires specific permissions, or if there are rate limits. For a tool interacting with a remote server, this is a significant gap in transparency.

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, direct sentence that efficiently conveys the core purpose without any fluff. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly. Every word earns its place, with no wasted verbiage.

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 SSH operations and the lack of annotations or output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., file list, errors), behavioral aspects like timeouts, or integration with sibling tools (e.g., ssh_connect). For a tool with no structured output and no annotations, more context is needed to be fully helpful.

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, with clear documentation for both parameters (connectionId and remotePath). The description adds no additional semantic context beyond what the schema provides, such as format examples or constraints. According to the rules, with high schema coverage, the baseline is 3 even without param info in the description.

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 ('List files') and target ('in a directory on the remote server'), which is specific and unambiguous. It distinguishes from siblings like ssh_download_file or ssh_exec by focusing on directory listing rather than file transfer or command execution. However, it doesn't explicitly differentiate from hypothetical similar listing tools, keeping it at 4 rather than 5.

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 (e.g., needing an active SSH connection via ssh_connect), exclusions (e.g., not for listing local files), or comparisons to other tools. This leaves the agent to infer usage from the tool name and context alone.

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

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