Skip to main content
Glama
itsalfredakku

Postgres MCP Server

security

Manage PostgreSQL database security by configuring SSL, authentication methods, encryption settings, audit logs, and access controls to protect sensitive data.

Instructions

Database security management: SSL, authentication, encryption, auditing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesSecurity operation to perform
tableNoTable name for RLS operations
policy_nameNoRLS policy name
policy_expressionNoRLS policy expression
audit_typeNoType of audit information

Implementation Reference

  • Handler function implementing the 'security' tool logic. Dispatches to specific security checks using SQL queries for SSL status, authentication methods, session security, row-level security, and audit logs.
    private async handleSecurity(args: any) {
      const { operation, table, policy_name, policy_expression, audit_type } = args;
    
      switch (operation) {
        case 'check_ssl':
          const sslInfo = await this.queryClient.executeQuery(`
            SELECT 
              name,
              setting,
              context,
              short_desc
            FROM pg_settings 
            WHERE name LIKE '%ssl%' OR name LIKE '%tls%'
            ORDER BY name
          `);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(sslInfo.rows, null, 2)
            }]
          };
    
        case 'list_auth_methods':
          const authMethods = await this.queryClient.executeQuery(`
            SELECT 
              type,
              database,
              user_name,
              address,
              netmask,
              auth_method,
              options,
              error
            FROM pg_hba_file_rules
            ORDER BY line_number
          `);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(authMethods.rows, null, 2)
            }]
          };
    
        case 'session_security':
          const sessionInfo = await this.queryClient.executeQuery(`
            SELECT 
              inet_client_addr() as client_ip,
              inet_server_addr() as server_ip,
              current_user,
              session_user,
              current_database(),
              pg_backend_pid() as backend_pid,
              pg_is_in_recovery() as in_recovery,
              current_setting('ssl') as ssl_enabled
          `);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(sessionInfo.rows[0], null, 2)
            }]
          };
    
        case 'row_level_security':
          if (!table) {
            // List all RLS policies
            const rlsPolicies = await this.queryClient.executeQuery(`
              SELECT 
                schemaname,
                tablename,
                policyname,
                permissive,
                roles,
                cmd,
                qual,
                with_check
              FROM pg_policies
              ORDER BY schemaname, tablename, policyname
            `);
            return {
              content: [{
                type: 'text',
                text: JSON.stringify(rlsPolicies.rows, null, 2)
              }]
            };
          } else {
            // Show RLS status for specific table
            const rlsStatus = await this.queryClient.executeQuery(`
              SELECT 
                schemaname,
                tablename,
                rowsecurity,
                forcerowsecurity
              FROM pg_tables 
              WHERE tablename = $1
            `, [table]);
            return {
              content: [{
                type: 'text',
                text: JSON.stringify(rlsStatus.rows, null, 2)
              }]
            };
          }
    
        case 'audit_log':
          const auditQuery = `
            SELECT 
              datname as database,
              usename as username,
              application_name,
              client_addr,
              backend_start,
              query_start,
              state,
              query
            FROM pg_stat_activity 
            WHERE state = 'active' 
            ORDER BY query_start DESC
            LIMIT 50
          `;
          const auditInfo = await this.queryClient.executeQuery(auditQuery);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(auditInfo.rows, null, 2)
            }]
          };
    
        default:
          throw new Error(`Unknown security operation: ${operation}`);
      }
    }
  • Input schema and definition for the 'security' MCP tool, specifying supported operations like check_ssl, list_auth_methods, etc.
    {
      name: 'security',
      description: 'Database security management: SSL, authentication, encryption, auditing',
      inputSchema: {
        type: 'object',
        properties: {
          operation: {
            type: 'string',
            enum: [
              'check_ssl', 'list_auth_methods', 'check_encryption', 'audit_log',
              'password_policy', 'connection_limits', 'session_security',
              'row_level_security', 'column_encryption', 'security_labels'
            ],
            description: 'Security operation to perform'
          },
          table: {
            type: 'string',
            description: 'Table name for RLS operations'
          },
          policy_name: {
            type: 'string',
            description: 'RLS policy name'
          },
          policy_expression: {
            type: 'string',
            description: 'RLS policy expression'
          },
          audit_type: {
            type: 'string',
            enum: ['connections', 'queries', 'ddl', 'dml', 'errors'],
            description: 'Type of audit information'
          }
        },
        required: ['operation']
      }
    }
  • src/index.ts:670-674 (registration)
    Registration of the 'security' tool in the CallToolRequestSchema handler switch statement, dispatching calls to handleSecurity.
    case 'permissions':
      return await this.handlePermissions(args);
    
    case 'security':
      return await this.handleSecurity(args);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'management' implies both read and write operations, the description doesn't clarify which operations are read-only versus mutative, what permissions are required, whether operations are destructive, or what the response format looks like. For a security tool with potentially sensitive operations, this is a significant gap.

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 extremely concise - a single phrase listing the tool's scope. Every word earns its place, with no redundant information. The structure is front-loaded with the core purpose followed by specific domains. This is an excellent example of efficient communication.

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 security management tool with 5 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain the tool's behavior, response format, or operational constraints. While the schema covers parameter mechanics, the description fails to provide the contextual understanding needed for an agent to use this tool effectively in security scenarios.

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 5 parameters thoroughly. The description mentions security domains that map to the 'operation' enum values (SSL, authentication, encryption, auditing), but doesn't add meaningful semantic context beyond what the schema provides. The baseline 3 is appropriate when 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 tool's purpose as 'Database security management' with specific domains listed (SSL, authentication, encryption, auditing). It distinguishes itself from siblings like 'permissions' or 'admin' by focusing on security aspects, though it doesn't explicitly contrast with them. The verb 'management' is somewhat broad but the listed domains provide good specificity.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'permissions', 'admin', and 'monitoring' that might overlap with security concerns, there's no indication of when this specific security tool is appropriate versus those other tools. The description simply lists domains without contextual usage information.

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

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