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
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: public) | public |
| table_name | Yes | Name of the table |
Implementation Reference
- src/index.js:337-371 (handler)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(); } }
- src/index.js:120-134 (schema)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');