mcp_get_sample_values
Retrieve sample values from a database column to understand data patterns, validate content, or prepare for analysis. Specify table, column, and limit parameters to extract distinct values.
Instructions
Get sample values from a specific column in a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Fully qualified table name (schema.table), e.g. "dbo.Users" | |
| column_name | Yes | Name of the column to get sample values from | |
| limit | No | Maximum number of distinct values to return |
Implementation Reference
- src/tools/dataOperations.ts:201-227 (handler)The main execution handler for the mcp_get_sample_values tool. Queries the database for the top distinct values in the specified column, grouped by value with frequency counts, ordered by frequency descending.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 (schema)MCP tool schema definition specifying input parameters, descriptions, types, and requirements.{ 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/tools.ts:189-211 (registration)The tool is registered in the MCP_MSQL_TOOLS array used by listTools handler.{ 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-99 (registration)Dispatcher switch case that routes calls to the mcp_get_sample_values handler.case 'mcp_get_sample_values': result = await toolHandlers.mcp_get_sample_values(input as any); break;
- src/tools/index.ts:26-27 (helper)Re-export of the handler from dataOperations.ts to centralize tool exports.mcp_get_sample_values // Sample values from column } from './dataOperations.js';