Skip to content

Commit 9eaeea8

Browse files
committed
Merge branch 'fix-error-handling-and-warnings' into develop
2 parents b53f8d0 + 16d272b commit 9eaeea8

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ asyncio_mode = "strict"
4141
testpaths = "tests"
4242
# Set default event loop scope for async tests
4343
asyncio_default_fixture_loop_scope = "function"
44+
filterwarnings = [
45+
"ignore::RuntimeWarning:selectors:",
46+
"ignore::pytest.PytestUnhandledCoroutineWarning:",
47+
]
4448

4549
[tool.ruff]
4650
lint.select = [

src/mcp_shell_server/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""MCP Shell Server Package."""
22

3-
import asyncio
4-
53
from . import server
64

5+
__version__ = "0.1.0"
6+
__all__ = ["main", "server"]
7+
78

89
def main():
910
"""Main entry point for the package."""
11+
import asyncio
12+
1013
asyncio.run(server.main())
1114

1215

13-
# Optionally expose other important items at package level
14-
__all__ = ["main", "server"]
15-
__version__ = "0.1.0"
16+
if __name__ == "__main__":
17+
main()

src/mcp_shell_server/server.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import logging
23
import traceback
34
from collections.abc import Sequence
@@ -77,15 +78,17 @@ async def run_tool(self, arguments: dict) -> Sequence[TextContent]:
7778
if not directory:
7879
raise ValueError("Directory is required")
7980

80-
result = await self.executor.execute(command, directory, stdin, timeout)
81-
82-
# Raise error if command execution failed
83-
if result.get("error"):
84-
raise ValueError(result["error"]) # Changed from RuntimeError to ValueError
81+
try:
82+
result = await self.executor.execute(command, directory, stdin, timeout)
83+
except asyncio.TimeoutError as e:
84+
raise ValueError(f"Command timed out after {timeout} seconds") from e
8585

8686
# Convert executor result to TextContent sequence
8787
content: list[TextContent] = []
8888

89+
if result.get("error"):
90+
raise ValueError(result["error"])
91+
8992
if result.get("stdout"):
9093
content.append(TextContent(type="text", text=result["stdout"]))
9194
if result.get("stderr"):
@@ -118,7 +121,6 @@ async def call_tool(name: str, arguments: Any) -> Sequence[TextContent]:
118121

119122
except Exception as e:
120123
logger.error(traceback.format_exc())
121-
logger.error(f"Error during call_tool: {str(e)}")
122124
raise RuntimeError(f"Error executing command: {str(e)}") from e
123125

124126

tests/test_init.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ def test_main(mocker):
1717
# The first argument of the call should be a coroutine object
1818
args = mock_run.call_args[0]
1919
assert len(args) == 1
20-
assert asyncio.iscoroutine(args[0])
20+
coro = args[0]
21+
assert asyncio.iscoroutine(coro)
22+
# Clean up the coroutine
23+
coro.close()

0 commit comments

Comments
 (0)