Skip to main content
Glama
devakone

MySQL Query MCP Server

by devakone

info

Retrieve MySQL database information from specified environments to understand database structures and configurations for query planning and data investigation.

Instructions

Get information about MySQL databases

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
environmentYesTarget environment to get information from

Implementation Reference

  • The handler function that implements the core logic of the 'info' tool: connects to the specified MySQL environment pool, executes queries to retrieve server version, status, variables, processlist, and databases, formats the information as JSON, and returns it.
    export async function runInfoTool(params: z.infer<typeof InfoToolSchema>): Promise<{ content: { type: string; text: string }[] }> { 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") as [any[], any[]]; const version = versionRows[0].version; // Get server status const [statusRows] = await connection.query("SHOW STATUS") as [any[], any[]]; const status = statusRows.reduce((acc: Record<string, string>, row: any) => { acc[row.Variable_name] = row.Value; return acc; }, {}); // Get server variables const [variableRows] = await connection.query("SHOW VARIABLES") as [any[], any[]]; const variables = variableRows.reduce((acc: Record<string, string>, row: any) => { acc[row.Variable_name] = row.Value; return acc; }, {}); // Get process list const [processRows] = await connection.query("SHOW PROCESSLIST") as [any[], any[]]; const processlist = processRows; // Get databases const [databaseRows] = await connection.query("SHOW DATABASES") as [any[], any[]]; const databases = databaseRows.map((row: any) => row.Database); const info: DatabaseInfo = { 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}`); } }
  • Zod schema definition for the 'info' tool input parameters, requiring an 'environment' from the enum ['local', 'development', 'staging', 'production'].
    // Info parameters schema export const InfoParams = z.object({ environment: Environment, }); export type InfoParameters = z.infer<typeof InfoParams>;
  • src/index.ts:65-72 (registration)
    Imports the 'info' tool's name, description, schema, and handler function from src/tools/info.js for use in MCP server registration.
    debug('Importing info tool...'); import { infoToolName, infoToolDescription, InfoToolSchema, runInfoTool, } from "./tools/info.js"; debug('Info tool imported:', { infoToolName });
  • src/index.ts:124-137 (registration)
    Registers the 'info' tool in the MCP server's capabilities object, specifying its description and input schema.
    [infoToolName]: { description: infoToolDescription, inputSchema: { type: "object", properties: { environment: { type: "string", enum: ["local", "development", "staging", "production"], description: "Target environment to get information from", }, }, required: ["environment"], }, },
  • src/index.ts:229-235 (registration)
    Handles 'info' tool calls in the MCP CallToolRequestSchema handler by validating arguments with InfoToolSchema and invoking runInfoTool.
    case infoToolName: { debug('Validating info tool arguments...'); const validated = InfoToolSchema.parse(args); debug('Validated info tool args:', validated); debug('Executing info tool...'); return await runInfoTool(validated); }

Other Tools

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

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