info
Retrieve metadata about MySQL databases in a specified environment. Provides essential details needed for database analysis and query planning.
Instructions
Get information about MySQL databases
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environment | Yes | Target environment to get information from |
Implementation Reference
- src/tools/info.ts:9-69 (handler)Main handler function for the 'info' tool. Takes environment parameter, connects to MySQL, and returns version, status, variables, processlist, and databases.
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}`); } } - src/types/index.ts:27-31 (schema)Zod schema defining input parameters for the info tool: requires an 'environment' field (enum: local, development, staging, production).
// Info parameters schema export const InfoParams = z.object({ environment: Environment, }); export type InfoParameters = z.infer<typeof InfoParams>; - src/types/index.ts:45-52 (schema)TypeScript interface defining the return shape of the info tool: version, status, variables, processlist, and databases.
// Database info result type export interface DatabaseInfo { version: string; status: string; variables: Record<string, string>; processlist: unknown[]; databases: string[]; } - src/index.ts:109-122 (registration)Registration of the 'info' tool in the MCP server capabilities (server constructor).
[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:214-220 (registration)CallTool handler dispatching to runInfoTool when the tool name is 'info', with Zod schema validation of arguments.
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); }