Skip to main content
Glama
InsForge

Insforge MCP Server

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
NameRequiredDescriptionDefault
apiKeyNoAPI key for authentication (optional if provided via --api_key)
tableNameYesName of the table

Implementation Reference

  • 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,
          };
        }
      })
    );
  • 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'),
    },
  • 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,
          };
        }
      })
    );

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