@@ -1556,6 +1556,42 @@ async def test_read_resource_not_found(mcp_server: MCPServerStdio) -> None:
15561556 assert exc_info .value .message == 'Unknown resource: resource://does_not_exist'
15571557
15581558
1559+ async def test_list_resources_error (mcp_server : MCPServerStdio ) -> None :
1560+ """Test that list_resources converts McpError to MCPServerError."""
1561+ mcp_error = McpError (error = ErrorData (code = - 32603 , message = 'Failed to list resources' ))
1562+
1563+ async with mcp_server :
1564+ with patch .object (
1565+ mcp_server ._client , # pyright: ignore[reportPrivateUsage]
1566+ 'list_resources' ,
1567+ new = AsyncMock (side_effect = mcp_error ),
1568+ ):
1569+ with pytest .raises (MCPServerError , match = 'Failed to list resources' ) as exc_info :
1570+ await mcp_server .list_resources ()
1571+
1572+ # Verify the exception has the expected attributes
1573+ assert exc_info .value .code == - 32603
1574+ assert exc_info .value .message == 'Failed to list resources'
1575+
1576+
1577+ async def test_list_resource_templates_error (mcp_server : MCPServerStdio ) -> None :
1578+ """Test that list_resource_templates converts McpError to MCPServerError."""
1579+ mcp_error = McpError (error = ErrorData (code = - 32001 , message = 'Service unavailable' ))
1580+
1581+ async with mcp_server :
1582+ with patch .object (
1583+ mcp_server ._client , # pyright: ignore[reportPrivateUsage]
1584+ 'list_resource_templates' ,
1585+ new = AsyncMock (side_effect = mcp_error ),
1586+ ):
1587+ with pytest .raises (MCPServerError , match = 'Service unavailable' ) as exc_info :
1588+ await mcp_server .list_resource_templates ()
1589+
1590+ # Verify the exception has the expected attributes
1591+ assert exc_info .value .code == - 32001
1592+ assert exc_info .value .message == 'Service unavailable'
1593+
1594+
15591595def test_load_mcp_servers (tmp_path : Path ):
15601596 config = tmp_path / 'mcp.json'
15611597
0 commit comments