mcp_preview_data
Preview data from a SQL Server table using optional filters and row limits for quick insights and validation.
Instructions
Get a preview of data from a SQL Server table with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filters | No | Optional filters as column-value pairs, e.g. {"Status": "Active"} | |
| limit | No | Maximum number of rows to return | |
| table_name | Yes | Fully qualified table name (schema.table), e.g. "dbo.Users" |
Implementation Reference
- src/tools/dataOperations.ts:40-66 (handler)The main handler function implementing the tool logic: previews data from a SQL table with optional filters and row limit using parameterized queries.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 (registration)Tool registration in MCP_MSQL_TOOLS array, providing name, description, and detailed input schema for tool discovery.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/server.ts:64-66 (registration)MCP server registration for ListTools request handler, exposing all tools including mcp_preview_data via MCP_MSQL_TOOLS.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: MCP_MSQL_TOOLS }));