Skip to content

Commit 73f2b1b

Browse files
committed
test: fix pipe union CI coverage
1 parent 24ffb7c commit 73f2b1b

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

tests/server/mcpserver/test_func_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def func_dict_str_int() -> dict[str, int]: # pragma: no cover
677677
def func_union() -> str | int: # pragma: no cover
678678
return "hello"
679679

680-
def func_pipe_union_containers() -> dict | list | str: # pragma: no cover
680+
def func_pipe_union_containers() -> dict[str, int] | list[str] | str: # pragma: no cover
681681
return {"a": 1}
682682

683683
def func_optional() -> str | None: # pragma: no cover
@@ -717,8 +717,8 @@ def func_optional() -> str | None: # pragma: no cover
717717
"result": {
718718
"title": "Result",
719719
"anyOf": [
720-
{"additionalProperties": True, "type": "object"},
721-
{"items": {}, "type": "array"},
720+
{"additionalProperties": {"type": "integer"}, "type": "object"},
721+
{"items": {"type": "string"}, "type": "array"},
722722
{"type": "string"},
723723
],
724724
}

tests/server/mcpserver/test_server.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
from pathlib import Path
3+
from types import TracebackType
34
from typing import Any
45
from unittest.mock import AsyncMock, MagicMock, patch
56

@@ -65,6 +66,47 @@ async def test_create_server(self):
6566
assert len(mcp.icons) == 1
6667
assert mcp.icons[0].src == "https://example.com/icon.png"
6768

69+
def test_run_stdio_transport(self):
70+
mcp = MCPServer("test")
71+
72+
with patch("mcp.server.mcpserver.server.anyio.run") as run:
73+
mcp.run("stdio")
74+
75+
run.assert_called_once_with(mcp.run_stdio_async)
76+
77+
def test_run_unknown_transport(self):
78+
mcp = MCPServer("test")
79+
80+
with pytest.raises(ValueError, match="Unknown transport: websocket"):
81+
mcp.run("websocket") # type: ignore[arg-type]
82+
83+
async def test_run_stdio_async_uses_stdio_transport(self):
84+
class StdioServer:
85+
async def __aenter__(self):
86+
return "read", "write"
87+
88+
async def __aexit__(
89+
self,
90+
exc_type: type[BaseException] | None,
91+
exc: BaseException | None,
92+
tb: TracebackType | None,
93+
) -> None:
94+
return None
95+
96+
mcp = MCPServer("test")
97+
run = AsyncMock()
98+
99+
with (
100+
patch("mcp.server.mcpserver.server.stdio_server", return_value=StdioServer()),
101+
patch.object(mcp._lowlevel_server, "run", run),
102+
):
103+
await mcp.run_stdio_async()
104+
105+
run.assert_awaited_once()
106+
await_args = run.await_args
107+
assert await_args is not None
108+
assert await_args.args[:2] == ("read", "write")
109+
68110
def test_dependencies(self):
69111
"""Dependencies list is read by `mcp install` / `mcp dev` CLI commands."""
70112
mcp = MCPServer("test", dependencies=["pandas", "numpy"])

0 commit comments

Comments
 (0)