Skip to content

Commit be02215

Browse files
committed
test: cover interrupt exit for all transports
1 parent 8ee2cc6 commit be02215

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
@@ -74,10 +74,24 @@ def test_dependencies(self):
7474
mcp_no_deps = MCPServer("test")
7575
assert mcp_no_deps.dependencies == []
7676

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

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

8397
run.assert_called_once_with(mcp.run_stdio_async)

0 commit comments

Comments
 (0)