Skip to main content
Glama

mcp_get_column_stats

Analyze column statistics in SQL Server tables to understand data distribution, identify patterns, and assess data quality for specific columns.

Instructions

Get comprehensive statistics for a specific column in a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesFully qualified table name (schema.table), e.g. "api.Idiomas"
column_nameYesName of the column to analyze

Implementation Reference

  • The core handler function that implements the mcp_get_column_stats tool. It queries the SQL Server database to compute statistics like total rows, null count, distinct count, min/max values, and top 10 sample values for the specified column.
    export const mcp_get_column_stats = async (args: { table_name: string, column_name: string }): Promise<ToolResult<any>> => {
      const { table_name, column_name } = args;
      console.log('Executing mcp_get_column_stats with:', args);
    
      try {
        const pool = getPool();
        const normalizedTableName = normalizeSqlObjectName(table_name);
        
        // Note: We're using double quotes for identifiers and params for values to prevent SQL injection
        const query = `
          SELECT
            '${column_name}' as column_name,
            COUNT(*) AS total_rows,
            SUM(CASE WHEN [${column_name}] IS NULL THEN 1 ELSE 0 END) AS null_count,
            COUNT(DISTINCT [${column_name}]) AS distinct_count,
            MIN([${column_name}]) AS min_value,
            MAX([${column_name}]) AS max_value
          FROM ${normalizedTableName}
        `;
        
        const result = await pool.request().query(query);
        
        // Get sample values
        const sampleQuery = `
          SELECT TOP 10 [${column_name}] AS value
          FROM ${normalizedTableName}
          WHERE [${column_name}] IS NOT NULL
          GROUP BY [${column_name}]
          ORDER BY COUNT(*) DESC
        `;
        
        const sampleResult = await pool.request().query(sampleQuery);
        
        const stats = result.recordset[0] || {};
        
        return { 
          success: true, 
          data: {
            ...stats,
            sample_values: sampleResult.recordset.map(row => row.value)
          }
        };
      } catch (error: any) {
        console.error(`Error in mcp_get_column_stats for table ${table_name}, column ${column_name}: ${error.message}`);
        return { success: false, error: error.message };
      }
    };
  • The tool definition including name, description, and input schema (parameters: table_name and column_name) used for tool listing and validation in the MCP server.
    {
      name: "mcp_get_column_stats",
      description: "Get comprehensive statistics for a specific column in a table",
      inputSchema: {
        type: "object",
        properties: {
          table_name: {
            type: "string",
            description: "Fully qualified table name (schema.table), e.g. \"api.Idiomas\""
          },
          column_name: {
            type: "string",
            description: "Name of the column to analyze"
          }
        },
        required: ["table_name", "column_name"]
      }
    },
  • Re-export of the mcp_get_column_stats handler (and related tools) from dataOperations.ts, making it available by name in the toolHandlers object imported by the MCP server for dynamic execution.
    export {
      mcp_preview_data,      // Data preview with filters
      mcp_preview_data_enhanced, // Para compatibilidad con server.ts
      mcp_get_column_stats,   // Column statistics
      mcp_get_column_stats_enhanced, // Para compatibilidad con server.ts
      mcp_quick_data_analysis, // Quick table analysis
      mcp_get_sample_values   // Sample values from column
    } from './dataOperations.js';
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get comprehensive statistics' implies a read-only operation, it doesn't specify whether this requires special permissions, what 'comprehensive' entails (e.g., statistical measures included), performance characteristics, or potential limitations like row count restrictions. The description provides minimal behavioral context beyond the basic operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point without unnecessary words. It's appropriately sized for a tool with two parameters and clear purpose, though it could potentially benefit from slightly more context given the lack of annotations and sibling tool differentiation.

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?

For a statistical analysis tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what 'comprehensive statistics' includes (mean, median, distribution, null counts, etc.), doesn't mention performance considerations for large tables, and provides no guidance on how this tool fits within the broader analytical toolkit represented by sibling tools.

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?

The description doesn't add any parameter information beyond what's already in the schema, which has 100% coverage with clear descriptions for both parameters. The baseline score of 3 is appropriate since the schema fully documents the parameters, and the description doesn't need to compensate for any gaps.

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 ('Get comprehensive statistics') and target ('for a specific column in a table'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like mcp_table_analysis or mcp_quick_data_analysis, which might offer overlapping functionality.

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. With siblings like mcp_table_analysis, mcp_quick_data_analysis, and mcp_preview_data that might offer related analytical functions, there's no indication of when this column-specific statistics tool is preferred or what distinguishes it from broader analysis tools.

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/hendrickcastro/MCPQL'

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