Skip to main content
Glama
HenkDz

PostgreSQL MCP Server

pg_analyze_database

Analyze PostgreSQL database configuration, performance, or security to identify optimization opportunities and potential issues.

Instructions

Analyze PostgreSQL database configuration and performance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionStringNoPostgreSQL connection string (optional if POSTGRES_CONNECTION_STRING environment variable or --connection-string CLI option is set)
analysisTypeNoType of analysis to perform

Implementation Reference

  • The main handler for the pg_analyze_database tool. Validates input, resolves connection string, executes analysis, and returns JSON-formatted result.
    export const analyzeDatabaseTool: PostgresTool = {
      name: toolDefinition.name,
      description: toolDefinition.description,
      inputSchema: toolDefinition.inputSchema,
      execute: async (args: { connectionString?: string; analysisType?: 'configuration' | 'performance' | 'security'; }, getConnectionString: GetConnectionStringFn): Promise<ToolOutput> => {
        const { connectionString: connStringArg, analysisType } = args;
    
        if (!analysisType || !['configuration', 'performance', 'security'].includes(analysisType)) {
            return {
                content: [{ type: 'text', text: 'Error: analysisType is required and must be one of [\'configuration\', \'performance\', \'security\'].' }],
                isError: true,
            };
        }
    
        const resolvedConnString = getConnectionString(connStringArg);
        const result = await originalAnalyzeDatabase(resolvedConnString, analysisType);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      },
    };
  • Zod inputSchema definition for the tool parameters: optional connectionString and analysisType.
    const toolDefinition = {
      name: 'pg_analyze_database',
      description: 'Analyze PostgreSQL database configuration and performance',
      inputSchema: z.object({
        connectionString: z.string().optional()
          .describe('PostgreSQL connection string (optional if POSTGRES_CONNECTION_STRING environment variable or --connection-string CLI option is set)'),
        analysisType: z.enum(['configuration', 'performance', 'security']).optional()
          .describe('Type of analysis to perform')
      })
    };
  • src/index.ts:225-257 (registration)
    The allTools array includes analyzeDatabaseTool, making it available to the PostgreSQLServer constructor which registers tools for MCP capabilities.
    const allTools: PostgresTool[] = [
      // Core Analysis & Debugging
      analyzeDatabaseTool,
      debugDatabaseTool,
      
      // Schema & Structure Management (Meta-Tools)
      manageSchemaTools,
      manageFunctionsTool,
      manageTriggersTools,
      manageIndexesTool,
      manageConstraintsTool,
      manageRLSTool,
      
      // User & Security Management
      manageUsersTool,
      
      // Query & Performance Management
      manageQueryTool,
      
      // Data Operations (Enhancement Tools)
      executeQueryTool,
      executeMutationTool,
      executeSqlTool,
      
      // Documentation & Metadata
      manageCommentsTool,
      
      // Data Migration & Monitoring
      exportTableDataTool,
      importTableDataTool,
      copyBetweenDatabasesTool,
      monitorDatabaseTool
    ];
  • src/index.ts:19-19 (registration)
    Import of analyzeDatabaseTool from './tools/analyze.js' (note: source file is analyze.ts).
    import { analyzeDatabaseTool } from './tools/analyze.js';
  • Core helper function that performs the actual database analysis: connects, retrieves version/settings/metrics/recommendations, and disconnects.
    export async function analyzeDatabase(
      connectionString: string,
      analysisType: 'configuration' | 'performance' | 'security' = 'configuration'
    ): Promise<AnalysisResult> {
      const db = DatabaseConnection.getInstance();
      await db.connect(connectionString);
    
      try {
        const version = await getVersion();
        const settings = await getSettings();
        const metrics = await getMetrics();
        const recommendations = await generateRecommendations(analysisType, settings, metrics);
    
        return {
          version,
          settings,
          metrics,
          recommendations,
        };
      } finally {
        await db.disconnect();
      }
    }
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. It mentions analysis but doesn't disclose behavioral traits such as whether it's read-only or has side effects, performance impact, required permissions, or output format. This is inadequate for a tool that interacts with a database.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded and appropriately sized, making it easy to parse without unnecessary details.

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?

Given the complexity of database analysis, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the analysis entails, potential impacts, or return values, leaving significant gaps for an AI agent to understand the tool's behavior.

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 fully documents the two parameters. The description adds no additional meaning beyond implying analysis types, which the schema already covers with the enum. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Analyze') and resource ('PostgreSQL database configuration and performance'), making the purpose understandable. However, it doesn't differentiate from sibling tools like pg_debug_database or pg_monitor_database, which might have overlapping analysis functions, so it misses full sibling distinction.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. With multiple sibling tools like pg_debug_database and pg_monitor_database that could involve analysis, the description lacks any context or exclusions, leaving the agent to guess based on tool names alone.

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/HenkDz/postgresql-mcp-server'

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