list_tables
Retrieve all tables from a SQL Server database to explore database structure and identify available data sources for querying.
Instructions
List all tables in a specific database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, uses current database if not specified) | |
| schema | No | Schema name (optional, defaults to dbo) |
Implementation Reference
- Core handler function that executes SQL query to list tables in a database/schema using INFORMATION_SCHEMA.TABLESasync listTables(database = null, schema = 'dbo') { let query; if (database) { query = ` SELECT t.TABLE_SCHEMA as schema_name, t.TABLE_NAME as table_name, t.TABLE_TYPE as table_type FROM [${database}].INFORMATION_SCHEMA.TABLES t WHERE t.TABLE_SCHEMA = '${schema}' ORDER BY t.TABLE_SCHEMA, t.TABLE_NAME `; } else { query = ` SELECT t.TABLE_SCHEMA as schema_name, t.TABLE_NAME as table_name, t.TABLE_TYPE as table_type FROM INFORMATION_SCHEMA.TABLES t WHERE t.TABLE_SCHEMA = '${schema}' ORDER BY t.TABLE_SCHEMA, t.TABLE_NAME `; } const result = await this.executeQuery(query, 'list_tables'); return this.formatResults(result); }
- lib/tools/tool-registry.js:24-37 (schema)Tool schema definition including input schema for parameters database and schema{ name: 'list_tables', description: 'List all tables in a specific database', inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional, uses current database if not specified)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' } } } },
- index.js:261-264 (registration)Tool registration in the main switch case for handling tool calls, delegates to databaseTools.listTablescase 'list_tables': return { content: await this.databaseTools.listTables(args.database, args.schema) };
- index.js:241-243 (registration)Registration of list tools endpoint which provides the tool list including list_tables via getAllTools() from registrythis.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getAllTools() }));
- index.js:527-532 (handler)Delegating wrapper method in main server class that calls the databaseTools handlerasync listTables(...args) { try { return { content: await this.databaseTools.listTables(...args) }; } catch (error) { throw new McpError(ErrorCode.InternalError, error.message); }