// Simple MCP Server Tool Verification import { spawn } from 'child_process'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); console.log('='.repeat(60)); console.log('SPOTIFY MCP SERVER TOOL VERIFICATION'); console.log('='.repeat(60) + '\n'); // Start server let server = spawn('node', ['build/index.js'], { cwd: __dirname, stdio: ['pipe', 'pipe', 'pipe'] }); const pendingRequests = new Map(); let requestIdCounter = 1; // Track results const results = []; server.stdout.on('data', (data) => { const msg = data.toString(); // Parse each line as JSON response for (const line of msg.split('\n')) { if (!line.trim()) continue; try { const response = JSON.parse(line); const id = response.id; // Handle initialization response if (id === 1) { if (response.result?.protocolVersion) { console.log('✅ MCP Server Initialized'); console.log(` Protocol: ${response.result.protocolVersion}`); console.log(''); // Start tests after a delay setTimeout(runTests, 300); } else if (response.error) { console.log('❌ Initialization failed:', response.error.message); process.exit(1); } continue; } // Handle tool responses if (pendingRequests.has(id)) { const req = pendingRequests.get(id); if (response.error || response.result?.isError) { console.log(`❌ ${req.tool}: ERROR`); results.push({ name: req.tool, success: false }); req.resolve(); } else if (response.result?.content) { const text = response.result.content[0]?.text || ''; console.log(`✅ ${req.tool}: OK`); results.push({ name: req.tool, success: true }); req.resolve(); } else { console.log(`⚠️ ${req.tool}: Unknown response`); results.push({ name: req.tool, success: false }); req.resolve(); } pendingRequests.delete(id); } } catch (e) { // Not JSON or parse error - skip } } }); server.stderr.on('data', () => {}); // Send MCP request helper function sendRequest(toolName, args) { return new Promise(resolve => { const id = requestIdCounter++; pendingRequests.set(id, { tool: toolName, resolve }); const request = JSON.stringify({ jsonrpc: "2.0", id: id, method: "tools/call", params: { name: toolName, arguments: args } }) + '\n'; server.stdin.write(request); }); } // Send initialization request after a short delay to ensure stdin is ready setTimeout(() => { const initRequest = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "verify-tools", version: "1.0" } } }) + '\n'; server.stdin.write(initRequest); }, 100); // Run all tests async function runTests() { console.log('Testing MCP Server Tools...\n'); console.log('-'.repeat(60)); // ===== READ OPERATIONS ===== await sendRequest('searchSpotify', { query: 'rock', type: 'track', limit: 1 }); await new Promise(r => setTimeout(r, 300)); await sendRequest('getNowPlaying', {}); await new Promise(r => setTimeout(r, 300)); await sendRequest('getMyPlaylists', { limit: 2 }); await new Promise(r => setTimeout(r, 300)); await sendRequest('getQueue', {}); await new Promise(r => setTimeout(r, 300)); await sendRequest('getAvailableDevices', {}); await new Promise(r => setTimeout(r, 300)); // ===== PLAYBACK CONTROL ===== await sendRequest('pausePlayback', {}); await new Promise(r => setTimeout(r, 300)); await sendRequest('resumePlayback', {}); await new Promise(r => setTimeout(r, 300)); // ===== SEARCH VARIATIONS ===== await sendRequest('searchSpotify', { query: 'beatles', type: 'artist', limit: 1 }); await new Promise(r => setTimeout(r, 300)); // Print summary and exit after delay setTimeout(() => { console.log('\n' + '='.repeat(60)); console.log('VERIFICATION COMPLETE'); console.log('='.repeat(60) + '\n'); const successCount = results.filter(r => r.success).length; const failCount = results.length - successCount; console.log(`Total Tests: ${results.length}`); console.log(`✅ Passed: ${successCount}`); console.log(`❌ Failed: ${failCount}\n`); if (server) server.kill(); console.log('\nTools Verified:'); console.log('- searchSpotify (search tracks, artists)'); console.log('- getNowPlaying (current playback state)'); console.log('- getMyPlaylists (user playlists)'); console.log('- getQueue (playback queue)'); console.log('- getAvailableDevices (Spotify Connect devices)'); console.log('- pausePlayback / resumePlayback'); process.exit(0); }, 2000); }