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.`,
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. The description mentions 'research-driven approach' which hints at some behavior (possibly research before execution), but doesn't clarify what 'LLM-managed' means in practice - whether this tool executes database commands directly, generates code, or requires specific permissions. For a tool with 7 parameters including potentially destructive actions, this is inadequate behavioral transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise (one phrase) but under-specified rather than efficiently informative. While it's brief, it fails to front-load the most critical information about what the tool actually does. The single phrase doesn't earn its place by providing meaningful guidance beyond the tool name.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 7 parameters, no annotations, no output schema, and potentially destructive database operations, the description is severely incomplete. It doesn't explain what types of database operations are supported, what 'LLM-managed' entails, what the research component involves, or what the tool returns. The description fails to compensate for the lack of structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 7 parameters with descriptions. The tool description adds no additional parameter information beyond what's in the schema. It doesn't explain relationships between parameters or provide usage examples. The baseline score of 3 reflects adequate schema coverage without description enhancement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'LLM-managed database operations with research-driven approach' is vague and tautological. It restates the tool name ('llm_database_management') without specifying what operations are performed or what resources are affected. The phrase 'research-driven approach' adds some context but doesn't clarify the actual purpose. Compared to sibling tools like 'llm_cloud_management', it fails to distinguish what makes this tool unique for database operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, appropriate contexts, or exclusions. Given the sibling tool 'llm_cloud_management', there's no indication of when database management should be chosen over cloud management or other related tools. The description offers zero usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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