mcp_preview_data
Preview SQL Server table data with optional filters to quickly examine records before deeper analysis. Specify table name, apply filters, and set row limits to sample database content.
Instructions
Get a preview of data from a SQL Server table with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Fully qualified table name (schema.table), e.g. "dbo.Users" | |
| filters | No | Optional filters as column-value pairs, e.g. {"Status": "Active"} | |
| limit | No | Maximum number of rows to return |
Implementation Reference
- src/tools/dataOperations.ts:40-66 (handler)Core implementation of the mcp_preview_data tool handler. Executes a parameterized SQL query to preview table data with optional filters and row limit.export const mcp_preview_data = async (args: { table_name: string; filters?: object; limit?: number }): Promise<ToolResult<any[]>> => { const { table_name, filters, limit = 100 } = args; console.log('Executing mcp_preview_data with:', args); try { const pool = getPool(); const request = pool.request(); const normalizedTableName = normalizeSqlObjectName(table_name); let query = `SELECT TOP ${limit} * FROM ${normalizedTableName}`; if (filters && Object.keys(filters).length > 0) { const whereClauses = Object.entries(filters).map(([key, value], index) => { const paramName = `param${index}`; request.input(paramName, value); return `${key} = @${paramName}`; }); query += ` WHERE ${whereClauses.join(' AND ')}`; } const result = await request.query(query); return { success: true, data: result.recordset }; } catch (error: any) { console.error('Error in mcp_preview_data:', error); return { success: false, error: error.message }; } };
- src/tools.ts:36-59 (schema)JSON schema definition and tool metadata for mcp_preview_data, including input validation schema used for MCP tool registration.name: "mcp_preview_data", description: "Get a preview of data from a SQL Server table with optional filters", inputSchema: { type: "object", properties: { table_name: { type: "string", description: "Fully qualified table name (schema.table), e.g. \"dbo.Users\"" }, filters: { type: "object", description: "Optional filters as column-value pairs, e.g. {\"Status\": \"Active\"}" }, limit: { type: "number", description: "Maximum number of rows to return", default: 100, minimum: 1, maximum: 1000 } }, required: ["table_name"] } },
- src/tools/index.ts:20-27 (registration)Export registration of the mcp_preview_data handler function from dataOperations for use in tool collections.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';