health_check
Check MySQL database connection health and server status to verify connectivity and operational state.
Instructions
Check database connection health and get server status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:602-641 (handler)The handler function for the 'health_check' tool. It tests the database connection with a ping, measures latency, retrieves the MySQL server version, uptime, connected threads, and total queries executed, returning a structured health status.async () => { const startTime = Date.now(); const p = await getPool(); // Test connection with ping const connection = await p.getConnection(); await connection.ping(); connection.release(); const pingLatency = Date.now() - startTime; // Get server version and status const [versionRows] = await p.query<RowDataPacket[]>("SELECT VERSION() as version"); const [statusRows] = await p.query<RowDataPacket[]>("SHOW STATUS WHERE Variable_name IN ('Uptime', 'Threads_connected', 'Questions')"); const version = versionRows[0]?.version || "unknown"; const status: Record<string, string> = {}; for (const row of statusRows) { status[row.Variable_name] = row.Value; } const output = { healthy: true, pingLatencyMs: pingLatency, serverVersion: version, uptime: status.Uptime ? parseInt(status.Uptime, 10) : null, threadsConnected: status.Threads_connected ? parseInt(status.Threads_connected, 10) : null, totalQueries: status.Questions ? parseInt(status.Questions, 10) : null, }; return { content: [ { type: "text" as const, text: `Database connection healthy (ping: ${pingLatency}ms, version: ${version})`, }, ], structuredContent: output, }; }
- src/index.ts:598-642 (registration)Registers the 'health_check' tool on the MCP server, specifying the tool name, description, empty input schema, and the handler function.server.tool( "health_check", "Check database connection health and get server status", {}, async () => { const startTime = Date.now(); const p = await getPool(); // Test connection with ping const connection = await p.getConnection(); await connection.ping(); connection.release(); const pingLatency = Date.now() - startTime; // Get server version and status const [versionRows] = await p.query<RowDataPacket[]>("SELECT VERSION() as version"); const [statusRows] = await p.query<RowDataPacket[]>("SHOW STATUS WHERE Variable_name IN ('Uptime', 'Threads_connected', 'Questions')"); const version = versionRows[0]?.version || "unknown"; const status: Record<string, string> = {}; for (const row of statusRows) { status[row.Variable_name] = row.Value; } const output = { healthy: true, pingLatencyMs: pingLatency, serverVersion: version, uptime: status.Uptime ? parseInt(status.Uptime, 10) : null, threadsConnected: status.Threads_connected ? parseInt(status.Threads_connected, 10) : null, totalQueries: status.Questions ? parseInt(status.Questions, 10) : null, }; return { content: [ { type: "text" as const, text: `Database connection healthy (ping: ${pingLatency}ms, version: ${version})`, }, ], structuredContent: output, }; } );
- src/index.ts:601-601 (schema)Input schema for the 'health_check' tool, which takes no parameters.{},