Skip to main content

File Tools

Benchmarked against: Anthropic — Text editor tool Tools: ubi_read_file, ubi_write_file, ubi_edit_file, ubi_list_directory, ubi_search_code Server: Local UBI MCP Security: Restricted to allowed directories

File tools provide agents with the ability to read, write, edit, and search files on the local filesystem. They are the MCP equivalent of Claude Code's built-in Read, Write, Edit, and Grep tools, but available to any agent connected to the Local UBI server.


Tools reference

ubi_read_file

Read file contents with line numbers, supporting pagination.

Parameters:

ParameterTypeRequiredDefaultDescription
pathstringYesAbsolute file path
offsetnumberNo0Line number to start from (0-based)
limitnumberNo2000Max lines to return

Example:

ubi_read_file(path="/Users/xy2024air15/Documents/SuperPortia/CLAUDE.md")

Response:

{
"content": " 1| # SuperPortia — 小克 Boot Config\n 2| \n 3| ## Identity\n...",
"total_lines": 45,
"offset": 0,
"limit": 2000
}

For large files, use pagination:

ubi_read_file(
path="/path/to/large-file.py",
offset=100,
limit=50
)
# Returns lines 100-149

ubi_write_file

Write content to a file. Creates the file if it doesn't exist, or overwrites if it does.

Safety feature: If the file already exists, a .bak backup is automatically created before overwriting.

Parameters:

ParameterTypeRequiredDescription
pathstringYesAbsolute file path
contentstringYesFull file content to write

Example:

ubi_write_file(
path="/Users/xy2024air15/Documents/SuperPortia/scripts/example.sh",
content="#!/bin/bash\necho 'Hello from SuperPortia'\n"
)

Response:

{
"success": true,
"path": "/Users/xy2024air15/Documents/SuperPortia/scripts/example.sh",
"backup": "/Users/xy2024air15/Documents/SuperPortia/scripts/example.sh.bak",
"bytes_written": 42
}

ubi_edit_file

Exact string replacement in a file. Like Claude Code's Edit tool — find an exact string and replace it.

Parameters:

ParameterTypeRequiredDefaultDescription
pathstringYesAbsolute file path
old_stringstringYesText to find (must be exact match)
new_stringstringYesReplacement text
replace_allbooleanNofalseReplace all occurrences (vs. unique match)

Example — single replacement:

ubi_edit_file(
path="/path/to/config.py",
old_string='DEFAULT_ENGINE = "groq"',
new_string='DEFAULT_ENGINE = "gemini"'
)

Example — replace all occurrences:

ubi_edit_file(
path="/path/to/code.py",
old_string="old_function_name",
new_string="new_function_name",
replace_all=True
)

Response:

{
"success": true,
"replacements": 1,
"path": "/path/to/config.py"
}

Error — non-unique match:

{
"error": "old_string found 3 times in file. Use replace_all=True or provide a more specific string.",
"occurrences": 3
}

ubi_list_directory

List directory contents, optionally as a recursive tree.

Parameters:

ParameterTypeRequiredDefaultDescription
pathstringYesAbsolute directory path
recursivebooleanNofalseShow tree structure
max_depthnumberNo3Max depth for recursive listing

Example — flat listing:

ubi_list_directory(path="/Users/xy2024air15/Documents/SuperPortia/ub")

Example — recursive tree:

ubi_list_directory(
path="/Users/xy2024air15/Documents/SuperPortia/docs-site/docs",
recursive=True,
max_depth=2
)

ubi_search_code

Search for patterns in code files using grep/ripgrep.

Parameters:

ParameterTypeRequiredDefaultDescription
patternstringYesRegex pattern to search for
pathstringNoFirst allowed dirDirectory to search in
file_globstringNoAll filesFile pattern filter (e.g., *.py, *.ts)
max_resultsnumberNo50Max matching lines to return

Example:

ubi_search_code(
pattern="ingest_fragment",
path="/Users/xy2024air15/Documents/SuperPortia/ub",
file_glob="*.py"
)

Response:

{
"matches": [
{
"file": "/Users/.../ub/mcp_server.py",
"line": 142,
"content": "async def ingest_fragment(path: str, input_type: str = 'file'):"
},
{
"file": "/Users/.../ub/worker.py",
"line": 89,
"content": " result = await ingest_fragment(content, source='api')"
}
],
"total_matches": 2
}

Comparison with Claude Code built-in tools

When running in Claude Code CLI, agents have access to both UBI file tools and Claude Code's native tools:

OperationUBI ToolClaude Code ToolDifference
Read fileubi_read_fileReadUBI returns JSON; Read returns formatted text
Write fileubi_write_fileWriteUBI creates .bak backup automatically
Edit fileubi_edit_fileEditSame exact-match replacement model
List dirubi_list_directoryGlob / Bash lsUBI supports recursive tree
Search codeubi_search_codeGrepSimilar capabilities, different output format

When to use which:

ContextUse
Interactive CLI sessionClaude Code native tools (faster, tighter integration)
Dispatch worker executionUBI tools (available via MCP, sandboxed)
Cross-agent automationUBI tools (any agent can use via MCP)
File operations needing backupUBI ubi_write_file (automatic .bak)

Security

All file tools enforce directory restrictions:

RuleEnforcement
Allowed directories onlyOperations outside configured dirs return error
No symlink traversalSymlinks that escape allowed dirs are blocked
Automatic backupubi_write_file creates .bak before overwriting
Read-only by defaultWrite/edit require explicit allowed directory config

PageRelationship
MCP Tools OverviewFull tool catalog
Run CommandShell commands for operations beyond file tools
Computer UseBrowser-based alternative
File Ingestion (MTAAA)Processing files through classification pipeline