Skip to main content
Glama
antonorlov

MCP PostgreSQL Server

describe_table

Retrieve PostgreSQL table structure including columns, data types, and constraints to understand database schema and plan queries effectively.

Instructions

Get table structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
schemaNoSchema name (default: public)

Implementation Reference

  • Main handler function for 'describe_table' tool. Validates input, queries PostgreSQL information_schema for table columns, data types, nullability, defaults, primary key status, and max length. Returns JSON-formatted results.
    private async handleDescribeTable(args: any) {
      await this.ensureConnection();
    
      if (!args.table) {
        throw new McpError(ErrorCode.InvalidParams, 'Table name is required');
      }
    
      const schema = args.schema || 'public';
    
      try {
        const result = await this.client!.query(`
          SELECT 
            c.column_name, 
            c.data_type, 
            c.is_nullable, 
            c.column_default,
            CASE 
              WHEN pk.constraint_type = 'PRIMARY KEY' THEN true 
              ELSE false 
            END AS is_primary_key,
            c.character_maximum_length
          FROM 
            information_schema.columns c
          LEFT JOIN (
            SELECT 
              tc.constraint_type, 
              kcu.column_name, 
              kcu.table_name,
              kcu.table_schema
            FROM 
              information_schema.table_constraints tc
            JOIN 
              information_schema.key_column_usage kcu
            ON 
              tc.constraint_name = kcu.constraint_name
            WHERE 
              tc.constraint_type = 'PRIMARY KEY'
          ) pk
          ON 
            c.column_name = pk.column_name
            AND c.table_name = pk.table_name
            AND c.table_schema = pk.table_schema
          WHERE 
            c.table_schema = $1 
            AND c.table_name = $2
          ORDER BY 
            c.ordinal_position
        `, [schema, args.table]);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result.rows, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to describe table: ${getErrorMessage(error)}`
        );
      }
    }
  • Input schema definition for the 'describe_table' tool, specifying required 'table' parameter and optional 'schema'.
    {
      name: 'describe_table',
      description: 'Get table structure',
      inputSchema: {
        type: 'object',
        properties: {
          table: {
            type: 'string',
            description: 'Table name',
          },
          schema: {
            type: 'string',
            description: 'Schema name (default: public)',
          },
        },
        required: ['table'],
      },
    },
  • src/index.ts:267-268 (registration)
    Dispatch/registration case in the tool request handler switch statement that routes 'describe_table' calls to the handleDescribeTable function.
    case 'describe_table':
      return await this.handleDescribeTable(request.params.arguments);
  • src/index.ts:137-253 (registration)
    Tool list registration in ListToolsRequestSchema handler, including 'describe_table' with its schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'connect_db',
          description: 'Connect to PostgreSQL database. NOTE: Default connection exists - only use when requested or if other commands fail',
          inputSchema: {
            type: 'object',
            properties: {
              host: {
                type: 'string',
                description: 'Database host',
              },
              port: {
                type: 'number',
                description: 'Database port (default: 5432)',
              },
              user: {
                type: 'string',
                description: 'Database user',
              },
              password: {
                type: 'string',
                description: 'Database password',
              },
              database: {
                type: 'string',
                description: 'Database name',
              },
            },
            required: ['host', 'user', 'password', 'database'],
          },
        },
        {
          name: 'query',
          description: 'Execute a SELECT query',
          inputSchema: {
            type: 'object',
            properties: {
              sql: {
                type: 'string',
                description: 'SQL SELECT query (use $1, $2, etc. for parameters)',
              },
              params: {
                type: 'array',
                items: {
                  type: ['string', 'number', 'boolean', 'null'],
                },
                description: 'Query parameters (optional)',
              },
            },
            required: ['sql'],
          },
        },
        {
          name: 'execute',
          description: 'Execute an INSERT, UPDATE, or DELETE query',
          inputSchema: {
            type: 'object',
            properties: {
              sql: {
                type: 'string',
                description: 'SQL query (INSERT, UPDATE, DELETE) (use $1, $2, etc. for parameters)',
              },
              params: {
                type: 'array',
                items: {
                  type: ['string', 'number', 'boolean', 'null'],
                },
                description: 'Query parameters (optional)',
              },
            },
            required: ['sql'],
          },
        },
        {
          name: 'list_schemas',
          description: 'List all schemas in the database',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'list_tables',
          description: 'List tables in the database',
          inputSchema: {
            type: 'object',
            properties: {
              schema: {
                type: 'string',
                description: 'Schema name (default: public)',
              },
            },
            required: [],
          },
        },
        {
          name: 'describe_table',
          description: 'Get table structure',
          inputSchema: {
            type: 'object',
            properties: {
              table: {
                type: 'string',
                description: 'Table name',
              },
              schema: {
                type: 'string',
                description: 'Schema name (default: public)',
              },
            },
            required: ['table'],
          },
        },
      ],
    }));
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. 'Get table structure' suggests a read-only operation, but it doesn't specify whether it requires authentication, has rate limits, returns detailed metadata (e.g., column types, constraints), or handles errors. This leaves significant gaps for a tool with potential database interactions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just three words, making it front-loaded and efficient. However, it might be overly terse, potentially sacrificing clarity for brevity, as it could benefit from slightly more detail to fully convey the tool's scope.

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 the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'table structure' entails (e.g., column definitions, indexes), how results are formatted, or any behavioral aspects like error handling. For a database tool with potential complexity, this leaves too much unspecified.

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?

The input schema has 100% description coverage, clearly documenting both parameters ('table' and 'schema') with their types and defaults. The description adds no additional meaning beyond what the schema provides, such as examples or constraints, but the schema is sufficient, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get table structure' clearly states the verb ('Get') and resource ('table structure'), making the purpose understandable. However, it doesn't differentiate from potential sibling tools like 'list_tables' or 'query', and 'structure' could be interpreted as metadata, columns, or schema details without further clarification.

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?

No explicit guidance is provided on when to use this tool versus alternatives like 'list_tables' or 'query'. The description implies it's for retrieving structural information, but it doesn't specify prerequisites (e.g., needing a database connection) or exclusions (e.g., not for data retrieval).

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

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