Skip to main content
Glama

mcp_get_column_stats

Analyze and retrieve detailed statistics for a specific column in a table using this MCPQL server tool for efficient database insights and performance optimization.

Instructions

Get comprehensive statistics for a specific column in a table

Input Schema

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

Implementation Reference

  • The handler function that executes the mcp_get_column_stats tool. It queries the SQL Server database to compute statistics for a specific column including total rows, null count, distinct count, min/max values, and top 10 sample values.
    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 }; } };
  • Defines the input schema and metadata for the mcp_get_column_stats tool, including required parameters table_name and column_name.
    { 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"] } },
  • src/server.ts:64-66 (registration)
    Registers the list of tools including mcp_get_column_stats via the MCP_MSQL_TOOLS array in the ListTools handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: MCP_MSQL_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