UNPKG

@rolandohuber/mysql-mcp-server

Version:

A comprehensive MCP server for MySQL database operations with 16 tools, multi-transport support, and intelligent test data generation

150 lines (126 loc) โ€ข 3.57 kB
#!/usr/bin/env node const http = require('http'); // Simple HTTP test for MCP server async function testMCPConnection() { const data = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} }); const options = { hostname: 'localhost', port: 3001, path: '/mcp/call', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; return new Promise((resolve, reject) => { const req = http.request(options, (res) => { let responseData = ''; res.on('data', (chunk) => { responseData += chunk; }); res.on('end', () => { try { const result = JSON.parse(responseData); resolve(result); } catch (error) { reject(new Error(`Parse error: ${responseData}`)); } }); }); req.on('error', reject); req.write(data); req.end(); }); } // Test individual tools async function testTool(toolName, args = {}) { const data = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: toolName, arguments: args } }); const options = { hostname: 'localhost', port: 3001, path: '/mcp/call', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; return new Promise((resolve, reject) => { const req = http.request(options, (res) => { let responseData = ''; res.on('data', (chunk) => { responseData += chunk; }); res.on('end', () => { try { const result = JSON.parse(responseData); resolve(result); } catch (error) { reject(new Error(`Parse error: ${responseData}`)); } }); }); req.on('error', reject); req.write(data); req.end(); }); } async function main() { console.log('๐Ÿ”— Testing MCP MySQL Server Connection...\n'); try { // Test tools list console.log('๐Ÿ“‹ Listing available tools...'); const toolsList = await testMCPConnection(); if (toolsList.error) { console.error('โŒ Error listing tools:', toolsList.error.message); return; } console.log('โœ… Available tools:'); if (toolsList.result && toolsList.result.tools) { toolsList.result.tools.forEach(tool => { console.log(` โ€ข ${tool.name}: ${tool.description}`); }); } console.log('\n๐Ÿงช Testing individual tools...\n'); // Test ping console.log('๐Ÿ“ก Testing mysql.ping...'); const pingResult = await testTool('mysql.ping'); console.log('Result:', pingResult.result ? 'โœ… Connected' : 'โŒ Failed'); // Test version console.log('\n๐Ÿ”ข Testing mysql.version...'); const versionResult = await testTool('mysql.version'); if (versionResult.result) { console.log('MySQL Version:', versionResult.result); } // Test list tables console.log('\n๐Ÿ“Š Testing mysql.listTables...'); const tablesResult = await testTool('mysql.listTables'); if (tablesResult.result) { console.log('Tables found:', tablesResult.result.length); tablesResult.result.slice(0, 3).forEach(table => { console.log(` โ€ข ${table}`); }); } } catch (error) { console.error('โŒ Connection failed:', error.message); console.log('\n๐Ÿ’ก Make sure the MCP server is running:'); console.log(' npm run dev'); } } if (require.main === module) { main(); }