Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//This script shows how to add a link to the Tools menu

mw.hook('wikipage.content').add(function() {
    mw.loader.using(['mediawiki.util'], function() {
        
        // Only add the link if it doesn't already exist
        if (!document.getElementById('t-mycustomtool2')) {	//linkid
            mw.util.addPortletLink(
                'p-tb',										//Target portlet ID (Tools menu)
                'https://tools.wmflabs.org/',				//linkurl
                'Wikimedia Tools',							//linktext
                't-mycustomtool2',							//linkid
                'Access Wikimedia developer tools'			//tooltip
            );
        }
    });
});