Skip to main content
Glama
srthkdev

DBeaver MCP Server

by srthkdev

list_tables

Retrieve all tables from a specified database connection using DBeaver, with options to filter by schema and include views.

Instructions

List all tables in a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesThe ID or name of the DBeaver connection
includeViewsNoInclude views in the results
schemaNoSpecific schema to list tables from (optional)

Implementation Reference

  • MCP tool handler for list_tables: validates connectionId, fetches connection, delegates to DBeaverClient.listTables, formats response as JSON.
    private async handleListTables(args: { 
      connectionId: string; 
      schema?: string; 
      includeViews?: 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 tables = await this.dbeaverClient.listTables(
        connection, 
        args.schema, 
        args.includeViews || false
      );
      
      return {
        content: [{
          type: 'text' as const,
          text: JSON.stringify(tables, null, 2),
        }],
      };
    }
  • Input schema definition and tool metadata registration for the list_tables tool in ListToolsRequestSchema response.
      name: 'list_tables',
      description: 'List all tables in a database',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: {
            type: 'string',
            description: 'The ID or name of the DBeaver connection',
          },
          schema: {
            type: 'string',
            description: 'Specific schema to list tables from (optional)',
          },
          includeViews: {
            type: 'boolean',
            description: 'Include views in the results',
            default: false
          }
        },
        required: ['connectionId'],
      },
    },
  • Core listTables method in DBeaverClient: builds driver-specific query, executes it, parses results into table objects. Called by MCP handler.
    async listTables(connection: DBeaverConnection, schema?: string, includeViews: boolean = false): Promise<any[]> {
      try {
        const query = buildListTablesQuery(connection.driver, schema, includeViews);
        const result = await this.executeQuery(connection, query);
        
        // Convert result to table objects
        return result.rows.map(row => {
          const tableObj: any = {};
          result.columns.forEach((col, idx) => {
            tableObj[col] = row[idx];
          });
          return tableObj;
        });
      } catch (error) {
        if (this.debug) {
          console.error(`Failed to list tables: ${error}`);
        }
        // Return empty array instead of crashing
        return [];
      }
    }
  • Helper function to generate database-driver-specific SQL queries for listing tables and views, used by DBeaverClient.listTables.
    export function buildListTablesQuery(driver: string, schema?: string, includeViews: boolean = false): string {
      const driverLower = driver.toLowerCase();
      
      if (driverLower.includes('postgresql') || driverLower.includes('postgres')) {
        let query = `
          SELECT 
            table_name,
            table_type,
            table_schema
          FROM information_schema.tables 
          WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
        `;
        
        if (schema) {
          query += ` AND table_schema = '${schema}'`;
        }
        
        if (!includeViews) {
          query += ` AND table_type = 'BASE TABLE'`;
        }
        
        query += ` ORDER BY table_schema, table_name;`;
        return query;
        
      } else if (driverLower.includes('mysql')) {
        let query = `
          SELECT 
            TABLE_NAME as table_name,
            TABLE_TYPE as table_type,
            TABLE_SCHEMA as table_schema
          FROM information_schema.TABLES 
          WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
        `;
        
        if (schema) {
          query += ` AND TABLE_SCHEMA = '${schema}'`;
        }
        
        if (!includeViews) {
          query += ` AND TABLE_TYPE = 'BASE TABLE'`;
        }
        
        query += ` ORDER BY TABLE_SCHEMA, TABLE_NAME;`;
        return query;
        
      } else if (driverLower.includes('sqlite')) {
        let query = `
          SELECT 
            name as table_name,
            type as table_type
          FROM sqlite_master 
          WHERE type IN ('table'${includeViews ? ", 'view'" : ''})
            AND name NOT LIKE 'sqlite_%'
          ORDER BY name;
        `;
        return query;
        
      } else if (driverLower.includes('oracle')) {
        let query = `
          SELECT 
            table_name,
            'TABLE' as table_type,
            owner as table_schema
          FROM all_tables
        `;
        
        if (schema) {
          query += ` WHERE owner = UPPER('${schema}')`;
        }
        
        if (includeViews) {
          query += `
            UNION ALL
            SELECT 
              view_name as table_name,
              'VIEW' as table_type,
              owner as table_schema
            FROM all_views
          `;
          
          if (schema) {
            query += ` WHERE owner = UPPER('${schema}')`;
          }
        }
        
        query += ` ORDER BY table_name;`;
        return query;
        
      } else {
        // Generic fallback
        let query = `
          SELECT 
            table_name,
            table_type,
            table_schema
          FROM information_schema.tables
        `;
        
        if (schema) {
          query += ` WHERE table_schema = '${schema}'`;
        }
        
        if (!includeViews) {
          query += `${schema ? ' AND' : ' WHERE'} table_type = 'BASE TABLE'`;
        }
        
        query += ` ORDER BY table_schema, table_name;`;
        return query;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states it's a list operation, implying read-only behavior, but doesn't mention potential side effects, authentication needs, rate limits, or what the output format looks like (e.g., pagination, error handling). This is a significant gap for a tool with no annotation coverage.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource, making it easy to parse quickly.

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 complexity (a database query tool with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't address what the output contains (e.g., table names, metadata), error conditions, or dependencies on other tools like 'list_connections', leaving the agent with insufficient context for reliable use.

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%, so the schema already documents all three parameters thoroughly. The description doesn't add any meaning beyond what's in the schema (e.g., it doesn't explain why 'connectionId' is required or how 'schema' interacts with database structure), meeting the baseline for high schema coverage.

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 action ('List') and resource ('all tables in a database'), making the purpose immediately understandable. It doesn't distinguish from siblings like 'get_table_schema' or 'list_connections', but it's specific enough to avoid confusion with unrelated tools like 'execute_query' or 'create_table'.

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. For example, it doesn't mention how this differs from 'get_table_schema' (which might provide detailed metadata) or 'list_connections' (which lists connections rather than tables), leaving the agent to infer usage from context 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