Skip to main content
Glama
MikelA92
by MikelA92

list_database_tables

Retrieve all available tables in a specific database to identify queryable data sources before executing database queries.

Instructions

📑 [SAFE] List all tables in a specific database. Use this to see what tables are available before querying. Risk: None - read-only operation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseIdYesThe ID of the database

Implementation Reference

  • The core handler function that executes the tool: validates databaseId, fetches database metadata via Metabase API, extracts tables, and returns a formatted text list.
    async listDatabaseTables(databaseId) { Validators.validateDatabaseId(databaseId); this.logger.debug('Listing database tables', { databaseId }); // Use metadata endpoint as /tables endpoint doesn't exist const metadata = await this.apiClient.makeRequest(`/api/database/${databaseId}/metadata`); const tables = metadata.tables || []; return { content: [ { type: 'text', text: `Tables in Database ${databaseId}: ${tables.map(t => `- ID: ${t.id} | Schema: ${t.schema} | Name: ${t.name}` ).join('\n')}`, }, ], }; }
  • Tool schema definition: specifies name, description, and input validation schema requiring a positive integer databaseId.
    { name: 'list_database_tables', description: '📑 [SAFE] List all tables in a specific database. Use this to see what tables are available before querying. Risk: None - read-only operation.', inputSchema: { type: 'object', properties: { databaseId: { type: 'integer', description: 'The ID of the database', minimum: 1, }, }, required: ['databaseId'], }, },
  • Registration in the tool execution switch statement: dispatches calls to list_database_tables to the DatabaseHandlers instance method.
    case 'list_database_tables': return await this.databaseHandlers.listDatabaseTables(args.databaseId);
  • Registration for listTools request: returns the TOOL_DEFINITIONS array containing the list_database_tables tool definition.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { this.logger.debug('Listing tools'); return { tools: TOOL_DEFINITIONS, }; });
  • Import and instantiation of DatabaseHandlers class, which contains the listDatabaseTables method, making it available for tool dispatch.
    import { DatabaseHandlers } from './handlers/databaseHandlers.js'; import { CollectionHandlers } from './handlers/collectionHandlers.js'; import { QueryHandlers } from './handlers/queryHandlers.js'; import { FieldHandlers } from './handlers/fieldHandlers.js'; import { SegmentMetricHandlers } from './handlers/segmentMetricHandlers.js'; import { UserHandlers } from './handlers/userHandlers.js'; import { TOOL_DEFINITIONS } from './config/toolDefinitions.js'; import { ConfigurationError, ToolExecutionError } from '../shared/errors/MetabaseError.js'; import { logger } from '../shared/utils/logger.js'; /** * MCP Server for Metabase API integration */ export class MetabaseMCPServer { constructor(config) { this.config = config; this.logger = logger.child('MetabaseMCPServer'); // Initialize API client this.apiClient = new ApiClient( config.metabaseUrl, config.apiKey, config.requestTimeout ); // Initialize handlers this.cardHandlers = new CardHandlers(this.apiClient); this.dashboardHandlers = new DashboardHandlers(this.apiClient); this.databaseHandlers = new DatabaseHandlers(this.apiClient);

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/MikelA92/metabase-mcp-mab'

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