Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

health_check

Check MySQL database connection health and server status to verify operational readiness and diagnose connectivity issues.

Instructions

Check database connection health and get server status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the health_check tool logic: pings the database connection for latency, fetches server version and key status metrics (uptime, threads_connected, questions).
    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 with the MCP server, specifying the tool name, description, empty input schema, and 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, }; } );

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/nilsir/mcp-server-mysql'

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