info
Retrieve detailed information from MySQL databases by specifying the target environment (local, development, staging, production). Facilitates database exploration and data investigation for AI-powered tools.
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 main handler function that implements the 'info' tool: connects to the MySQL connection pool for the specified environment, executes queries to fetch server version, status summary, global variables, process list, and list of databases, then returns the information as a formatted JSON string.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 the input parameters for the 'info' tool: requires an 'environment' field (enum: 'local', 'development', 'staging', 'production'). This schema is exported and aliased as InfoToolSchema in the handler file.// Info parameters schema export const InfoParams = z.object({ environment: Environment, }); export type InfoParameters = z.infer<typeof InfoParams>;
- src/index.ts:124-137 (registration)Registration of the 'info' tool in the MCP server's capabilities object, specifying its description and input schema for tool discovery.[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)Dispatch logic in the CallTool request handler: validates arguments using InfoToolSchema and invokes the runInfoTool handler for the 'info' tool.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); }
- src/index.ts:184-197 (registration)'info' tool specification returned by the ListTools request handler, including name, description, and input schema.name: infoToolName, description: infoToolDescription, inputSchema: { type: "object", properties: { environment: { type: "string", enum: ["local", "development", "staging", "production"], description: "Target environment to get information from", }, }, required: ["environment"], }, },