Skip to main content
Glama

llm_database_management

Manage database operations using LLM-generated commands with research-driven approaches for PostgreSQL, MongoDB, Redis, MySQL, and MariaDB.

Instructions

LLM-managed database operations with research-driven approach

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase type to use
actionYesDatabase action to perform
parametersNoAction parameters
llmInstructionsYesLLM instructions for command generation
researchFirstNoResearch best approach first
projectPathNoPath to project directory.
adrDirectoryNoDirectory containing ADR filesdocs/adrs

Implementation Reference

  • The primary handler function `llmDatabaseManagement` that executes LLM-driven database management operations. It supports multiple database types, researches best practices, generates commands via LLM, and simulates execution.
    export async function llmDatabaseManagement( args: { database: 'postgresql' | 'mongodb' | 'redis' | 'mysql' | 'mariadb'; action: string; parameters?: Record<string, any>; llmInstructions: string; researchFirst?: boolean; projectPath?: string; adrDirectory?: string; }, context?: ToolContext ): Promise<any> { const { database, action, parameters = {}, llmInstructions, researchFirst = true, projectPath, adrDirectory, } = args; if (!database || !action || !llmInstructions) { throw new McpAdrError( 'Database, action, and llmInstructions are required', 'MISSING_REQUIRED_PARAMS' ); } try { context?.info(`🗄️ Initializing ${database} database management for: ${action}`); context?.report_progress(0, 100); // Initialize research orchestrator const orchestrator = new ResearchOrchestrator(projectPath, adrDirectory); let researchResult = null; if (researchFirst) { context?.info('📚 Researching best practices and optimization strategies...'); context?.report_progress(20, 100); // Step 1: Research the best approach const researchQuery = ` How to ${action} in ${database}? Best practices for ${database} ${action} ${database} ${action} documentation and examples Performance optimization for ${database} ${action} Security considerations for ${database} ${action} ${llmInstructions} `; researchResult = await orchestrator.answerResearchQuestion(researchQuery); } // Step 2: Generate command using LLM context?.info('🤖 Generating database commands with LLM guidance...'); context?.report_progress(50, 100); const command = await generateDatabaseCommand({ database, action, parameters, research: researchResult, instructions: llmInstructions, }); // Step 3: Execute the command (simulated for now) context?.info(`🗄️ Executing ${database} operation...`); context?.report_progress(80, 100); const executionResult = await executeDatabaseCommand(command); context?.info('✅ Database operation complete!'); context?.report_progress(100, 100); return { content: [ { type: 'text', text: `# LLM-Managed Database Operation ## Operation Details - **Database**: ${database} - **Action**: ${action} - **Parameters**: ${JSON.stringify(parameters, null, 2)} ## LLM Instructions ${llmInstructions} ${ researchResult ? ` ## Research Results - **Confidence**: ${(researchResult.confidence * 100).toFixed(1)}% - **Sources**: ${researchResult.metadata.sourcesQueried.join(', ')} - **Research Summary**: ${researchResult.answer} ` : '' } ## Generated Command \`\`\`sql ${command.generated} \`\`\` ## Execution Result ${executionResult.success ? '✅ Success' : '❌ Failed'} ${executionResult.output ? `\n\`\`\`\n${executionResult.output}\n\`\`\`` : ''} ## LLM Analysis ${command.analysis || 'No analysis available'} ## Metadata - **Command Confidence**: ${(command.confidence * 100).toFixed(1)}% - **Timestamp**: ${new Date().toISOString()} - **Research-Driven**: ${researchFirst ? 'Yes' : 'No'} `, }, ], }; } catch (error) { throw new McpAdrError( `Database management operation failed: ${error instanceof Error ? error.message : String(error)}`, 'DATABASE_MANAGEMENT_ERROR' ); } }
  • Tool metadata and input schema definition in the central TOOL_CATALOG registry, used for MCP tool discovery and ListTools responses.
    TOOL_CATALOG.set('llm_database_management', { name: 'llm_database_management', shortDescription: 'Database management via LLM', fullDescription: 'Database operations with LLM assistance.', category: 'research', complexity: 'complex', tokenCost: { min: 2500, max: 5000 }, hasCEMCPDirective: true, // Phase 4.3: Complex tool - database management orchestration relatedTools: ['llm_cloud_management', 'llm_web_search'], keywords: ['database', 'management', 'llm', 'sql', 'nosql'], requiresAI: true, inputSchema: { type: 'object', properties: { operation: { type: 'string' }, databaseType: { type: 'string' }, }, required: ['operation'], }, });
  • Helper function to generate database-specific SQL/CLI commands using LLM analysis and research context (currently placeholder).
    async function generateDatabaseCommand(context: { database: string; action: string; parameters: Record<string, any>; research: any; instructions: string; }): Promise<{ generated: string; confidence: number; analysis: string }> { // const { loadAIConfig, getAIExecutor } = await import('../config/ai-config.js'); // const aiConfig = loadAIConfig(); // const executor = getAIExecutor(); // const prompt = ` // Generate a ${context.database} command for the following operation: // // Action: ${context.action} // Parameters: ${JSON.stringify(context.parameters, null, 2)} // Instructions: ${context.instructions} // // ${context.research ? ` // Research Context: // - Confidence: ${(context.research.confidence * 100).toFixed(1)}% // - Sources: ${context.research.metadata.sourcesQueried.join(', ')} // - Key Findings: ${context.research.answer} // ` : ''} // // Database Context: // ${getDatabaseContext(context.database)} // // Generate the appropriate command (SQL, CLI, or API call) and provide analysis of the approach. // `; // TODO: Implement LLM command generation when AI executor is available // const result = await executor.executeStructuredPrompt(prompt, { // type: 'object', // properties: { // command: { type: 'string' }, // confidence: { type: 'number' }, // analysis: { type: 'string' } // } // }); // return { // generated: result.data.command || '-- Command generation failed', // confidence: result.data.confidence || 0.5, // analysis: result.data.analysis || 'No analysis available' // }; // Placeholder implementation return { generated: `-- LLM command generation for ${context.database} ${context.action} not yet implemented`, confidence: 0.3, analysis: 'LLM command generation is not yet available. This is a placeholder implementation.', }; }
  • Helper function to execute the generated database command (currently simulated for safety).
    /** * Execute database command (simulated for now) */ async function executeDatabaseCommand(command: { generated: string; confidence: number; }): Promise<{ success: boolean; output: string }> { // For now, simulate command execution // In a real implementation, this would execute the actual database command return { success: command.confidence > 0.7, output: `Simulated execution of: ${command.generated}\n\nThis is a simulation. In production, this would execute the actual database command.`, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tosin2013/mcp-adr-analysis-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server