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
| Name | Required | Description | Default |
|---|---|---|---|
| databaseId | Yes | The 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'], }, },
- src/server/MetabaseMCPServer.js:194-195 (registration)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);
- src/server/MetabaseMCPServer.js:129-134 (registration)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);