Skip to main content
Glama

fs_rmrf

Remove files or directories recursively on remote SSH servers to manage disk space and clean up unwanted data.

Instructions

Removes files or directories recursively

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
pathYesPath to remove

Implementation Reference

  • The handler function `removeRecursive` implements the logic for `fs_rmrf` by interacting with the SFTP session.
    export async function removeRecursive(
      sessionId: string,
      path: string
    ): Promise<boolean> {
      logger.debug('Removing path recursively', { sessionId, path });
      
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
      
      try {
        // Check if path exists and get its type
        const stats = await session.sftp.stat(path);
        
        if ((stats as any).isDirectory && (stats as any).isDirectory()) {
          // Remove directory recursively
          await session.sftp.rmdir(path, true); // recursive = true
        } else {
          // Remove file
          await session.sftp.delete(path);
        }
        
        logger.debug('Path removed successfully', { sessionId, path });
        return true;
      } catch (error) {
        logger.error('Failed to remove path', { sessionId, path, error });
        throw wrapError(
          error,
          ErrorCode.EFS,
          `Failed to remove ${path}. Check if the path exists and you have write permissions.`
        );
      }
    }
  • src/mcp.ts:245-255 (registration)
    Registration of `fs_rmrf` tool in the list of available tools.
      name: 'fs_rmrf',
      description: 'Removes files or directories recursively',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'SSH session ID' },
          path: { type: 'string', description: 'Path to remove' }
        },
        required: ['sessionId', 'path']
      }
    },
  • Handling the `fs_rmrf` tool call by invoking `removeRecursive` from `fs-tools.ts`.
    case 'fs_rmrf': {
      const params = FSPathSchema.parse(args);
      const result = await removeRecursive(params.sessionId, params.path);
      logger.info('Path removed', { sessionId: params.sessionId, path: params.path });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }

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