Skip to main content
Glama
test.js4.9 kB
#!/usr/bin/env node /** * Simple test script to verify the MCP server works * This script tests that the server can start and list its tools */ import { spawn } from 'child_process'; const testMCPServer = () => { return new Promise((resolve, reject) => { // Spawn the MCP server const server = spawn('node', ['index.js'], { cwd: '/home/user/Desktop/claude/mcp-derive', env: { ...process.env, DERIVE_ENVIRONMENT: 'testnet', }, }); let stderr = ''; let stdout = ''; let initialized = false; // Capture stderr for server logs server.stderr.on('data', (data) => { stderr += data.toString(); // Check if server initialized successfully if (stderr.includes('Derive MCP Server running on stdio')) { initialized = true; // Send initialize request const initRequest = { jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'test-client', version: '1.0.0', }, }, }; server.stdin.write(JSON.stringify(initRequest) + '\n'); // After initialize, request tool list setTimeout(() => { const listToolsRequest = { jsonrpc: '2.0', id: 2, method: 'tools/list', params: {}, }; server.stdin.write(JSON.stringify(listToolsRequest) + '\n'); // Give it time to respond then close setTimeout(() => { server.kill(); }, 1000); }, 500); } }); // Capture stdout for responses server.stdout.on('data', (data) => { stdout += data.toString(); }); server.on('close', (code) => { if (!initialized) { reject(new Error('Server failed to initialize\nStderr: ' + stderr)); return; } // Parse the responses const lines = stdout.trim().split('\n').filter(line => line.trim()); console.log('✓ Server started successfully'); console.log('✓ Server initialized'); // Look for the tools/list response for (const line of lines) { try { const response = JSON.parse(line); if (response.id === 2 && response.result && response.result.tools) { console.log(`✓ Found ${response.result.tools.length} tools:`); response.result.tools.forEach(tool => { console.log(` - ${tool.name}: ${tool.description.substring(0, 60)}...`); }); // Verify we have the expected tools const toolNames = response.result.tools.map(t => t.name); const expectedTools = [ 'get_currencies', 'get_instruments', 'get_ticker', 'get_tickers', 'get_orderbook', 'get_trade_history', 'get_funding_rate_history', 'get_spot_feed_history', 'get_option_settlement_history', 'get_liquidation_history', 'get_account', 'get_subaccounts', 'get_balance', 'get_positions', 'get_collaterals', 'get_margin', 'get_open_orders', 'get_orders_history', 'place_order', 'cancel_order', 'cancel_all_orders', 'replace_order', 'get_my_trades', 'get_funding_history', 'get_deposit_history', 'get_withdrawal_history', 'send_rfq', 'get_rfqs', 'execute_quote', 'get_liquidation_price', 'margin_watch', ]; const missingTools = expectedTools.filter(t => !toolNames.includes(t)); if (missingTools.length > 0) { reject(new Error(`Missing tools: ${missingTools.join(', ')}`)); return; } console.log('✓ All expected tools are present'); console.log('\n✅ MCP server test passed!'); resolve(); return; } } catch (e) { // Ignore parse errors, continue to next line } } reject(new Error('Did not receive tools/list response\nStdout: ' + stdout)); }); server.on('error', (error) => { reject(error); }); // Timeout after 10 seconds setTimeout(() => { server.kill(); reject(new Error('Test timeout after 10 seconds')); }, 10000); }); }; // Run the test console.log('Testing MCP Derive server...\n'); testMCPServer() .then(() => { process.exit(0); }) .catch((error) => { console.error('❌ Test failed:', error.message); process.exit(1); });

Latest Blog Posts

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/solenyaresearch0000/derive-MCP'

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