Skip to main content
Glama
itsalfredakku

Postgres MCP Server

monitoring

Retrieve PostgreSQL database performance metrics, statistics, and health checks including connections, locks, replication status, and query performance.

Instructions

Database monitoring: performance metrics, statistics, health checks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
metricYesMetric type to retrieve
timeRangeNoTime range for metrics1h
limitNoMaximum number of results

Implementation Reference

  • The main execution handler for the 'monitoring' tool. Handles different metrics (connections, performance, cache, security) by delegating to various managers and returning JSON-formatted monitoring data.
    private async handleMonitoring(args: any) {
      const { metric } = args;
      
      switch (metric) {
        case 'connections':
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(this.dbManager.getPoolStats(), null, 2)
            }]
          };
    
        case 'performance':
          const operationalStats = this.dbManager.getOperationalStats();
          const performanceMetrics = this.performanceMonitor.getMetrics();
          const slowOperations = this.performanceMonitor.getSlowOperations();
          
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                operational: operationalStats,
                performance: performanceMetrics,
                slowOperations,
                cache: this.cache.getStats()
              }, null, 2)
            }]
          };
    
        case 'cache':
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                stats: this.cache.getStats(),
                recent: this.cache.getRecentEntries(5),
                popular: this.cache.getPopularEntries(5)
              }, null, 2)
            }]
          };
    
        case 'security':
          const rateLimitEntries = Array.from(this.rateLimiter.getAllEntries().entries()).slice(0, 10);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                rateLimits: rateLimitEntries,
                securityEvents: 'Security event logging would be implemented here'
              }, null, 2)
            }]
          };
    
        default:
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ message: `Monitoring metric '${metric}' not yet implemented` }, null, 2)
            }]
          };
      }
    }
  • Input schema for the 'monitoring' tool, defining parameters such as metric (required), timeRange, and limit.
    {
      name: 'monitoring',
      description: 'Database monitoring: performance metrics, statistics, health checks',
      inputSchema: {
        type: 'object',
        properties: {
          metric: {
            type: 'string',
            enum: ['connections', 'performance', 'locks', 'replication', 'disk_usage', 'query_stats', 'index_usage'],
            description: 'Metric type to retrieve'
          },
          timeRange: {
            type: 'string',
            enum: ['1h', '24h', '7d', '30d'],
            description: 'Time range for metrics',
            default: '1h'
          },
          limit: {
            type: 'integer',
            description: 'Maximum number of results',
            default: 50
          }
        },
        required: ['metric']
      }
    },
  • src/index.ts:633-637 (registration)
    Registration of all tool definitions (including 'monitoring') via ListToolsRequestSchema handler, exposing schemas to clients.
    // Register tool definitions
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: toolDefinitions,
    }));
  • src/index.ts:664-666 (registration)
    Dispatch/registration in the CallToolRequestSchema switch statement, routing 'monitoring' tool calls to the handleMonitoring function.
    case 'monitoring':
      return await this.handleMonitoring(args);
  • Tool name mappings in validation module, associating 'monitor' and 'stats' aliases with the 'monitoring' category for error suggestions.
    'monitor': 'monitoring',
    'stats': 'monitoring',

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/itsalfredakku/postgres-mcp'

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