Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

list_tables

Retrieve and organize data tables managed by Hasura, filtered by schema, to simplify database exploration and schema discovery.

Instructions

Lists available data tables (or collections) managed by Hasura, organized by schema with descriptions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameNoOptional. The database schema name to filter results. If omitted, returns tables from all schemas.

Implementation Reference

  • The core handler function that implements the logic for listing tables: introspects query_root fields, filters non-table fields, parses schema from descriptions, groups by schema, sorts, and returns JSON-formatted list.
    async ({ schemaName }) => {
        console.log(`[INFO] Executing tool 'list_tables' for schema: ${schemaName || 'ALL'}`);
        try {
          const schema = await getIntrospectionSchema();
          
          const query = gql`
            query GetTablesWithDescriptions {
              __type(name: "query_root") {
                fields {
                  name
                  description
                  type {
                    name
                    kind
                  }
                }
              }
            }
          `;
          
          const result = await makeGqlRequest(query);
          
          const tablesData: Record<string, Array<{name: string, description: string | null}>> = {};
          
          if (result.__type && result.__type.fields) {
            const fieldEntries = result.__type.fields;
            
            for (const field of fieldEntries) {
              if (field.name.includes('_aggregate') || 
                  field.name.includes('_by_pk') || 
                  field.name.includes('_stream') ||
                  field.name.includes('_mutation') ||
                  field.name.startsWith('__')) {
                continue;
              }
              
              let currentSchema = 'public';
              if (field.description && field.description.includes('schema:')) {
                const schemaMatch = field.description.match(/schema:\s*([^\s,]+)/i);
                if (schemaMatch && schemaMatch[1]) {
                  currentSchema = schemaMatch[1];
                }
              }
              
              if (schemaName && currentSchema !== schemaName) {
                continue;
              }
              
              if (!tablesData[currentSchema]) {
                tablesData[currentSchema] = [];
              }
              
              tablesData[currentSchema].push({
                name: field.name,
                description: field.description
              });
            }
          }
          
          const formattedOutput = Object.entries(tablesData)
            .map(([schema, tables]) => ({
              schema,
              tables: tables.sort((a, b) => a.name.localeCompare(b.name))
            }))
            .sort((a, b) => a.schema.localeCompare(b.schema));
            
          return { content: [{ type: "text", text: JSON.stringify(formattedOutput, null, 2) }] };
        } catch (error: any) {
          console.error(`[ERROR] Tool 'list_tables' failed: ${error.message}`);
          throw error;
        }
    }
  • Zod input schema defining the optional 'schemaName' parameter for filtering tables by database schema.
    {
      schemaName: z.string().optional().describe("Optional. The database schema name to filter results. If omitted, returns tables from all schemas.")
    },
  • src/index.ts:167-245 (registration)
    MCP server.tool call registering the 'list_tables' tool with name, description, input schema, and inline handler function.
    server.tool(
      "list_tables",
      "Lists available data tables (or collections) managed by Hasura, organized by schema with descriptions",
      {
        schemaName: z.string().optional().describe("Optional. The database schema name to filter results. If omitted, returns tables from all schemas.")
      },
      async ({ schemaName }) => {
          console.log(`[INFO] Executing tool 'list_tables' for schema: ${schemaName || 'ALL'}`);
          try {
            const schema = await getIntrospectionSchema();
            
            const query = gql`
              query GetTablesWithDescriptions {
                __type(name: "query_root") {
                  fields {
                    name
                    description
                    type {
                      name
                      kind
                    }
                  }
                }
              }
            `;
            
            const result = await makeGqlRequest(query);
            
            const tablesData: Record<string, Array<{name: string, description: string | null}>> = {};
            
            if (result.__type && result.__type.fields) {
              const fieldEntries = result.__type.fields;
              
              for (const field of fieldEntries) {
                if (field.name.includes('_aggregate') || 
                    field.name.includes('_by_pk') || 
                    field.name.includes('_stream') ||
                    field.name.includes('_mutation') ||
                    field.name.startsWith('__')) {
                  continue;
                }
                
                let currentSchema = 'public';
                if (field.description && field.description.includes('schema:')) {
                  const schemaMatch = field.description.match(/schema:\s*([^\s,]+)/i);
                  if (schemaMatch && schemaMatch[1]) {
                    currentSchema = schemaMatch[1];
                  }
                }
                
                if (schemaName && currentSchema !== schemaName) {
                  continue;
                }
                
                if (!tablesData[currentSchema]) {
                  tablesData[currentSchema] = [];
                }
                
                tablesData[currentSchema].push({
                  name: field.name,
                  description: field.description
                });
              }
            }
            
            const formattedOutput = Object.entries(tablesData)
              .map(([schema, tables]) => ({
                schema,
                tables: tables.sort((a, b) => a.name.localeCompare(b.name))
              }))
              .sort((a, b) => a.schema.localeCompare(b.schema));
              
            return { content: [{ type: "text", text: JSON.stringify(formattedOutput, null, 2) }] };
          } catch (error: any) {
            console.error(`[ERROR] Tool 'list_tables' failed: ${error.message}`);
            throw error;
          }
      }
    );
Behavior3/5

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

With no annotations provided, the description carries the full burden. It mentions organization by schema with descriptions, which adds context beyond a basic list. However, it lacks details on behavioral traits such as pagination, rate limits, authentication needs, or what 'available' means (e.g., permissions). The description does not contradict annotations (none exist).

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 ('Lists available data tables') and adds useful context ('organized by schema with descriptions'). There is no wasted verbiage or redundancy, making it appropriately sized for its function.

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

Completeness3/5

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

Given the tool's low complexity (1 optional parameter, no output schema, no annotations), the description is moderately complete. It covers the purpose and organization but lacks details on output format (e.g., structure of returned data), error handling, or integration with siblings. Without an output schema, more guidance on return values would be beneficial.

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%, with the parameter 'schemaName' fully documented in the schema as an optional filter. The description does not add any parameter-specific details beyond what the schema provides, such as format examples or default behavior when omitted. Baseline 3 is appropriate as the schema handles 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 action ('Lists') and resource ('available data tables (or collections) managed by Hasura'), specifying organization by schema with descriptions. It distinguishes from siblings like 'describe_table' (detailed metadata) and 'preview_table_data' (data viewing), though not explicitly named. However, it could be more specific about what 'lists' entails (e.g., names, counts).

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 for browsing tables by schema, but does not explicitly state when to use this tool versus alternatives like 'describe_table' (for detailed info) or 'list_root_fields' (for GraphQL endpoints). No guidance on prerequisites or exclusions is provided, leaving usage context inferred rather than defined.

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