Skip to content

Commit 4d3dfc9

Browse files
Yoshihiro TakaharaYoshihiro Takahara
authored andcommitted
Improve login shell detection
- Use pwd module to get user's login shell - Add assertions to shell startup test
1 parent 4c40b81 commit 4d3dfc9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/mcp_shell_server/shell_executor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
import pwd
34
import shlex
45
import time
56
from typing import IO, Any, Dict, List, Optional, Tuple, Union
@@ -379,8 +380,11 @@ def _preprocess_command(self, command: List[str]) -> List[str]:
379380
return preprocessed_command
380381

381382
def _get_default_shell(self) -> str:
382-
"""Get the default shell from environment variables"""
383-
return os.environ.get("SHELL", "/bin/sh")
383+
"""Get the login shell of the current user"""
384+
try:
385+
return pwd.getpwuid(os.getuid()).pw_shell
386+
except (ImportError, KeyError):
387+
return os.environ.get("SHELL", "/bin/sh")
384388

385389
async def execute(
386390
self,

tests/test_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ async def test_shell_startup(monkeypatch, temp_test_dir):
332332
"shell_execute",
333333
{"command": ["ps", "-p", "$$", "-o", "command="], "directory": temp_test_dir},
334334
)
335-
print("Shell process info:", result) # Debug output
335+
assert len(result) == 1
336+
assert "sh" in result[0].text or "bash" in result[0].text or "zsh" in result[0].text
336337

337338

338339
@pytest.mark.asyncio
@@ -344,4 +345,3 @@ async def test_environment_variables(monkeypatch, temp_test_dir):
344345
{"command": ["env"], "directory": temp_test_dir},
345346
)
346347
assert len(result) == 1
347-
print(result[0].text) # 環境変数の内容を確認

0 commit comments

Comments
 (0)