Skip to content

Commit 6cd21d0

Browse files
authored
Skip directories on different filesystems when listing directory size (#221)
* Skip directories on different filesystems when listing directory size * Only fail when one error message is given If many error messages are printed to stderr, that means that du is traversing a large directory tree and some errors are expected. * Simpler heuristic for determining when to fail
1 parent 5dd9713 commit 6cd21d0

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/linux_mcp_server/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class CommandGroup(BaseModel):
184184
),
185185
"list_directories_size": CommandGroup(
186186
commands={
187-
"default": CommandSpec(args=("du", "-b", "--max-depth=1", "{path}")),
187+
"default": CommandSpec(args=("du", "-b", "--one-file-system", "{path}")),
188188
}
189189
),
190190
"list_directories_name": CommandGroup(

src/linux_mcp_server/tools/storage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ async def list_directories(
121121

122122
returncode, stdout, stderr = await cmd.run(host=host, path=path)
123123

124-
if returncode != 0:
124+
# The du command will exit with code 1 even if it gets some valid results.
125+
# Only error in the case where we got non-zero exit code and no data in stdout.
126+
if returncode != 0 and not stdout:
125127
raise ToolError(f"Error running command: command failed with return code {returncode}: {stderr}")
126128

127129
# Parse the output

tests/tools/test_storage.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ async def test_list_directories_nonexistent_path(self, tmp_path, mcp_client):
282282
"""Test list_directories with nonexistent path raises ToolError."""
283283
nonexistent = tmp_path / "nonexistent"
284284

285-
with pytest.raises(ToolError) as exc_info:
285+
with pytest.raises(ToolError, match="Error running command: command failed with return code 1"):
286286
await mcp_client.call_tool("list_directories", arguments={"path": str(nonexistent)})
287287

288-
assert "Error running command: command failed with return code 1" in str(exc_info.value)
289-
290288
async def test_list_directories_restricted_path(self, restricted_path, mcp_client):
291289
"""Test list_directories with restricted path raises ToolError."""
292290
with pytest.raises(ToolError) as exc_info:

0 commit comments

Comments
 (0)