Package-level declarations

Types

Link copied to clipboard
class BrowseFilesTool(context: Context) : McpTool

Lists the immediate contents of a directory, sandboxed to external storage via PathValidator (defaults to /sdcard). Directories sort first, then by name. Requires READ_EXTERNAL_STORAGE on API ≤32; uses File API access on API 33+. Under scoped storage (API 30+) the listing omits non-media files created by other apps — they are simply invisible to this app's File API view, with no error. Output: path, entries (each {name, path, size_bytes, last_modified, is_directory}, size_bytes is null for directories) capped at the limit param, and count.

Link copied to clipboard

Creates a directory (and any missing parents) under external storage, sandboxed via PathValidator. Succeeds without change when it already exists. Output: path, created (false when it was already there).

Link copied to clipboard

Deletes a file or directory under external storage, sandboxed via PathValidator. The storage root, its top-level folders (DCIM, Download, …) and anything under Android/ are refused. A non-empty directory is only removed with recursive, and then at most MAX_RECURSIVE_ENTRIES entries. Output: path, deleted_count (files and directories removed).

Link copied to clipboard

Serves files under external storage as MCP resources at file:///storage/... URIs, inside the same PathValidator sandbox as the file tools. A text file (by extension or content) of at most MAX_TEXT_BYTES that is valid UTF-8 comes back as text, byte-for-byte (line endings untouched); anything else as a base64 blob up to MAX_BYTES, so nothing is silently truncated or altered. Nothing is listed up front — clients find paths with browse_files / search_files. Hidden while read_file is gated off.

Link copied to clipboard
object FilesTools

Provider for the sandboxed file tools: BrowseFilesTool, ReadFileTool and SearchFilesTool, plus the write tools WriteFileTool, CreateDirectoryTool, MoveFileTool and DeleteFileTool. All paths are confined to external storage by PathValidator.

Link copied to clipboard

Moves or renames a file or directory; both ends must pass PathValidator. The storage root, its top-level folders (DCIM, Download, …) and Android/ can't be moved, matching what DeleteFileTool refuses, and nothing can be moved into Android/. An existing destination is replaced only with overwrite (never when it is a non-empty directory, the storage root or a top-level folder); it is set aside first and restored if the move fails, so a failed move loses nothing. A rename that only changes letter case works in place. Falls back to copy-then-delete when a plain rename fails (e.g. across volumes). Output: source, destination, is_directory.

Link copied to clipboard
class ReadFileTool(context: Context) : McpTool

Reads a text file's content, sandboxed to external storage via PathValidator. Files with an unrecognized extension are scanned for null bytes in the first 8 KB and rejected as binary if any are found. Output is truncated to the max_lines param and to a hard cap of ~1 MB of characters (MAX_CHARS); the file is streamed through a bounded buffer, so arbitrarily large files or single huge lines never load fully into memory. Requires READ_EXTERNAL_STORAGE on API ≤32; uses File API access on API 33+. Under scoped storage (API 30+) non-media files created by other apps are not readable. Output: path, content (newline-joined lines), lines_returned, truncated, and truncated_by ("max_lines", "max_chars", or null).

Link copied to clipboard
class SearchFilesTool(context: Context) : McpTool

Recursively searches for files and directories whose name contains a case-insensitive substring, sandboxed to external storage via PathValidator (defaults to /sdcard). Recursion is capped at depth 5, 20 000 visited entries and 10 s per call; unreadable directories are skipped silently, symlinks are neither followed nor reported, every result is re-checked against PathValidator, and the walk stops promptly when the call is cancelled. Requires READ_EXTERNAL_STORAGE on API ≤32; uses File API access on API 33+. Under scoped storage (API 30+) non-media files created by other apps are invisible to the walk. Output: query, search_path, results (each {name, path, size_bytes, last_modified, is_directory}) capped at the limit param, count, and search_incomplete (true when the visit/time budget ran out before the tree was fully searched).

Link copied to clipboard

Writes UTF-8 text to a file, sandboxed to external storage via PathValidator. mode is create (default; fails if the file exists), overwrite or append. Parent directories are created only with create_dirs. Content is capped at MAX_CHARS characters. Nothing under Android/ (other apps' data) can be written. On API 30+ only this app's own files and new files in shared folders such as Download/ or Documents/ are writable; see FilesTools for API 28-29. Output: path, bytes_written, size_bytes (file size afterwards), created.