get-table-schema
Retrieve detailed table schema including RLS policies, indexes, and constraints to understand database structure and implement secure data access.
Instructions
Returns the detailed schema(including RLS, indexes, constraints, etc.) of a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | API key for authentication (optional if provided via --api_key) | |
| tableName | Yes | Name of the table |
Implementation Reference
- src/shared/tools.ts:371-404 (handler)The handler function for the 'get-table-schema' tool. It fetches the detailed table schema from the backend API endpoint `/api/metadata/{tableName}` using the provided or global API key, processes the response with handleApiResponse, adds optional background context, formats the output, and handles errors gracefully.withUsageTracking('get-table-schema', async ({ apiKey, tableName }) => { try { const actualApiKey = getApiKey(apiKey); const response = await fetch(`${API_BASE_URL}/api/metadata/${tableName}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('Schema retrieved', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error getting table schema: ${errMsg}`, }, ], isError: true, }; } }) );
- src/shared/tools.ts:364-370 (schema)Input schema validation using Zod schemas for the tool parameters: optional 'apiKey' string and required 'tableName' string.{ apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), tableName: z.string().describe('Name of the table'), },
- src/shared/tools.ts:361-404 (registration)Registration of the 'get-table-schema' tool on the MCP server within the registerInsforgeTools function, including name, description, input schema, and wrapped handler.server.tool( 'get-table-schema', 'Returns the detailed schema(including RLS, indexes, constraints, etc.) of a specific table', { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), tableName: z.string().describe('Name of the table'), }, withUsageTracking('get-table-schema', async ({ apiKey, tableName }) => { try { const actualApiKey = getApiKey(apiKey); const response = await fetch(`${API_BASE_URL}/api/metadata/${tableName}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('Schema retrieved', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error getting table schema: ${errMsg}`, }, ], isError: true, }; } }) );