Skip to main content
Glama
adetxt

SQL MCP Server

by adetxt

Get Tables

get_tables

Retrieve a list of all tables in your SQL database to understand its structure and available data. Connect using your database type and connection string to view tables.

Instructions

Get list of table in database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
db_typeYes
connection_stringYes

Implementation Reference

  • The main handler function for the 'get_tables' tool. It creates a Sequelize connection based on db_type and connection_string, queries the database for tables depending on the dialect (postgres, mysql, sqlite), processes the results into a list of tables, and returns them as JSON text content.
    async ({db_type, connection_string}) => {
      const sequelize = new Sequelize(connection_string, {
        dialect: db_type,
      })
    
      let result: any[] = []
      let tables: string[] = []
      
      switch (db_type) {
        case 'postgres':
          [result] = await sequelize.query('SELECT * FROM information_schema.tables')
          tables = result
            .filter((table: any) => table.table_schema !== 'information_schema' && table.table_schema !== 'pg_catalog')
            .map((table: any) => `${table.table_schema}.${table.table_name}`)
          break
        case 'mysql':
          [result] = await sequelize.query('SELECT * FROM information_schema.tables')
          tables = result.map((table: any) => table.table_name)
          break
        case 'sqlite':
          [result] = await sequelize.query('SELECT * FROM sqlite_master WHERE type = "table"')
          tables = result.map((table: any) => table.name)
          break
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(tables),
          }
        ],
      }
    },
  • Input schema definition for the 'get_tables' tool using Zod schemas for db_type (enum: postgres, mysql, sqlite) and connection_string (string).
    inputSchema: {
      db_type: z.enum(['postgres', 'mysql', 'sqlite']),
      connection_string: z.string(),
    },
  • src/tools.ts:6-50 (registration)
    Registers the 'get_tables' tool with the MCP server, specifying the tool name, metadata, input schema, and handler function.
    server.registerTool(
      'get_tables',
      {
        title: 'Get Tables',
        description: 'Get list of table in database',
        inputSchema: {
          db_type: z.enum(['postgres', 'mysql', 'sqlite']),
          connection_string: z.string(),
        },
      },
      async ({db_type, connection_string}) => {
        const sequelize = new Sequelize(connection_string, {
          dialect: db_type,
        })
    
        let result: any[] = []
        let tables: string[] = []
        
        switch (db_type) {
          case 'postgres':
            [result] = await sequelize.query('SELECT * FROM information_schema.tables')
            tables = result
              .filter((table: any) => table.table_schema !== 'information_schema' && table.table_schema !== 'pg_catalog')
              .map((table: any) => `${table.table_schema}.${table.table_name}`)
            break
          case 'mysql':
            [result] = await sequelize.query('SELECT * FROM information_schema.tables')
            tables = result.map((table: any) => table.table_name)
            break
          case 'sqlite':
            [result] = await sequelize.query('SELECT * FROM sqlite_master WHERE type = "table"')
            tables = result.map((table: any) => table.name)
            break
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(tables),
            }
          ],
        }
      },
    )
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. It states a read operation ('Get list'), which implies it's non-destructive, but doesn't cover permissions, rate limits, output format, or error handling. This is a significant gap for a tool that interacts with databases, making it inadequate for safe and effective use.

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 a single, efficient sentence that gets straight to the point without unnecessary words. However, the grammatical error ('table' vs. 'tables') slightly detracts from clarity, but it remains appropriately sized and front-loaded.

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 of database interactions, no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It lacks details on behavior, parameters, output, and usage context, making it insufficient for an AI agent to reliably invoke this tool without additional assumptions or errors.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter descriptions. The tool description adds no information about the parameters (db_type, connection_string), their meanings, or how they affect the operation. This leaves both parameters entirely undocumented, failing to compensate for the schema's lack of coverage.

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 list of table in database' clearly states the action (get/list) and resource (tables), but it's grammatically incorrect ('table' should be 'tables') and doesn't distinguish from sibling tools like 'get_columns' or 'execute_query'. It provides a basic purpose but lacks specificity about scope or differentiation.

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 guidance is provided on when to use this tool versus alternatives like 'get_columns' or 'execute_query'. The description implies it's for listing tables, but there's no explicit context, exclusions, or prerequisites mentioned, leaving the agent to infer usage based on tool names 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/adetxt/sql-mcp'

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