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
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Optional. Maximum number of rows... | |
| tableName | Yes | The 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
- src/index.ts:339-367 (handler)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; } }
- src/index.ts:335-338 (schema)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; } } );