1+ import asyncio
2+
3+ import pytest
4+ from mcp .client .session import ClientSession
5+ from mcp .client .stdio import StdioServerParameters , stdio_client
6+
7+
8+ @pytest .mark .asyncio
9+ async def test_mcp_server_tools () -> None :
10+ """Test that we can connect to the server and list available tools."""
11+ async with stdio_client (
12+ StdioServerParameters (command = "uv" , args = ["run" , "mcp-simple-tool" ])
13+ ) as (read , write ):
14+ async with ClientSession (read , write ) as session :
15+ await session .initialize ()
16+ tools = await session .list_tools ()
17+ assert tools is not None , "Tools list should not be None"
18+ assert tools .tools , "Server should provide at least one tool"
19+
20+
21+ @pytest .mark .asyncio
22+ async def test_mcp_server_mood () -> None :
23+ """Test that the mood tool works correctly."""
24+ async with stdio_client (
25+ StdioServerParameters (command = "uv" , args = ["run" , "mcp-simple-tool" ])
26+ ) as (read , write ):
27+ async with ClientSession (read , write ) as session :
28+ await session .initialize ()
29+ result = await session .call_tool ("mood" , {"question" : "How are you today?" })
30+ assert result is not None , "Mood response should not be None"
31+ assert "❤️" in str (result ), "Mood response should contain a heart emoji"
32+
33+
34+ if __name__ == "__main__" :
35+ asyncio .run (test_mcp_server_tools ())
36+ asyncio .run (test_mcp_server_mood ())
0 commit comments