Skip to main content
Glama
safurrier

MCP Filesystem Server

move_file

Relocate or rename files and directories within the MCP Filesystem Server. Specify source and destination paths, with an option to overwrite existing files.

Instructions

Move or rename files and directories.

Args: source: Source path destination: Destination path overwrite: Whether to overwrite existing destination ctx: MCP context Returns: Success or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationYes
overwriteNo
sourceYes

Implementation Reference

  • Core handler function that validates paths, checks existence and overwrite permissions, then performs the file/directory move using shutil.move.
    async def move_file( self, source: Union[str, Path], destination: Union[str, Path], overwrite: bool = False, ) -> None: """Move or rename a file or directory. Args: source: Source path destination: Destination path overwrite: Whether to overwrite destination if it exists Raises: ValueError: If paths are outside allowed directories FileNotFoundError: If source does not exist FileExistsError: If destination exists and overwrite is False """ source_path, source_allowed = await self.validator.validate_path(source) if not source_allowed: raise ValueError(f"Source path outside allowed directories: {source}") dest_path, dest_allowed = await self.validator.validate_path(destination) if not dest_allowed: raise ValueError( f"Destination path outside allowed directories: {destination}" ) # Check if source exists if not source_path.exists(): raise FileNotFoundError(f"Source does not exist: {source}") # Check if destination exists and we're not overwriting if dest_path.exists() and not overwrite: raise FileExistsError(f"Destination already exists: {destination}") try: # Use shutil.move which handles cross-filesystem moves await anyio.to_thread.run_sync(shutil.move, source_path, dest_path) except (PermissionError, shutil.Error) as e: raise ValueError(f"Cannot move file: {e}")
  • MCP tool registration using @mcp.tool() decorator. This wrapper function handles the tool call, retrieves components, delegates to operations.move_file, and returns success/error messages.
    async def move_file( source: str, destination: str, ctx: Context, overwrite: bool = False, ) -> str: """Move or rename files and directories. Args: source: Source path destination: Destination path overwrite: Whether to overwrite existing destination ctx: MCP context Returns: Success or error message """ try: components = get_components() await components["operations"].move_file(source, destination, overwrite) return f"Successfully moved {source} to {destination}" except Exception as e: return f"Error moving file: {str(e)}"

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/safurrier/mcp-filesystem'

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