Skip to main content
Glama

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

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "limit": { "default": 5, "description": "Optional. Maximum number of rows...", "exclusiveMinimum": 0, "type": "integer" }, "tableName": { "description": "The exact name of the table...", "type": "string" } }, "required": [ "tableName" ], "type": "object" }

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; } } );

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