get_table_data
Retrieve sample data from SQL Server tables with optional filtering and row limits for database analysis and exploration.
Instructions
Get sample data from a table with optional filtering and limiting
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table | |
| database | No | Database name (optional) | |
| schema | No | Schema name (optional, defaults to dbo) | |
| limit | No | Maximum number of rows to return (optional, defaults to 100) | |
| where | No | WHERE clause conditions (optional) |
Implementation Reference
- Main implementation of get_table_data tool: constructs paginated SELECT query for the specified table and executes it via executeQuery/** * Get table data with pagination support */ async getTableData(tableName, database = null, schema = 'dbo', limit = 100, offset = 0) { let query; if (database) { query = ` SELECT * FROM [${database}].[${schema}].[${tableName}] ORDER BY (SELECT NULL) OFFSET ${offset} ROWS FETCH NEXT ${limit} ROWS ONLY `; } else { query = ` SELECT * FROM [${schema}].[${tableName}] ORDER BY (SELECT NULL) OFFSET ${offset} ROWS FETCH NEXT ${limit} ROWS ONLY `; } const result = await this.executeQuery(query, 'get_table_data'); return this.formatResults(result); }
- lib/tools/tool-registry.js:66-83 (schema)Input schema and metadata definition for the get_table_data tool used in tool listing{ name: 'get_table_data', description: 'Get sample data from a table with optional filtering and limiting', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table' }, database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' }, limit: { type: 'number', description: 'Maximum number of rows to return (optional, defaults to 100)' }, where: { type: 'string', description: 'WHERE clause conditions (optional)' } }, required: ['table_name'] } },
- index.js:287-296 (registration)Registration and dispatch of get_table_data tool call to the DatabaseToolsHandler in the main MCP server switch statementcase 'get_table_data': return { content: await this.databaseTools.getTableData( args.table_name, args.database, args.schema, args.limit, args.offset ) };