get_table_metadata
Retrieve detailed table structure information including columns, data types, and foreign key relationships to understand database schema before querying.
Instructions
🔍 [SAFE] Get detailed metadata for a specific table including all columns, data types, and foreign key relationships. Use this to understand table structure before writing queries. Risk: None - read-only operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableId | Yes | The ID of the table |
Implementation Reference
- The core handler function that implements the get_table_metadata tool logic. It validates the tableId, fetches metadata from the Metabase API endpoint `/api/table/${tableId}/query_metadata`, processes the fields, and returns a formatted text response with table details and field information.async getTableMetadata(tableId) { Validators.validateTableId(tableId); this.logger.debug('Getting table metadata', { tableId }); const table = await this.apiClient.makeRequest(`/api/table/${tableId}/query_metadata`); const fields = table.fields?.map(f => ({ id: f.id, name: f.name, type: f.base_type, description: f.description, })) || []; return { content: [ { type: 'text', text: `Table Metadata: ID: ${table.id} Name: ${table.name} Schema: ${table.schema} Database: ${table.db?.name} Total Fields: ${fields.length} Fields: ${fields.map(f => `- ${f.name} (${f.type})${f.description ? ` - ${f.description}` : ''}` ).join('\n')}`, }, ], }; }
- The input schema and description definition for the get_table_metadata tool, used when listing tools via MCP.{ name: 'get_table_metadata', description: '🔍 [SAFE] Get detailed metadata for a specific table including all columns, data types, and foreign key relationships. Use this to understand table structure before writing queries. Risk: None - read-only operation.', inputSchema: { type: 'object', properties: { tableId: { type: 'integer', description: 'The ID of the table', minimum: 1, }, }, required: ['tableId'], }, },
- src/server/MetabaseMCPServer.js:196-197 (registration)The registration of the get_table_metadata tool in the main server switch statement, which delegates execution to the DatabaseHandlers instance.case 'get_table_metadata': return await this.databaseHandlers.getTableMetadata(args.tableId);