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
| Name | Required | Description | Default |
|---|---|---|---|
| environment | Yes | Target environment to get information from |
Implementation Reference
- src/tools/info.ts:13-73 (handler)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}`); } }
- src/types/index.ts:27-31 (schema)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); }