Skip to main content
Glama

fs_rename

Renames or moves files and directories on remote servers via SSH to organize or relocate data.

Instructions

Renames or moves a file/directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
fromYesSource path
toYesDestination path

Implementation Reference

  • The handler function that executes the rename operation using the SFTP session.
    export async function renameFile(
      sessionId: string,
      from: string,
      to: string
    ): Promise<boolean> {
      logger.debug('Renaming file', { sessionId, from, to });
      
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
      
      try {
        await session.sftp.rename(from, to);
        logger.debug('File renamed successfully', { sessionId, from, to });
        return true;
      } catch (error) {
        logger.error('Failed to rename file', { sessionId, from, to, error });
        throw wrapError(
          error,
          ErrorCode.EFS,
          `Failed to rename ${from} to ${to}. Check if the source exists and destination is writable.`
        );
      }
    }
  • The schema defining the expected input for the fs_rename tool.
    export const FSRenameSchema = z.object({
      sessionId: z.string().min(1),
      from: z.string().min(1),
      to: z.string().min(1)
    });
  • src/mcp.ts:257-268 (registration)
    Registration of the 'fs_rename' tool in the MCP server's tool list.
      name: 'fs_rename',
      description: 'Renames or moves a file/directory',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'SSH session ID' },
          from: { type: 'string', description: 'Source path' },
          to: { type: 'string', description: 'Destination path' }
        },
        required: ['sessionId', 'from', 'to']
      }
    },
  • Tool call handler case for 'fs_rename', which validates inputs and calls the renameFile function.
    case 'fs_rename': {
      const params = FSRenameSchema.parse(args);
      const result = await renameFile(params.sessionId, params.from, params.to);
      logger.info('Path renamed', { sessionId: params.sessionId, from: params.from, to: params.to });
      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