Skip to main content
Glama

Safari MCP Server

by lxman
basic-tests.tsโ€ข4.87 kB
/** * Basic tests for Safari MCP Server * Run with: npm test (after adding test script to package.json) */ import { SafariDriverManager } from './safari-driver.js'; import { SafariMCPServer } from './safari-mcp-server.js'; // Mock tests - would need a proper testing framework like Jest for real tests export class SafariMCPTests { private driverManager: SafariDriverManager; private server: SafariMCPServer; constructor() { this.driverManager = new SafariDriverManager(); this.server = new SafariMCPServer(); } async runBasicTests(): Promise<void> { console.log('๐Ÿงช Running Safari MCP Server Tests...\n'); try { await this.testServerInitialization(); await this.testToolListRetrieval(); await this.testSystemRequirements(); console.log('\nโœ… All basic tests passed!'); } catch (error) { console.error('\nโŒ Test failed:', error); throw error; } } private async testServerInitialization(): Promise<void> { console.log('๐Ÿ“‹ Test 1: Server Initialization'); try { // Test that server can be created without errors const testServer = new SafariMCPServer(); console.log(' โœ… Server created successfully'); // Test driver manager creation const testDriverManager = new SafariDriverManager(); console.log(' โœ… Driver manager created successfully'); } catch (error) { console.error(' โŒ Server initialization failed:', error); throw error; } } private async testToolListRetrieval(): Promise<void> { console.log('\n๐Ÿ“‹ Test 2: Tool List Retrieval'); try { // This would normally require setting up the full MCP protocol // For now, we'll just verify the tools are defined correctly const expectedTools = [ 'safari_start_session', 'safari_navigate', 'safari_get_console_logs', 'safari_get_network_logs', 'safari_execute_script', 'safari_take_screenshot', 'safari_inspect_element', 'safari_get_performance_metrics', 'safari_get_page_info', 'safari_list_sessions', 'safari_close_session' ]; console.log(` โœ… Expected ${expectedTools.length} tools defined`); expectedTools.forEach(tool => { console.log(` - ${tool}`); }); } catch (error) { console.error(' โŒ Tool list test failed:', error); throw error; } } private async testSystemRequirements(): Promise<void> { console.log('\n๐Ÿ“‹ Test 3: System Requirements Check'); try { // Check if running on macOS const platform = process.platform; if (platform !== 'darwin') { console.log(' โš ๏ธ Not running on macOS - Safari automation not available'); console.log(` Current platform: ${platform}`); return; } console.log(' โœ… Running on macOS'); // Check Node.js version const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion < 18) { throw new Error(`Node.js 18+ required, current: ${nodeVersion}`); } console.log(` โœ… Node.js version: ${nodeVersion}`); // Check if safaridriver exists (would need child_process to verify) console.log(' โ„น๏ธ SafariDriver check skipped (requires file system access)'); } catch (error) { console.error(' โŒ System requirements check failed:', error); throw error; } } async testErrorHandling(): Promise<void> { console.log('\n๐Ÿ“‹ Test 4: Error Handling'); try { // Test handling of invalid session ID try { this.driverManager.getSession('non-existent-session'); console.log(' โœ… Invalid session handled correctly'); } catch (error) { // Expected to fail } // Test handling of malformed tool calls would go here console.log(' โœ… Error handling tests passed'); } catch (error) { console.error(' โŒ Error handling test failed:', error); throw error; } } } // CLI runner async function runTests() { const tests = new SafariMCPTests(); try { await tests.runBasicTests(); await tests.testErrorHandling(); console.log('\n๐ŸŽ‰ All tests completed successfully!'); console.log('\nNext steps:'); console.log('1. Ensure Safari is configured for automation'); console.log('2. Run: sudo safaridriver --enable'); console.log('3. Test with a real MCP client like Claude Desktop'); } catch (error) { console.error('\n๐Ÿ’ฅ Tests failed:', error); process.exit(1); } } // Run tests if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { runTests(); } export { runTests };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lxman/safari-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server