Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

describe_table

Examine table structure with column types and descriptions using a Hasura GraphQL MCP Server. Input table name and optional schema to retrieve details.

Instructions

Shows the structure of a table including all columns with their types and descriptions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameNoOptional. The database schema name, defaults to 'public'public
tableNameYesThe exact name of the table to describe

Implementation Reference

  • The handler function for 'describe_table' tool. It performs GraphQL introspection to fetch the table type, handles case variations for type name, parses field types (including lists and non-nulls), and returns structured column information.
    async ({ tableName, schemaName }) => {
      console.log(`[INFO] Executing tool 'describe_table' for table: ${tableName} in schema: ${schemaName}`);
      try {
        const schema = await getIntrospectionSchema();
        
        const tableTypeQuery = gql`
          query GetTableType($typeName: String!) {
            __type(name: $typeName) {
              name
              kind
              description
              fields {
                name
                description
                type {
                  kind
                  name
                  ofType {
                    kind
                    name
                    ofType {
                      kind
                      name
                      ofType {
                        kind
                        name
                      }
                    }
                  }
                }
                args {
                  name
                  description
                  type {
                    kind
                    name
                    ofType {
                      kind
                      name
                    }
                  }
                }
              }
            }
          }
        `;
        
        const tableTypeResult = await makeGqlRequest(tableTypeQuery, { typeName: tableName });
        
        if (!tableTypeResult.__type) {
          console.log(`[INFO] No direct match for table type: ${tableName}, trying case variations`);
          const pascalCaseName = tableName.charAt(0).toUpperCase() + tableName.slice(1);
          const alternativeResult = await makeGqlRequest(tableTypeQuery, { typeName: pascalCaseName });
          if (!alternativeResult.__type) {
            throw new Error(`Table '${tableName}' not found in schema. Check the table name and schema.`);
          }
          tableTypeResult.__type = alternativeResult.__type;
        }
        
        const columnsInfo = tableTypeResult.__type.fields.map((field: any) => {
          let typeInfo = field.type;
          let typeString = '';
          let isNonNull = false;
          let isList = false;
          
          while (typeInfo) {
            if (typeInfo.kind === 'NON_NULL') {
              isNonNull = true;
              typeInfo = typeInfo.ofType;
            } else if (typeInfo.kind === 'LIST') {
              isList = true;
              typeInfo = typeInfo.ofType;
            } else {
              typeString = typeInfo.name || 'unknown';
              break;
            }
          }
          
          let fullTypeString = '';
          if (isList) {
            fullTypeString = `[${typeString}]`;
          } else {
            fullTypeString = typeString;
          }
          if (isNonNull) {
            fullTypeString += '!';
          }
          
          return {
            name: field.name,
            type: fullTypeString,
            description: field.description || null,
            args: field.args?.length ? field.args : null
          };
        });
        
        const result = {
          table: {
            name: tableName,
            schema: schemaName,
            description: tableTypeResult.__type.description || null,
            columns: columnsInfo.sort((a: any, b: any) => a.name.localeCompare(b.name))
          }
        };
        
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      } catch (error: any) {
        console.error(`[ERROR] Tool 'describe_table' failed: ${error.message}`);
        throw error;
      }
    }
  • Input schema using Zod: requires 'tableName' (string), optional 'schemaName' (string, defaults to 'public').
    {
      tableName: z.string().describe("The exact name of the table to describe"),
      schemaName: z.string().optional().default('public').describe("Optional. The database schema name, defaults to 'public'")
    },
  • src/index.ts:468-585 (registration)
    Registration of the 'describe_table' tool via server.tool(), including name, description, input schema, and handler reference.
      "describe_table",
      "Shows the structure of a table including all columns with their types and descriptions",
      {
        tableName: z.string().describe("The exact name of the table to describe"),
        schemaName: z.string().optional().default('public').describe("Optional. The database schema name, defaults to 'public'")
      },
      async ({ tableName, schemaName }) => {
        console.log(`[INFO] Executing tool 'describe_table' for table: ${tableName} in schema: ${schemaName}`);
        try {
          const schema = await getIntrospectionSchema();
          
          const tableTypeQuery = gql`
            query GetTableType($typeName: String!) {
              __type(name: $typeName) {
                name
                kind
                description
                fields {
                  name
                  description
                  type {
                    kind
                    name
                    ofType {
                      kind
                      name
                      ofType {
                        kind
                        name
                        ofType {
                          kind
                          name
                        }
                      }
                    }
                  }
                  args {
                    name
                    description
                    type {
                      kind
                      name
                      ofType {
                        kind
                        name
                      }
                    }
                  }
                }
              }
            }
          `;
          
          const tableTypeResult = await makeGqlRequest(tableTypeQuery, { typeName: tableName });
          
          if (!tableTypeResult.__type) {
            console.log(`[INFO] No direct match for table type: ${tableName}, trying case variations`);
            const pascalCaseName = tableName.charAt(0).toUpperCase() + tableName.slice(1);
            const alternativeResult = await makeGqlRequest(tableTypeQuery, { typeName: pascalCaseName });
            if (!alternativeResult.__type) {
              throw new Error(`Table '${tableName}' not found in schema. Check the table name and schema.`);
            }
            tableTypeResult.__type = alternativeResult.__type;
          }
          
          const columnsInfo = tableTypeResult.__type.fields.map((field: any) => {
            let typeInfo = field.type;
            let typeString = '';
            let isNonNull = false;
            let isList = false;
            
            while (typeInfo) {
              if (typeInfo.kind === 'NON_NULL') {
                isNonNull = true;
                typeInfo = typeInfo.ofType;
              } else if (typeInfo.kind === 'LIST') {
                isList = true;
                typeInfo = typeInfo.ofType;
              } else {
                typeString = typeInfo.name || 'unknown';
                break;
              }
            }
            
            let fullTypeString = '';
            if (isList) {
              fullTypeString = `[${typeString}]`;
            } else {
              fullTypeString = typeString;
            }
            if (isNonNull) {
              fullTypeString += '!';
            }
            
            return {
              name: field.name,
              type: fullTypeString,
              description: field.description || null,
              args: field.args?.length ? field.args : null
            };
          });
          
          const result = {
            table: {
              name: tableName,
              schema: schemaName,
              description: tableTypeResult.__type.description || null,
              columns: columnsInfo.sort((a: any, b: any) => a.name.localeCompare(b.name))
            }
          };
          
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        } catch (error: any) {
          console.error(`[ERROR] Tool 'describe_table' failed: ${error.message}`);
          throw error;
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only operation, what permissions are required, how errors are handled, or the format of the returned structure. The description is minimal beyond stating the output content.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part of the sentence contributes directly to understanding the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that returns structural metadata. It doesn't explain the return format, error conditions, or behavioral traits, leaving significant gaps for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, such as examples or constraints. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'shows' and the resource 'structure of a table', specifying what information is included (columns with types and descriptions). It distinguishes from siblings like list_tables (which lists table names) and preview_table_data (which shows actual data), though not explicitly named.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing table metadata rather than data or schema listings, but doesn't explicitly state when to use this tool versus alternatives like list_tables or preview_table_data. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/husamabusafa/hasura_mcp'

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