Skip to content

Commit 886c978

Browse files
committed
style(shell_executor.py): format the execute method parameters for better readability
style(test_server.py): format call_tool function calls for improved readability in tests
1 parent 61ab7ea commit 886c978

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

mcp_shell_server/shell_executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def get_allowed_commands(self) -> list[str]:
9999
return list(self._get_allowed_commands())
100100

101101
async def execute(
102-
self, command: List[str], stdin: Optional[str] = None, directory: Optional[str] = None
102+
self,
103+
command: List[str],
104+
stdin: Optional[str] = None,
105+
directory: Optional[str] = None,
103106
) -> Dict[str, Any]:
104107
"""
105108
Execute a shell command with optional stdin input and working directory.

tests/test_server.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ async def test_call_tool_empty_command():
9191
async def test_call_tool_with_directory(temp_test_dir, monkeypatch):
9292
"""Test command execution in a specific directory"""
9393
monkeypatch.setenv("ALLOW_COMMANDS", "pwd")
94-
result = await call_tool("execute", {
95-
"command": ["pwd"],
96-
"directory": temp_test_dir
97-
})
94+
result = await call_tool(
95+
"execute", {"command": ["pwd"], "directory": temp_test_dir}
96+
)
9897
assert len(result) == 1
9998
assert isinstance(result[0], TextContent)
10099
assert result[0].type == "text"
@@ -112,17 +111,13 @@ async def test_call_tool_with_file_operations(temp_test_dir, monkeypatch):
112111
f.write("test content")
113112

114113
# Test ls command
115-
result = await call_tool("execute", {
116-
"command": ["ls"],
117-
"directory": temp_test_dir
118-
})
114+
result = await call_tool("execute", {"command": ["ls"], "directory": temp_test_dir})
119115
assert "test.txt" in result[0].text
120116

121117
# Test cat command
122-
result = await call_tool("execute", {
123-
"command": ["cat", "test.txt"],
124-
"directory": temp_test_dir
125-
})
118+
result = await call_tool(
119+
"execute", {"command": ["cat", "test.txt"], "directory": temp_test_dir}
120+
)
126121
assert result[0].text.strip() == "test content"
127122

128123

@@ -131,10 +126,9 @@ async def test_call_tool_with_nonexistent_directory(monkeypatch):
131126
"""Test command execution with a non-existent directory"""
132127
monkeypatch.setenv("ALLOW_COMMANDS", "ls")
133128
with pytest.raises(RuntimeError) as excinfo:
134-
await call_tool("execute", {
135-
"command": ["ls"],
136-
"directory": "/nonexistent/directory"
137-
})
129+
await call_tool(
130+
"execute", {"command": ["ls"], "directory": "/nonexistent/directory"}
131+
)
138132
assert "Directory does not exist: /nonexistent/directory" in str(excinfo.value)
139133

140134

@@ -149,10 +143,7 @@ async def test_call_tool_with_file_as_directory(temp_test_dir, monkeypatch):
149143
f.write("test content")
150144

151145
with pytest.raises(RuntimeError) as excinfo:
152-
await call_tool("execute", {
153-
"command": ["ls"],
154-
"directory": test_file
155-
})
146+
await call_tool("execute", {"command": ["ls"], "directory": test_file})
156147
assert f"Not a directory: {test_file}" in str(excinfo.value)
157148

158149

@@ -166,8 +157,5 @@ async def test_call_tool_with_nested_directory(temp_test_dir, monkeypatch):
166157
os.mkdir(nested_dir)
167158
nested_real_path = os.path.realpath(nested_dir)
168159

169-
result = await call_tool("execute", {
170-
"command": ["pwd"],
171-
"directory": nested_dir
172-
})
160+
result = await call_tool("execute", {"command": ["pwd"], "directory": nested_dir})
173161
assert result[0].text.strip() == nested_real_path

0 commit comments

Comments
 (0)