Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

get_indexes

Retrieve indexes for a specific table in a PostgreSQL database. Specify the table name and schema to access index details, aiding in database structure analysis and optimization.

Instructions

Get indexes for a specific table

Input Schema

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

Implementation Reference

  • The handler function that connects to the PostgreSQL database, queries pg_indexes for indexes on the specified table and schema, formats the results, and returns them in MCP content format.
    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 for the get_indexes tool, defining table_name as required string and schema as 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, including name, 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'], }, },
  • src/index.js:157-158 (registration)
    Dispatch case in the CallToolRequest handler that invokes the getIndexes method.
    case 'get_indexes': return await this.getIndexes(args.table_name, args?.schema || 'public');

Other Tools

Related 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