Skip to main content
Glama
michaelyuwh

Enhanced MCP MSSQL Server

by michaelyuwh

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
NameRequiredDescriptionDefault
serverYesMSSQL Server hostname or IP address
portNoPort number (default: 1433)
userYesUsername for authentication
passwordYesPassword for authentication
databaseYesDatabase name
tableYesTable name
limitNoNumber of sample rows (default: 10)
encryptNoUse encrypted connection (default: true)
trustServerCertificateNoTrust server certificate (default: true)

Implementation Reference

  • 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);
  • 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'),
    });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/michaelyuwh/mcp-mssql-connector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server