Skip to main content
Glama

fs_list

Lists directory contents on remote servers via SSH to view files and folders for navigation and management.

Instructions

Lists directory contents

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
pathYesDirectory path to list
pageNoPage number for pagination
limitNoMaximum items per page (default: 100)

Implementation Reference

  • The actual implementation of the listDirectory function, which handles the logic for listing contents of a directory on an SSH session.
    export async function listDirectory(
      sessionId: string,
      path: string,
      page?: number,
      limit: number = 100
    ): Promise<DirListResult> {
      logger.debug('Listing directory', { sessionId, path, page, limit });
      
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
      
      try {
        const fileList = await session.sftp.list(path);
        
        // Convert to our DirEntry format
        const entries: DirEntry[] = fileList.map((item: any) => {
          let type: DirEntry['type'] = 'other';
          if (item.type === 'd') {
            type = 'directory';
          } else if (item.type === '-') {
            type = 'file';
          } else if (item.type === 'l') {
            type = 'symlink';
          }
          
          return {
            name: item.name,
            type,
            size: item.size,
            mtime: new Date(item.modifyTime),
            mode: item.rights ? parseInt(item.rights.toString(), 8) : undefined
          };
        });
        
        // Apply pagination if requested
        if (page !== undefined) {
          const startIndex = page * limit;
          const endIndex = startIndex + limit;
          const paginatedEntries = entries.slice(startIndex, endIndex);
          
          const hasMore = endIndex < entries.length;
          const nextToken = hasMore ? String(page + 1) : undefined;
          
          logger.debug('Directory listed with pagination', {
            sessionId,
            path,
            total: entries.length,
            page,
            returned: paginatedEntries.length,
            hasMore
          });
          
          return {
            entries: paginatedEntries,
            nextToken
          };
        }
        
        logger.debug('Directory listed', { sessionId, path, count: entries.length });
        return { entries };
      } catch (error) {
        logger.error('Failed to list directory', { sessionId, path, error });
        throw wrapError(
          error,
          ErrorCode.EFS,
          `Failed to list directory ${path}. Check if the directory exists and is readable.`
        );
      }
    }
  • src/mcp.ts:447-452 (registration)
    Registration and call handling for the "fs_list" tool in the SSH MCP server.
    case 'fs_list': {
      const params = FSListSchema.parse(args);
      const result = await listDirectory(params.sessionId, params.path, params.page, params.limit);
      logger.info('Directory listed', { sessionId: params.sessionId, path: params.path });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • Input validation schema for the "fs_list" tool using zod.
    export const FSListSchema = z.object({
      sessionId: z.string().min(1),
      path: z.string().min(1),
      page: z.number().min(0).optional(),
      limit: z.number().min(1).max(1000).optional().default(100)
    });
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. 'Lists directory contents' implies a read-only operation, but it doesn't specify whether it's safe, what happens with invalid paths (e.g., errors vs. empty results), or if it supports pagination (implied by parameters but not stated). The description lacks details on permissions, rate limits, or output format, which are critical for a tool with SSH dependencies.

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 extremely concise with a single sentence 'Lists directory contents', which is front-loaded and wastes no words. It directly states the core function without unnecessary elaboration, making it efficient for quick understanding.

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 tool's complexity (involving SSH sessions and file system operations) and lack of annotations and output schema, the description is incomplete. It doesn't explain what the output contains (e.g., file list format), error conditions, or dependencies on SSH sessions, leaving significant gaps for an agent to use the tool effectively in context.

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 four parameters (sessionId, path, page, limit). The description adds no additional meaning beyond what's in the schema, such as explaining path formats (e.g., absolute vs. relative) or pagination behavior. 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.

Purpose3/5

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

The description 'Lists directory contents' clearly states the verb ('lists') and resource ('directory contents'), making the basic purpose understandable. However, it doesn't differentiate from sibling tools like fs_stat (which provides file metadata) or fs_read (which reads file contents), nor does it specify what type of listing is provided (e.g., file names, metadata, permissions).

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 when to choose fs_list over fs_stat for checking directory existence or over other file system tools, nor does it indicate prerequisites like requiring an active SSH session. This leaves the agent without context for tool selection.

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

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