mysql-query-mcp-server
Version:
MySQL Query MCP server for AI assistants - execute read-only MySQL queries from Cursor IDE, Windsurf, or Claude Desktop
62 lines • 2.39 kB
JavaScript
import { InfoParams } from "../types/index.js";
import { config } from "dotenv";
import { pools } from "../db/pools.js";
config();
export const infoToolName = "info";
export const infoToolDescription = "Get information about MySQL databases";
export const InfoToolSchema = InfoParams;
export async function runInfoTool(params) {
const { environment } = params;
// Get connection pool
const pool = pools.get(environment);
if (!pool) {
throw new Error(`No connection pool available for environment: ${environment}`);
}
try {
const connection = await pool.getConnection();
try {
// Get server version
const [versionRows] = await connection.query("SELECT VERSION() as version");
const version = versionRows[0].version;
// Get server status
const [statusRows] = await connection.query("SHOW STATUS");
const status = statusRows.reduce((acc, row) => {
acc[row.Variable_name] = row.Value;
return acc;
}, {});
// Get server variables
const [variableRows] = await connection.query("SHOW VARIABLES");
const variables = variableRows.reduce((acc, row) => {
acc[row.Variable_name] = row.Value;
return acc;
}, {});
// Get process list
const [processRows] = await connection.query("SHOW PROCESSLIST");
const processlist = processRows;
// Get databases
const [databaseRows] = await connection.query("SHOW DATABASES");
const databases = databaseRows.map((row) => row.Database);
const info = {
version,
status: status.Uptime ? `Up ${status.Uptime} seconds` : "Unknown",
variables,
processlist,
databases,
};
return {
content: [{
type: "text",
text: JSON.stringify(info, null, 2),
}],
};
}
finally {
connection.release();
}
}
catch (error) {
const message = error instanceof Error ? error.message : "Unknown error occurred";
throw new Error(`Failed to get database info: ${message}`);
}
}
//# sourceMappingURL=info.js.map