get_card
Retrieve Metabase card details and SQL queries by ID to analyze question construction and understand underlying data logic.
Instructions
🔍 [SAFE] Get a Metabase card/question by ID, including its SQL query. Use this when you need to see the SQL behind a specific question or analyze how a card is built. Risk: None - read-only operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cardId | Yes | The ID of the card/question to retrieve |
Implementation Reference
- The core handler function for the 'get_card' tool. Fetches card details from Metabase API, extracts SQL query or query builder structure, and returns formatted card information including metadata and query details.async getCard(cardId) { Validators.validateCardId(cardId); this.logger.debug('Getting card', { cardId }); const card = await this.apiClient.makeRequest(`/api/card/${cardId}`); const sqlQuery = card.dataset_query?.native?.query || 'No native SQL query found'; const queryBuilder = card.dataset_query?.query ? JSON.stringify(card.dataset_query.query, null, 2) : null; const cardInfo = { id: card.id, name: card.name, description: card.description, sqlQuery: sqlQuery, databaseId: card.dataset_query?.database, queryType: card.dataset_query?.type, createdAt: card.created_at, updatedAt: card.updated_at, }; let queryDetails = ''; if (card.dataset_query?.type === 'native') { queryDetails = `SQL Query:\n${sqlQuery}`; } else if (card.dataset_query?.type === 'query' && queryBuilder) { queryDetails = `Query Builder Structure:\n${queryBuilder}`; } else { queryDetails = 'No query information available'; } return { content: [ { type: 'text', text: `Card Information: ID: ${cardInfo.id} Name: ${cardInfo.name} Description: ${cardInfo.description || 'No description'} Database ID: ${cardInfo.databaseId} Query Type: ${cardInfo.queryType} Created: ${cardInfo.createdAt} Updated: ${cardInfo.updatedAt} ${queryDetails}`, }, ], }; }
- The tool definition including name, description, and input schema (JSON Schema) for validating 'get_card' tool calls.{ name: 'get_card', description: '🔍 [SAFE] Get a Metabase card/question by ID, including its SQL query. Use this when you need to see the SQL behind a specific question or analyze how a card is built. Risk: None - read-only operation.', inputSchema: { type: 'object', properties: { cardId: { type: 'integer', description: 'The ID of the card/question to retrieve', minimum: 1, }, }, required: ['cardId'], }, },
- src/server/MetabaseMCPServer.js:168-169 (registration)The registration/dispatch in the MCP server's executeTool switch statement that routes 'get_card' calls to the CardHandlers.getCard method.case 'get_card': return await this.cardHandlers.getCard(args.cardId);