Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

get_indexes

Retrieve index information for a PostgreSQL table to analyze database performance and structure.

Instructions

Get indexes for a specific table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table
schemaNoSchema name (default: public)public

Implementation Reference

  • The main handler function for the 'get_indexes' tool. It connects to the PostgreSQL database, executes a query to retrieve indexes for the specified table and schema from pg_indexes, formats the results into a text response including index names, types, and definitions, and handles the case where no indexes are found.
    async getIndexes(tableName, schema = 'public') {
      const client = await this.connectToDatabase();
      
      try {
        const query = `
          SELECT 
            i.indexname,
            i.indexdef,
            am.amname AS index_type
          FROM pg_indexes i
          JOIN pg_class c ON c.relname = i.indexname
          JOIN pg_am am ON am.oid = c.relam
          WHERE i.schemaname = $1 AND i.tablename = $2
          ORDER BY i.indexname;
        `;
        
        const result = await client.query(query, [schema, tableName]);
        
        return {
          content: [
            {
              type: 'text',
              text: result.rows.length > 0 ? 
                `Indexes for table "${schema}.${tableName}":\n\n` + 
                result.rows.map(row => 
                  `${row.indexname} (${row.index_type}):\n  ${row.indexdef}`
                ).join('\n\n') :
                `No indexes found for table "${schema}.${tableName}"`
            },
          ],
        };
      } finally {
        await client.end();
      }
    }
  • Input schema validation for the 'get_indexes' tool, defining properties for table_name (required string) and schema (optional string with default 'public').
    inputSchema: {
      type: 'object',
      properties: {
        table_name: {
          type: 'string',
          description: 'Name of the table',
        },
        schema: {
          type: 'string',
          description: 'Schema name (default: public)',
          default: 'public'
        }
      },
      required: ['table_name'],
    },
  • src/index.js:117-135 (registration)
    Tool registration in the ListTools response, defining the name 'get_indexes', description, and input schema.
    {
      name: 'get_indexes',
      description: 'Get indexes for a specific table',
      inputSchema: {
        type: 'object',
        properties: {
          table_name: {
            type: 'string',
            description: 'Name of the table',
          },
          schema: {
            type: 'string',
            description: 'Schema name (default: public)',
            default: 'public'
          }
        },
        required: ['table_name'],
      },
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behavioral aspects: whether this is a read-only operation, what format the indexes are returned in, whether it shows all index types or just specific ones, or if there are permission requirements. The description is minimal and lacks operational context.

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 sentence with zero wasted words. It's front-loaded with the core purpose and efficiently communicates the basic function. Every word earns its place in this minimal description.

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 no annotations and no output schema, the description is incomplete for a database tool. It doesn't explain what information is returned about indexes (columns, types, uniqueness, etc.), doesn't mention error conditions or permissions needed, and provides no context about how this fits with sibling tools. For a tool that presumably returns structured data about database objects, this is inadequate.

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 fully documents both parameters (table_name and schema with default). The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain what constitutes a valid table name, what schemas are available, or how the parameters interact. Baseline 3 is appropriate when schema does all the work.

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 ('Get indexes') and target resource ('for a specific table'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'describe_table' or 'get_table_relationships' that might also provide structural information about tables.

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. It doesn't mention sibling tools like 'describe_table' (which might include index information) or clarify whether this is for database administration versus general querying. No exclusions or prerequisites are stated.

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/sbfulfil/pg-mcp'

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