get_schema
Retrieve the schema of a data source by providing its ID. Understand the structure of tables and columns in Redash.
Instructions
Get schema of a specific data source
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dataSourceId | Yes | ID of the data source to get schema |
Implementation Reference
- src/index.ts:620-649 (handler)The main handler function for the 'get_schema' tool. It takes validated params (dataSourceId), calls redashClient.getSchema(), and returns the schema as JSON text content.
async function getSchema(params: z.infer<typeof getSchemaSchema>) { try { const { dataSourceId } = params; const query = await redashClient.getSchema(dataSourceId); return { content: [ { type: "text", text: JSON.stringify(query, null, 2), }, ], }; } catch (error) { logger.error( `Error getting data source ${params.dataSourceId} schema: ${error}` ); return { isError: true, content: [ { type: "text", text: `Error getting data source ${params.dataSourceId} schema: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } - src/index.ts:616-618 (schema)Zod schema for validating the 'get_schema' tool input. Requires a 'dataSourceId' (coerced number).
const getSchemaSchema = z.object({ dataSourceId: z.coerce.number(), }); - src/index.ts:1809-1822 (registration)Registration entry for the 'get_schema' tool in the ListToolsRequestSchema handler. Defines the tool name, description, and inputSchema (JSON Schema) for the MCP tool list.
{ name: "get_schema", description: "Get schema of a specific data source", inputSchema: { type: "object", properties: { dataSourceId: { type: "number", description: "ID of the data source to get schema", }, }, required: ["dataSourceId"], }, }, - src/index.ts:2393-2395 (registration)Dispatch case in the CallToolRequestSchema handler that routes 'get_schema' requests to the getSchema handler function with schema validation.
case "get_schema": logger.debug(`Handling get_schema`); return await getSchema(getSchemaSchema.parse(args)); - src/redashClient.ts:738-754 (helper)Helper method on the RedashClient class that makes the actual HTTP GET request to Redash's /api/data_sources/{id}/schema endpoint and returns the schema data.
// Get a specific data source schema by data source ID async getSchema(dataSourceId: number): Promise<RedashSchema> { try { const response = await this.client.get( `/api/data_sources/${dataSourceId}/schema` ); return response.data; } catch (error) { console.error( `Error fetching data source ${dataSourceId} schema:`, error ); throw new Error( `Failed to fetch data source ${dataSourceId} schema from Redash` ); } }