Skip to main content
Glama

rename_file

Rename files or folders directly via the dev-kit-mcp-server by specifying the path and new name, simplifying file management without using terminal commands.

Instructions

Use instead of terminal: Rename a file or folder.

Args: path: Path to the file or folder to rename new_name: New name for the file or folder (not a full path, just the name) Returns: A dictionary containing the status and paths of the renamed file or folder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
new_nameNo
pathYes

Implementation Reference

  • The __call__ method serves as the main handler for the 'rename_file' tool, executing the rename operation and returning a success response.
    async def __call__(self, path: str, new_name: str = None) -> Dict[str, Any]: """Rename a file or folder. Args: path: Path to the file or folder to rename new_name: New name for the file or folder (not a full path, just the name) Returns: A dictionary containing the status and paths of the renamed file or folder """ self._rename_file_or_folder(path, new_name) return { "status": "success", "message": f"Successfully renamed {path} to {new_name}", "path": path, "new_name": new_name, }
  • Helper method that implements the core logic for renaming a file or folder, including validation and the os.rename call.
    def _rename_file_or_folder(self, path: str, new_name: str) -> None: """Rename a file or folder. Args: path: Path to the file or folder to rename new_name: New name for the file or folder (not a full path, just the name) Raises: FileNotFoundError: If the path does not exist FileExistsError: If a file or folder with the new name already exists """ root_path = self._root_path abs_path = self._validate_path_in_root(root_path, path) # Check if source exists source_path = Path(abs_path) if not source_path.exists(): raise FileNotFoundError(f"Path does not exist: {path}") # Get the parent directory and create the new path parent_dir = source_path.parent new_path = parent_dir / new_name # Check if destination exists if new_path.exists(): raise FileExistsError(f"A file or folder with the name '{new_name}' already exists in the same directory") # Rename the file or folder os.rename(str(source_path), str(new_path))
  • Import statement that registers the RenameOperation class as part of the tools package.
    from .file_sys.rename import RenameOperation
  • Assignment of the tool name 'rename_file' within the RenameOperation class.
    name = "rename_file"

Other Tools

Related 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/DanielAvdar/dev-kit-mcp-server'

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