mysql-query-mcp-server
Version:
MySQL Query MCP server for AI assistants - execute read-only MySQL queries from Cursor IDE, Windsurf, or Claude Desktop
60 lines • 2.41 kB
JavaScript
import { z } from "zod";
import { Environment } from "../types/index.js";
export const environmentsToolName = "environments";
export const environmentsToolDescription = "List available MySQL database environments";
export const EnvironmentsToolSchema = z.object({});
function debug(message, ...args) {
process.stderr.write(`DEBUG: ${message} ${args.map(arg => JSON.stringify(arg)).join(' ')}\n`);
}
// Map of environment to env var prefix
const ENV_PREFIX_MAP = {
local: 'LOCAL',
development: 'DEVELOPMENT',
staging: 'STAGING',
production: 'PRODUCTION'
};
export async function runEnvironmentsTool(_params) {
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;
}
}
//# sourceMappingURL=environments.js.map