@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
JavaScript
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();
}