Skip to main content
Glama

list_tables

Retrieve all table names from your connected database to inspect schema structure and identify available data sources.

Instructions

List all tables in the connected database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'list_tables' tool. It checks for an active database connection and executes database-specific queries to retrieve and return a list of tables in JSON format for both PostgreSQL and MySQL.
    async listTables() { if (!this.currentConfig) { throw new Error('Not connected to any database. Call connect_database first.'); } if (this.currentConfig.type === 'postgresql') { if (!this.postgresPool) { throw new Error('PostgreSQL connection not initialized'); } const query = ` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name; `; const result = await this.postgresPool.query(query); return { content: [ { type: 'text', text: JSON.stringify( { tables: result.rows.map((row) => row.table_name), }, null, 2 ), }, ], }; } else if (this.currentConfig.type === 'mysql') { if (!this.mysqlConnection) { throw new Error('MySQL connection not initialized'); } const [rows] = await this.mysqlConnection.query( `SHOW TABLES FROM ${this.currentConfig.database}` ); const tableKey = `Tables_in_${this.currentConfig.database}`; const tables = rows.map((row) => row[tableKey]); return { content: [ { type: 'text', text: JSON.stringify( { tables: tables, }, null, 2 ), }, ], }; } else { throw new Error(`Unsupported database type: ${this.currentConfig.type}`); } }
  • index.js:175-182 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the name, description, and empty input schema for the 'list_tables' tool.
    { name: 'list_tables', description: 'List all tables in the connected database', inputSchema: { type: 'object', properties: {}, }, },
  • Input schema definition for the 'list_tables' tool, which requires no parameters.
    inputSchema: { type: 'object', properties: {}, },
  • Dispatch case in the CallToolRequestSchema handler that invokes the listTables method for the 'list_tables' tool.
    case 'list_tables': return await this.listTables();

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

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