mssql_sample_data
Retrieve sample data from MSSQL Server tables to preview content and structure for analysis or testing purposes.
Instructions
Get sample data from a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | MSSQL Server hostname or IP address | |
| port | No | Port number (default: 1433) | |
| user | Yes | Username for authentication | |
| password | Yes | Password for authentication | |
| database | Yes | Database name | |
| table | Yes | Table name | |
| limit | No | Number of sample rows (default: 10) | |
| encrypt | No | Use encrypted connection (default: true) | |
| trustServerCertificate | No | Trust server certificate (default: true) |
Implementation Reference
- src/index.ts:631-656 (handler)Executes the tool logic: parses arguments, connects to MSSQL, queries sample data with SELECT TOP ${limit} * FROM [table], returns JSON with results.
private async handleSampleData(args: any) { const config = ConnectionSchema.parse(args); const { table, limit = 10 } = args; const pool = await this.getConnection(config); const request = pool.request(); const result = await request.query(` USE [${config.database}]; SELECT TOP ${limit} * FROM [${table}] `); return { content: [ { type: 'text', text: JSON.stringify({ server: config.server, database: config.database, table: table, sampleSize: result.recordset.length, data: result.recordset, }, null, 2), }, ], }; } - src/index.ts:342-360 (registration)Registers the mssql_sample_data tool in the list of available tools, including name, description, and input schema.
{ name: 'mssql_sample_data', description: 'Get sample data from a table', inputSchema: { type: 'object', properties: { server: { type: 'string', description: 'MSSQL Server hostname or IP address' }, port: { type: 'number', description: 'Port number (default: 1433)', default: 1433 }, user: { type: 'string', description: 'Username for authentication' }, password: { type: 'string', description: 'Password for authentication' }, database: { type: 'string', description: 'Database name' }, table: { type: 'string', description: 'Table name' }, limit: { type: 'number', description: 'Number of sample rows (default: 10)', default: 10 }, encrypt: { type: 'boolean', description: 'Use encrypted connection (default: true)', default: true }, trustServerCertificate: { type: 'boolean', description: 'Trust server certificate (default: true)', default: true }, }, required: ['server', 'user', 'password', 'database', 'table'], }, }, - src/index.ts:445-446 (registration)Dispatches tool calls to the handleSampleData handler in the switch statement.
case 'mssql_sample_data': return await this.handleSampleData(args); - src/index.ts:76-84 (schema)Zod schema used to parse and validate connection parameters for the tool.
const ConnectionSchema = z.object({ server: z.string().describe('MSSQL Server hostname or IP address'), port: z.number().default(1433).describe('Port number (default: 1433)'), user: z.string().describe('Username for authentication'), password: z.string().describe('Password for authentication'), database: z.string().optional().describe('Database name (optional)'), encrypt: z.boolean().default(true).describe('Use encrypted connection'), trustServerCertificate: z.boolean().default(true).describe('Trust server certificate'), });