mssql_list_tables
Retrieve all table names from a Microsoft SQL Server database to discover database structure and available data sources.
Instructions
List all tables in a database
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 | |
| encrypt | No | Use encrypted connection (default: true) | |
| trustServerCertificate | No | Trust server certificate (default: true) |
Implementation Reference
- src/index.ts:497-525 (handler)The handler function for mssql_list_tables tool. Parses connection args, connects to the database, executes a query to list tables from INFORMATION_SCHEMA.TABLES, and returns the result as JSON.private async handleListTables(args: any) { const config = ConnectionSchema.parse(args); const pool = await this.getConnection(config); const request = pool.request(); const result = await request.query(` USE [${config.database}]; SELECT TABLE_SCHEMA as schema_name, TABLE_NAME as table_name, TABLE_TYPE as table_type FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_SCHEMA, TABLE_NAME `); return { content: [ { type: 'text', text: JSON.stringify({ server: config.server, database: config.database, tables: result.recordset, }, null, 2), }, ], }; }
- src/index.ts:288-303 (schema)Input schema definition for the mssql_list_tables tool, specifying connection parameters and database name as required.{ name: 'mssql_list_tables', description: 'List all tables in a database', 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' }, 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'], },
- src/index.ts:439-440 (registration)Registration of the mssql_list_tables handler in the tool call switch statement.case 'mssql_list_tables': return await this.handleListTables(args);