move_files_by_glob
Moves all files matching a glob pattern from source directory to destination directory.
Instructions
Move all files matching a glob pattern from source_dir into destination_dir.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source_dir | Yes | ||
| pattern | Yes | ||
| destination_dir | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:133-167 (handler)The main handler function for the 'move_files_by_glob' tool. Uses @mcp.tool() decorator to register the function. It moves all files matching a glob pattern from source_dir to destination_dir, skipping files that already exist at the destination, and returns a JSON summary of what was moved/skipped.
@mcp.tool() def move_files_by_glob(source_dir: str, pattern: str, destination_dir: str) -> str: """Move all files matching a glob pattern from source_dir into destination_dir.""" source_root = _resolve_file_ops_path(source_dir) destination_root = _resolve_file_ops_path(destination_dir) if not source_root.is_dir(): raise ValueError(f"Source directory does not exist: {source_root}") destination_root.mkdir(parents=True, exist_ok=True) moved: list[str] = [] skipped: list[str] = [] for source in sorted(source_root.glob(pattern)): if not source.is_file(): continue destination = destination_root / source.name if destination.exists(): skipped.append(source.name) continue shutil.move(str(source), str(destination)) moved.append(source.name) summary = { "source_dir": str(source_root), "destination_dir": str(destination_root), "pattern": pattern, "moved_count": len(moved), "skipped_existing_count": len(skipped), "moved_files": moved, "skipped_existing_files": skipped, } return json.dumps(summary, indent=2) - server.py:133-134 (registration)The @mcp.tool() decorator on line 133 registers 'move_files_by_glob' as an MCP tool. No separate registration file exists; FastMCP's decorator pattern handles it inline.
@mcp.tool() def move_files_by_glob(source_dir: str, pattern: str, destination_dir: str) -> str: