Skip to main content
Glama

Analyze Table Statistics

analyze-table-statistics

Analyze table statistics including row count, column data, and distribution patterns to understand database structure and optimize queries.

Instructions

Analyzes statistical information about a table including row count, column statistics, and data distribution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYesName of the table to analyze

Implementation Reference

  • The async handler function that executes the core logic: queries row count, table schema using describeTable, sample data, computes statistics object including column details, and returns formatted response or error.
    handler: async (args: z.infer<typeof AnalyzeTableStatisticsArgsSchema>) => {
        const { tableName } = args;
        logger.info(`Analyzing statistics for table: ${tableName}`);
    
        try {
            // Get row count
            const countResult = await executeQuery(`SELECT COUNT(*) as ROW_COUNT FROM "${tableName}"`);
            const rowCount = countResult[0]?.ROW_COUNT || 0;
    
            // Get table schema
            const schema = await describeTable(tableName);
    
            // Get sample data for analysis
            const sampleData = await executeQuery(`SELECT FIRST 100 * FROM "${tableName}"`);
    
            const statistics = {
                tableName,
                rowCount,
                columnCount: schema.length,
                sampleSize: sampleData.length,
                columns: schema.map((col: any) => ({
                    name: col.FIELD_NAME,
                    type: col.FIELD_TYPE,
                    nullable: col.NULL_FLAG === 'YES',
                    hasDefault: !!col.DEFAULT_VALUE
                }))
            };
    
            logger.info(`Statistics analyzed for ${tableName}: ${rowCount} rows, ${schema.length} columns`);
    
            return {
                content: [{
                    type: "text",
                    text: formatForClaude(statistics)
                }]
            };
        } catch (error) {
            const errorResponse = wrapError(error);
            logger.error(`Error analyzing statistics for ${tableName}: ${errorResponse.error}`);
    
            return {
                content: [{
                    type: "text",
                    text: formatForClaude(errorResponse)
                }]
            };
        }
    }
  • Zod input schema requiring a single 'tableName' string parameter.
    export const AnalyzeTableStatisticsArgsSchema = z.object({
        tableName: z.string().min(1).describe("Name of the table to analyze")
    });
  • Registers the 'analyze-table-statistics' tool in the Map returned by setupDatabaseTools, providing name, title, description, schema, and handler.
    tools.set("analyze-table-statistics", {
        name: "analyze-table-statistics",
        title: "Analyze Table Statistics",
        description: "Analyzes statistical information about a table including row count, column statistics, and data distribution.",
        inputSchema: AnalyzeTableStatisticsArgsSchema,
        handler: async (args: z.infer<typeof AnalyzeTableStatisticsArgsSchema>) => {
            const { tableName } = args;
            logger.info(`Analyzing statistics for table: ${tableName}`);
    
            try {
                // Get row count
                const countResult = await executeQuery(`SELECT COUNT(*) as ROW_COUNT FROM "${tableName}"`);
                const rowCount = countResult[0]?.ROW_COUNT || 0;
    
                // Get table schema
                const schema = await describeTable(tableName);
    
                // Get sample data for analysis
                const sampleData = await executeQuery(`SELECT FIRST 100 * FROM "${tableName}"`);
    
                const statistics = {
                    tableName,
                    rowCount,
                    columnCount: schema.length,
                    sampleSize: sampleData.length,
                    columns: schema.map((col: any) => ({
                        name: col.FIELD_NAME,
                        type: col.FIELD_TYPE,
                        nullable: col.NULL_FLAG === 'YES',
                        hasDefault: !!col.DEFAULT_VALUE
                    }))
                };
    
                logger.info(`Statistics analyzed for ${tableName}: ${rowCount} rows, ${schema.length} columns`);
    
                return {
                    content: [{
                        type: "text",
                        text: formatForClaude(statistics)
                    }]
                };
            } catch (error) {
                const errorResponse = wrapError(error);
                logger.error(`Error analyzing statistics for ${tableName}: ${errorResponse.error}`);
    
                return {
                    content: [{
                        type: "text",
                        text: formatForClaude(errorResponse)
                    }]
                };
            }
        }
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions what is analyzed but doesn't disclose behavioral traits such as whether this is a read-only operation, if it requires specific permissions, potential performance impact, or what the output format looks like (e.g., summary vs. detailed report). For a tool with no annotations, this is a significant gap in transparency.

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 purpose ('analyzes statistical information') and lists key components (row count, column statistics, data distribution). There is zero waste, and every word earns its place by clarifying 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 the complexity (statistical analysis tool), no annotations, and no output schema, the description is incomplete. It doesn't explain what the output contains (e.g., numeric summaries, distributions), potential limitations, or how it differs from similar tools. This leaves gaps for an agent to understand the tool's full behavior and use cases.

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 'tableName' fully documented in the schema. The description adds no additional meaning beyond the schema, such as examples of valid table names or constraints. With high schema coverage, the baseline is 3, as the description doesn't compensate but also doesn't detract.

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 ('analyzes') and the target ('statistical information about a table'), specifying what it does (row count, column statistics, data distribution). It distinguishes from siblings like 'describe-table' (metadata) or 'get-table-data' (raw data), but doesn't explicitly name alternatives. This is clear but lacks explicit sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'describe-table' (for schema) or 'analyze-query-performance' (for query stats). It implies usage for statistical analysis but offers no explicit context, prerequisites, or exclusions. This leaves the agent to infer based on tool names alone.

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

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/PuroDelphi/mcpFirebird'

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