Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

describe_table

Retrieve detailed schema information for PostgreSQL tables to understand column definitions, data types, and table structure for database exploration and analysis.

Instructions

Get detailed schema information for a specific table

Input Schema

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

Implementation Reference

  • The core handler function that implements the describe_table tool. It queries the PostgreSQL information_schema.columns for column details of the specified table and schema, formats them into a readable text table, and returns as MCP content.
    async describeTable(tableName, schema = 'public') {
      const client = await this.connectToDatabase();
      
      try {
        const query = `
          SELECT 
            column_name,
            data_type,
            is_nullable,
            column_default,
            character_maximum_length,
            numeric_precision,
            numeric_scale,
            ordinal_position
          FROM information_schema.columns 
          WHERE table_schema = $1 AND table_name = $2
          ORDER BY ordinal_position;
        `;
        
        const result = await client.query(query, [schema, tableName]);
        
        if (result.rows.length === 0) {
          throw new Error(`Table "${tableName}" not found in schema "${schema}"`);
        }
    
        const tableInfo = result.rows.map(row => ({
          column: row.column_name,
          type: row.data_type,
          nullable: row.is_nullable === 'YES',
          default: row.column_default,
          maxLength: row.character_maximum_length,
          precision: row.numeric_precision,
          scale: row.numeric_scale,
          position: row.ordinal_position
        }));
    
        return {
          content: [
            {
              type: 'text',
              text: `Schema for table "${schema}.${tableName}":\n\n` + 
                    tableInfo.map(col => 
                      `${col.column} | ${col.type}${col.maxLength ? `(${col.maxLength})` : ''}${col.precision ? `(${col.precision}${col.scale ? `,${col.scale}` : ''})` : ''} | ${col.nullable ? 'NULL' : 'NOT NULL'}${col.default ? ` | DEFAULT ${col.default}` : ''}`
                    ).join('\n'),
            },
          ],
        };
      } finally {
        await client.end();
      }
    }
  • Input schema for the describe_table tool, defining parameters table_name (required, string) and schema (optional string, defaults to 'public').
    inputSchema: {
      type: 'object',
      properties: {
        table_name: {
          type: 'string',
          description: 'Name of the table to describe',
        },
        schema: {
          type: 'string',
          description: 'Schema name (default: public)',
          default: 'public'
        }
      },
      required: ['table_name'],
    },
  • src/index.js:71-89 (registration)
    Registration of the describe_table tool in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: 'describe_table',
      description: 'Get detailed schema information for a specific table',
      inputSchema: {
        type: 'object',
        properties: {
          table_name: {
            type: 'string',
            description: 'Name of the table to describe',
          },
          schema: {
            type: 'string',
            description: 'Schema name (default: public)',
            default: 'public'
          }
        },
        required: ['table_name'],
      },
    },
  • src/index.js:148-149 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement, mapping tool calls to the describeTable handler.
    case 'describe_table':
      return await this.describeTable(args.table_name, args?.schema || 'public');

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