Skip to main content
Glama

mcp_get_sample_values

Retrieve distinct sample values from a specified column in a database table, with an optional limit on the number of values returned. Simplify data analysis and validation tasks.

Instructions

Get sample values from a specific column in a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
column_nameYesName of the column to get sample values from
limitNoMaximum number of distinct values to return
table_nameYesFully qualified table name (schema.table), e.g. "dbo.Users"

Implementation Reference

  • The main handler function that executes a SQL query to retrieve the top N most frequent distinct values from a specified column in a table, including their frequencies.
    export const mcp_get_sample_values = async (args: { table_name: string; column_name: string; limit?: number }): Promise<ToolResult<any[]>> => { const { table_name, column_name, limit = 10 } = args; console.log('Executing mcp_get_sample_values with:', args); try { const pool = getPool(); const normalizedTableName = normalizeSqlObjectName(table_name); const query = ` SELECT TOP ${limit} [${column_name}] AS value, COUNT(*) AS frequency FROM ${normalizedTableName} WHERE [${column_name}] IS NOT NULL GROUP BY [${column_name}] ORDER BY COUNT(*) DESC, [${column_name}] `; const result = await pool.request().query(query); return { success: true, data: result.recordset }; } catch (error: any) { console.error(`Error in mcp_get_sample_values: ${error.message}`); return { success: false, error: error.message }; } };
  • src/tools.ts:189-211 (registration)
    Tool registration in MCP_MSQL_TOOLS array, defining name, description, and input schema for MCP protocol.
    { name: "mcp_get_sample_values", description: "Get sample values from a specific column in a table", inputSchema: { type: "object", properties: { table_name: { type: "string", description: "Fully qualified table name (schema.table), e.g. \"dbo.Users\"" }, column_name: { type: "string", description: "Name of the column to get sample values from" }, limit: { type: "number", description: "Maximum number of distinct values to return", default: 10 } }, required: ["table_name", "column_name"] } },
  • src/server.ts:97-98 (registration)
    Server-side dispatch in the CallTool handler that routes requests for this tool to its handler function.
    case 'mcp_get_sample_values': result = await toolHandlers.mcp_get_sample_values(input as any);
  • Re-export of the handler function from dataOperations.ts for use in toolHandlers.
    mcp_get_sample_values // Sample values from column } from './dataOperations.js';

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