Skip to main content
Glama

move_dir

Move files or folders from a source path to a destination path on the MCP server. Simplifies directory management without terminal commands, returning status and path details for the transferred items.

Instructions

Use instead of terminal: Move a file or folder from path1 to path2.

    Args:
        path1: Source path of the file or folder to move
        path2: Destination path where the file or folder will be moved to

    Returns:
        A dictionary containing the status and paths of the moved file or folder

    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
path1No
path2No

Implementation Reference

  • The MoveDirOperation class implements the 'move_dir' tool logic. It defines the tool name, validates paths within the root directory, checks existence, creates parent dirs if needed, and moves using shutil.move. The __call__ method is the entrypoint invoked by the MCP server.
    @dataclass(unsafe_hash=True, slots=True)
    class MoveDirOperation(AsyncOperation):
        """Class to move a file or folder in the workspace."""
    
        name = "move_dir"
    
        def _move_folder(self, path1: str, path2: str) -> None:
            """Move a file or folder from path1 to path2.
    
            Args:
                path1: Source path
                path2: Destination path
    
            Raises:
                FileNotFoundError: If the source path does not exist
                FileExistsError: If the destination path already exists
    
            """
            root_path = self._root_path
            abs_path1 = self._validate_path_in_root(root_path, path1)
            abs_path2 = self._validate_path_in_root(root_path, path2)
    
            # Check if source exists
            source_path = Path(abs_path1)
            if not source_path.exists():
                raise FileNotFoundError(f"Source path does not exist: {path1}")
    
            # Check if destination exists
            dest_path = Path(abs_path2)
            if dest_path.exists():
                raise FileExistsError(f"Destination path already exists: {path2}")
    
            # Create parent directories of destination if they don't exist
            dest_path.parent.mkdir(parents=True, exist_ok=True)
    
            # Move the file or folder
            shutil.move(str(source_path), str(dest_path))
    
        async def __call__(self, path1: str = None, path2: str = None) -> Dict[str, Any]:
            """Move a file or folder from path1 to path2.
    
            Args:
                path1: Source path of the file or folder to move
                path2: Destination path where the file or folder will be moved to
    
            Returns:
                A dictionary containing the status and paths of the moved file or folder
    
            """
            # Handle both model and direct path input for backward compatibility
    
            self._move_folder(path1, path2)
            return {
                "status": "success",
                "message": f"Successfully moved from {path1} to {path2}",
                "path1": path1,
                "path2": path2,
            }
  • ToolFactory is instantiated and invoked with the 'dev_kit_mcp_server.tools' module, which transitively includes MoveDirOperation from file_sys.move, registering the 'move_dir' tool with the FastMCP server.
    # Register all tools
    tool_factory = ToolFactory(fastmcp)
    tool_factory(["dev_kit_mcp_server.tools"], root_dir=root_dir, commands_toml=commands_toml)
    return fastmcp
  • In _decorate_function, for each operation like MoveDirOperation, a Tool is created from its __call__ and name, then registered to the MCP server via add_fast_tool. This is where 'move_dir' gets registered.
    tool = self.create_tool(func)
    self.mcp.add_fast_tool(
        tool=tool,
    )
  • Private helper method in MoveDirOperation that performs path validation, existence checks, directory creation, and the actual shutil.move operation.
    def _move_folder(self, path1: str, path2: str) -> None:
        """Move a file or folder from path1 to path2.
    
        Args:
            path1: Source path
            path2: Destination path
    
        Raises:
            FileNotFoundError: If the source path does not exist
            FileExistsError: If the destination path already exists
    
        """
        root_path = self._root_path
        abs_path1 = self._validate_path_in_root(root_path, path1)
        abs_path2 = self._validate_path_in_root(root_path, path2)
    
        # Check if source exists
        source_path = Path(abs_path1)
        if not source_path.exists():
            raise FileNotFoundError(f"Source path does not exist: {path1}")
    
        # Check if destination exists
        dest_path = Path(abs_path2)
        if dest_path.exists():
            raise FileExistsError(f"Destination path already exists: {path2}")
    
        # Create parent directories of destination if they don't exist
        dest_path.parent.mkdir(parents=True, exist_ok=True)
    
        # Move the file or folder
        shutil.move(str(source_path), str(dest_path))
Install Server

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