On this page
Filesystem MCP tools scoped to an agent's worktree: read, write, edit, list, and search files with path traversal guard enforcement.
#src.wesktop.mcp_tools.filesystem
#src.wesktop.mcp_tools.filesystem
Filesystem MCP tools scoped to an agent's worktree: read, write, edit, list, and search files with path traversal guard enforcement.
All paths are relative to the worktree root. Traversal outside the worktree is blocked by _guard_path.
#_guard_path
def _guard_path(worktree: Path, relative: str) -> PathResolve a relative path and ensure it stays under the worktree.
Raises ValueError on path traversal attempts.
#read_file
def read_file(worktree: str, path: str) -> strRead a file from the worktree. Path is relative to worktree root.
#write_file
def write_file(worktree: str, path: str, content: str) -> strWrite content to a file in the worktree. Creates parent dirs as needed.
#edit_file
def edit_file(worktree: str, path: str, old_text: str, new_text: str) -> strFind and replace text in a file. Fails if old_text is not found.
#list_files
def list_files(worktree: str, path: str='') -> strList directory contents under the worktree.
Returns one entry per line: 'd
#search_files
def search_files(worktree: str, pattern: str, path: str='') -> strSearch file contents using ripgrep. Returns matching lines with context.