Skip to main content
Glama
srthkdev

DBeaver MCP Server

by srthkdev

get_table_schema

Retrieve schema details for a database table, including columns, data types, and optional index information, to understand its structure and relationships.

Instructions

Get schema information for a specific table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesThe ID or name of the DBeaver connection
includeIndexesNoInclude index information
tableNameYesThe name of the table to describe

Implementation Reference

  • Primary execution handler for the get_table_schema tool. Resolves connection, fetches schema via DBeaverClient, optionally removes indexes, returns JSON response.
    private async handleGetTableSchema(args: { 
      connectionId: string; 
      tableName: string; 
      includeIndexes?: boolean 
    }) {
      const connectionId = sanitizeConnectionId(args.connectionId);
      const connection = await this.configParser.getConnection(connectionId);
      
      if (!connection) {
        throw new McpError(ErrorCode.InvalidParams, `Connection not found: ${connectionId}`);
      }
      
      const schema = await this.dbeaverClient.getTableSchema(connection, args.tableName);
      
      if (!args.includeIndexes) {
        (schema as any).indexes = undefined;
      }
      
      return {
        content: [{
          type: 'text' as const,
          text: JSON.stringify(schema, null, 2),
        }],
      };
    }
  • Input schema for validating tool arguments: requires connectionId and tableName, optional includeIndexes.
    inputSchema: {
      type: 'object',
      properties: {
        connectionId: {
          type: 'string',
          description: 'The ID or name of the DBeaver connection',
        },
        tableName: {
          type: 'string',
          description: 'The name of the table to describe',
        },
        includeIndexes: {
          type: 'boolean',
          description: 'Include index information',
          default: true
        }
      },
      required: ['connectionId', 'tableName'],
    },
  • src/index.ts:320-342 (registration)
    Registration of the get_table_schema tool in the tools list, defining name, description, and input schema.
    {
      name: 'get_table_schema',
      description: 'Get schema information for a specific table',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: {
            type: 'string',
            description: 'The ID or name of the DBeaver connection',
          },
          tableName: {
            type: 'string',
            description: 'The name of the table to describe',
          },
          includeIndexes: {
            type: 'boolean',
            description: 'Include index information',
            default: true
          }
        },
        required: ['connectionId', 'tableName'],
      },
    },
  • Helper method in DBeaverClient that builds driver-specific schema query, executes it, and parses into SchemaInfo.
    async getTableSchema(connection: DBeaverConnection, tableName: string): Promise<SchemaInfo> {
      const schemaQuery = this.buildSchemaQuery(connection.driver, tableName);
      const result = await this.executeQuery(connection, schemaQuery);
      
      return this.parseSchemaResult(result, tableName);
    }
  • Parses raw query results from schema query into structured column information for SchemaInfo.
    private parseSchemaResult(result: any, tableName: string): SchemaInfo {
      const columns: any[] = [];
      
      if (result.rows && result.columns) {
        // Parse each row as a column definition
        result.rows.forEach((row: any[]) => {
          const columnInfo: any = {
            name: '',
            type: 'string',
            nullable: true,
            isPrimaryKey: false,
            isAutoIncrement: false
          };
          
          // Map columns based on the query result structure
          result.columns.forEach((colName: string, idx: number) => {
            const value = row[idx];
            
            switch (colName.toLowerCase()) {
              case 'column_name':
              case 'name':
                columnInfo.name = value || '';
                break;
              case 'data_type':
              case 'type':
                columnInfo.type = value || 'string';
                break;
              case 'is_nullable':
              case 'nullable':
                columnInfo.nullable = value === 'YES' || value === 'Y' || value === true;
                break;
              case 'column_default':
              case 'default':
                columnInfo.defaultValue = value;
                break;
              case 'column_key':
              case 'key':
                columnInfo.isPrimaryKey = value === 'PRI' || value === 'PRIMARY';
                break;
              case 'extra':
                columnInfo.isAutoIncrement = value && value.toLowerCase().includes('auto_increment');
                break;
              case 'character_maximum_length':
              case 'length':
                columnInfo.length = parseInt(value) || undefined;
                break;
              case 'numeric_precision':
              case 'precision':
                columnInfo.precision = parseInt(value) || undefined;
                break;
              case 'numeric_scale':
              case 'scale':
                columnInfo.scale = parseInt(value) || undefined;
                break;
            }
          });
          
          if (columnInfo.name) {
            columns.push(columnInfo);
          }
        });
      }
      
      return {
        tableName,
        columns,
        indexes: [],
        constraints: []
      };
    }
  • Utility function generating driver-specific SQL queries to fetch table schema information.
    export function buildSchemaQuery(driver: string, tableName: string): string {
      const driverLower = driver.toLowerCase();
      
      if (driverLower.includes('postgresql') || driverLower.includes('postgres')) {
        return `
          SELECT 
            column_name,
            data_type,
            is_nullable,
            column_default,
            character_maximum_length,
            numeric_precision,
            numeric_scale
          FROM information_schema.columns 
          WHERE table_name = '${tableName}'
          ORDER BY ordinal_position;
        `;
      } else if (driverLower.includes('mysql')) {
        return `
          SELECT 
            COLUMN_NAME as column_name,
            DATA_TYPE as data_type,
            IS_NULLABLE as is_nullable,
            COLUMN_DEFAULT as column_default,
            CHARACTER_MAXIMUM_LENGTH as character_maximum_length,
            NUMERIC_PRECISION as numeric_precision,
            NUMERIC_SCALE as numeric_scale,
            COLUMN_KEY as column_key,
            EXTRA as extra
          FROM information_schema.COLUMNS 
          WHERE TABLE_NAME = '${tableName}'
          ORDER BY ORDINAL_POSITION;
        `;
      } else if (driverLower.includes('sqlite')) {
        return `PRAGMA table_info(${tableName});`;
      } else if (driverLower.includes('oracle')) {
        return `
          SELECT 
            column_name,
            data_type,
            nullable,
            data_default,
            data_length,
            data_precision,
            data_scale
          FROM user_tab_columns 
          WHERE table_name = UPPER('${tableName}')
          ORDER BY column_id;
        `;
      } else if (driverLower.includes('mssql') || driverLower.includes('sqlserver')) {
        return `
          SELECT 
            COLUMN_NAME as column_name,
            DATA_TYPE as data_type,
            IS_NULLABLE as is_nullable,
            COLUMN_DEFAULT as column_default,
            CHARACTER_MAXIMUM_LENGTH as character_maximum_length,
            NUMERIC_PRECISION as numeric_precision,
            NUMERIC_SCALE as numeric_scale
          FROM INFORMATION_SCHEMA.COLUMNS 
          WHERE TABLE_NAME = '${tableName}'
          ORDER BY ORDINAL_POSITION;
        `;
      } else {
        // Generic fallback
        return `
          SELECT 
            column_name,
            data_type,
            is_nullable,
            column_default
          FROM information_schema.columns 
          WHERE table_name = '${tableName}';
        `;
      }
    }
  • TypeScript interface defining the structure of table schema output.
    export interface SchemaInfo {
      tableName: string;
      columns: ColumnInfo[];
      indexes: IndexInfo[];
      constraints: ConstraintInfo[];
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description states it 'gets' schema information, implying a read-only operation, but doesn't specify whether this requires specific permissions, what format the output returns (e.g., JSON, structured data), or any rate limits or side effects. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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 a single, clear sentence with zero wasted words. It's front-loaded with the core purpose ('Get schema information') and specifies the target ('for a specific table'). Every word earns its place, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally adequate. It states what the tool does but lacks details on output format, error handling, or integration with sibling tools. Without annotations or an output schema, the description should ideally provide more context about the returned schema information, but it meets the bare minimum for understanding the tool's purpose.

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 schema description coverage is 100%, with all parameters well-documented in the input schema (connectionId, includeIndexes, tableName). The description doesn't add any additional semantic context beyond what the schema provides, such as explaining relationships between parameters or usage nuances. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

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 tool's purpose as 'Get schema information for a specific table', which includes a specific verb ('Get') and resource ('schema information for a specific table'). It distinguishes from siblings like 'list_tables' (which lists tables) and 'create_table' (which creates tables), but doesn't explicitly differentiate from tools like 'get_connection_info' or 'get_database_stats' that also retrieve metadata.

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 when this tool is appropriate compared to 'list_tables' (for table enumeration) or 'execute_query' (for custom schema queries), nor does it specify prerequisites or exclusions. The agent must infer usage from the tool name and parameters alone.

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/srthkdev/omnisql-mcp'

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