Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

preview_table_data

Retrieve a sample of rows from a specified table to preview data, with an optional row limit, for efficient schema exploration and query validation.

Instructions

Fetch esa limited sample of rows (default 5) from a specified table...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoOptional. Maximum number of rows...
tableNameYesThe exact name of the table...

Implementation Reference

  • The main handler function for the 'preview_table_data' tool. It fetches the GraphQL introspection schema, finds the table object type, selects scalar and enum fields, builds a GraphQL query to preview limited rows, executes it via makeGqlRequest, and returns the result as formatted JSON text.
    async ({ tableName, limit }) => {
      console.log(`[INFO] Executing tool 'preview_table_data' for table: ${tableName}, limit: ${limit}`);
      try {
        const schema = await getIntrospectionSchema();
        const tableType = schema.types.find(t => t.name === tableName && t.kind === 'OBJECT') as IntrospectionObjectType | undefined;
        if (!tableType) {
            throw new Error(`Table (Object type) '${tableName}' not found in schema.`);
        }
        const scalarFields = tableType.fields
          ?.filter(f => { 
              let currentType = f.type;
              while (currentType.kind === 'NON_NULL' || currentType.kind === 'LIST') currentType = currentType.ofType;
              return currentType.kind === 'SCALAR' || currentType.kind === 'ENUM';
          })
          .map(f => f.name) || [];
         if (scalarFields.length === 0) {
             console.warn(`[WARN] No scalar fields found for table ${tableName}...`);
             scalarFields.push('__typename');
         }
        const fieldsString = scalarFields.join('\n          ');
        const query = gql` query PreviewData($limit: Int!) { ${tableName}(limit: $limit) { ${fieldsString} } }`;
        const variables = { limit };
        const result = await makeGqlRequest(query, variables);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      } catch (error: any) {
        console.error(`[ERROR] Tool 'preview_table_data' failed: ${error.message}`);
        throw error;
      }
    }
  • Zod input schema for the tool, defining 'tableName' as a required string and 'limit' as an optional positive integer defaulting to 5.
    {
      tableName: z.string().describe("The exact name of the table..."),
      limit: z.number().int().positive().optional().default(5).describe("Optional. Maximum number of rows..."),
    },
  • src/index.ts:332-368 (registration)
    The server.tool() registration call for 'preview_table_data', including the tool name, description, input schema, and handler function.
    server.tool(
      "preview_table_data",
      "Fetch esa limited sample of rows (default 5) from a specified table...",
      {
        tableName: z.string().describe("The exact name of the table..."),
        limit: z.number().int().positive().optional().default(5).describe("Optional. Maximum number of rows..."),
      },
      async ({ tableName, limit }) => {
        console.log(`[INFO] Executing tool 'preview_table_data' for table: ${tableName}, limit: ${limit}`);
        try {
          const schema = await getIntrospectionSchema();
          const tableType = schema.types.find(t => t.name === tableName && t.kind === 'OBJECT') as IntrospectionObjectType | undefined;
          if (!tableType) {
              throw new Error(`Table (Object type) '${tableName}' not found in schema.`);
          }
          const scalarFields = tableType.fields
            ?.filter(f => { 
                let currentType = f.type;
                while (currentType.kind === 'NON_NULL' || currentType.kind === 'LIST') currentType = currentType.ofType;
                return currentType.kind === 'SCALAR' || currentType.kind === 'ENUM';
            })
            .map(f => f.name) || [];
           if (scalarFields.length === 0) {
               console.warn(`[WARN] No scalar fields found for table ${tableName}...`);
               scalarFields.push('__typename');
           }
          const fieldsString = scalarFields.join('\n          ');
          const query = gql` query PreviewData($limit: Int!) { ${tableName}(limit: $limit) { ${fieldsString} } }`;
          const variables = { limit };
          const result = await makeGqlRequest(query, variables);
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        } catch (error: any) {
          console.error(`[ERROR] Tool 'preview_table_data' 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 the full burden. It mentions the default limit of 5 rows, which is useful behavioral context. However, it lacks details on permissions needed, error handling (e.g., if table doesn't exist), or response format (e.g., structure of returned rows), leaving gaps for a tool that fetches data.

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 ('fetch esa limited sample of rows') and includes key details (default limit, table specification). There is no wasted text, making it highly concise and well-structured.

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 no annotations and no output schema, the description is adequate for a simple data-fetching tool with two parameters. It covers the basic purpose and default behavior, but lacks details on output (e.g., what 'esa' means, row format) and error conditions, which could be important 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 fully documents both parameters (tableName and limit). The description adds minimal value by mentioning the default limit of 5, but doesn't provide additional context beyond what the schema already covers, such as examples or constraints not in the schema.

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 ('fetch') and resource ('rows from a specified table'), specifying it's a 'limited sample' with a default of 5 rows. It distinguishes from siblings like 'describe_table' (metadata) or 'run_graphql_query' (full queries), but doesn't explicitly name alternatives.

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 previewing table data with a sample, suggesting it's for quick inspection rather than full data retrieval. However, it doesn't explicitly state when to use this versus alternatives like 'run_graphql_query' for complete data or 'list_tables' for table discovery.

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