environments
Retrieve a list of available MySQL database environments to identify which databases can be queried.
Instructions
List available MySQL database environments
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/environments.ts:20-72 (handler)Main handler that checks environment variables for each environment (local, development, staging, production) and returns a list of configured environments with DB_HOST, DB_USER, and DB_NAME.
export async function runEnvironmentsTool(_params?: z.infer<typeof EnvironmentsToolSchema>): Promise<{ content: { type: string; text: string }[] }> { try { debug('=== Running environments tool ==='); // Log all environment variables for debugging const envVars = Object.keys(process.env) .filter(key => key.includes('_DB_')) .reduce((acc, key) => ({ ...acc, [key]: process.env[key] }), {}); debug('Found DB-related environment variables:', envVars); const environments = Object.values(Environment.enum).filter(env => { const envPrefix = ENV_PREFIX_MAP[env]; // Check only for required variables that pools.ts uses const hasConfig = !!( process.env[`${envPrefix}_DB_HOST`] && process.env[`${envPrefix}_DB_USER`] && process.env[`${envPrefix}_DB_NAME`] ); debug(`Checking ${env} (${envPrefix}):`, { prefix: envPrefix, host: process.env[`${envPrefix}_DB_HOST`], user: process.env[`${envPrefix}_DB_USER`], db: process.env[`${envPrefix}_DB_NAME`], hasConfig }); return hasConfig; }); debug('Available environments:', environments); // Return the environments in the format expected by the MCP protocol return { content: [{ type: "text", text: JSON.stringify({ environments, count: environments.length, debug: { envVars, environments } }, null, 2), }], }; } catch (error) { debug('Error in environments tool:', error); throw error; } } - src/tools/environments.ts:6-6 (schema)Zod schema for the environments tool (empty object - no input parameters needed).
export const EnvironmentsToolSchema = z.object({}); - src/index.ts:30-35 (registration)Import of the environments tool components into the main server file.
import { environmentsToolName, environmentsToolDescription, EnvironmentsToolSchema, runEnvironmentsTool, } from "./tools/environments.js"; - src/index.ts:221-227 (registration)CallTool handler case that routes 'environments' tool requests to runEnvironmentsTool after schema validation.
case environmentsToolName: { debug('Validating environments tool arguments...'); const validated = EnvironmentsToolSchema.parse(args); debug('Validated environments tool args:', validated); debug('Executing environments tool...'); return await runEnvironmentsTool(validated); } - src/index.ts:183-191 (registration)ListTools handler registration of the environments tool (no input parameters required).
{ name: environmentsToolName, description: environmentsToolDescription, inputSchema: { type: "object", properties: {}, required: [], }, },