Skip to content

Commit 9ddabd2

Browse files
committed
test: cover interrupt exit for all transports
1 parent 60d99f3 commit 9ddabd2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

tests/server/mcpserver/test_server.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import base64
22
from pathlib import Path
3-
from typing import Any
3+
from typing import Any, Literal
44
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
@@ -73,10 +73,24 @@ def test_dependencies(self):
7373
mcp_no_deps = MCPServer("test")
7474
assert mcp_no_deps.dependencies == []
7575

76-
def test_stdio_keyboard_interrupt_exits_cleanly(self):
76+
@pytest.mark.parametrize("transport", ["stdio", "sse", "streamable-http"])
77+
def test_keyboard_interrupt_exits_cleanly(self, transport: Literal["stdio", "sse", "streamable-http"]):
7778
mcp = MCPServer("test")
7879

7980
with patch("mcp.server.mcpserver.server.anyio.run", side_effect=KeyboardInterrupt) as run:
81+
mcp.run(transport)
82+
83+
assert run.call_count == 1
84+
if transport == "stdio":
85+
run.assert_called_once_with(mcp.run_stdio_async)
86+
87+
def test_run_propagates_non_interrupt_errors(self):
88+
mcp = MCPServer("test")
89+
90+
with (
91+
patch("mcp.server.mcpserver.server.anyio.run", side_effect=RuntimeError("boom")) as run,
92+
pytest.raises(RuntimeError, match="boom"),
93+
):
8094
mcp.run("stdio")
8195

8296
run.assert_called_once_with(mcp.run_stdio_async)

0 commit comments

Comments
 (0)