Skip to main content
Glama

get-table-schema

Retrieve detailed database table schema including RLS policies, indexes, and constraints to understand table structure and relationships for database analysis and management.

Instructions

Returns the detailed schema(including RLS, indexes, constraints, etc.) of a specific table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyNoAPI key for authentication (optional if provided via --api_key)
tableNameYesName of the table

Implementation Reference

  • Handler function that fetches the detailed schema of a specific table from the backend API endpoint /api/metadata/{tableName}, handles the response, adds background context, and formats the output.
    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, }; } })
  • Zod input schema defining parameters: apiKey (optional string) and tableName (required string).
    { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), tableName: z.string().describe('Name of the table'), },
  • Complete MCP server.tool registration including name, description, input schema, and wrapped handler for the get-table-schema tool.
    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, }; } }) );
  • Helper function getApiKey that returns the global API key, throwing error if not set.
    const getApiKey = (_toolApiKey?: string): string => { if (!GLOBAL_API_KEY) { throw new Error('API key is required. Pass --api_key when starting the MCP server.'); } return GLOBAL_API_KEY; };
  • Helper wrapper withUsageTracking that adds usage tracking around tool handlers, logging success or failure.
    function withUsageTracking<T extends unknown[], R>( toolName: string, handler: (...args: T) => Promise<R> ): (...args: T) => Promise<R> { return async (...args: T): Promise<R> => { try { const result = await handler(...args); await trackToolUsage(toolName, true); return result; } catch (error) { await trackToolUsage(toolName, false); throw error; } }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/InsForge/insforge-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server