MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / test_desktop

Function test_desktop

tests/test_examples.py:67–93  ·  view source on GitHub ↗

Test the desktop server

(tmp_path: Path, monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

65
66@pytest.mark.anyio
67async def test_desktop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
68 """Test the desktop server"""
69 # Build a real Desktop directory under tmp_path rather than patching
70 # Path.iterdir — a class-level patch breaks jsonschema_specifications'
71 # import-time schema discovery when this test happens to be the first
72 # tool call in an xdist worker.
73 desktop = tmp_path / "Desktop"
74 desktop.mkdir()
75 (desktop / "file1.txt").touch()
76 (desktop / "file2.txt").touch()
77 monkeypatch.setattr(Path, "home", lambda: tmp_path)
78
79 from examples.mcpserver.desktop import mcp
80
81 async with Client(mcp) as client:
82 # Test the sum function
83 result = await client.call_tool("sum", {"a": 1, "b": 2})
84 assert result == snapshot(CallToolResult(content=[TextContent(text="3")], structured_content={"result": 3}))
85
86 # Test the desktop resource
87 result = await client.read_resource("dir://desktop")
88 assert len(result.contents) == 1
89 content = result.contents[0]
90 assert isinstance(content, TextResourceContents)
91 assert isinstance(content.text, str)
92 assert "file1.txt" in content.text
93 assert "file2.txt" in content.text
94
95
96# TODO(v2): Change back to README.md when v2 is released

Callers

nothing calls this directly

Calls 5

ClientClass · 0.90
CallToolResultClass · 0.90
TextContentClass · 0.90
call_toolMethod · 0.45
read_resourceMethod · 0.45

Tested by

no test coverage detected