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
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | SSH session ID | |
| path | Yes | Path to remove |
Implementation Reference
- src/fs-tools.ts:242-275 (handler)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'] } }, - src/mcp.ts:461-466 (handler)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) }] }; }