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
| Name | Required | Description | Default |
|---|---|---|---|
| new_name | No | ||
| path | Yes |
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))
- dev_kit_mcp_server/tools/__init__.py:11-11 (registration)Import statement that registers the RenameOperation class as part of the tools package.from .file_sys.rename import RenameOperation
- dev_kit_mcp_server/tools/file_sys/rename.py:15-15 (registration)Assignment of the tool name 'rename_file' within the RenameOperation class.name = "rename_file"