list_tables
Retrieve all tables in a SQL Server database to explore schema structure and identify available data sources for queries and analysis.
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 constructs and executes SQL query to list tables in a database/schemaasync 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); }
- index.js:261-264 (registration)Tool dispatch/registration in the main MCP server switch statement, calling the databaseTools handlercase 'list_tables': return { content: await this.databaseTools.listTables(args.database, args.schema) };
- lib/tools/tool-registry.js:25-36 (schema)Tool schema definition including input validation schema for list_tablesname: '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:241-242 (registration)Registration of the tool list handler which provides all tools including list_tables via tool-registry.jsthis.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getAllTools()
- index.js:527-532 (handler)Wrapper handler method on the main server class for testing/compatibility purposes, delegates to databaseTools.listTablesasync listTables(...args) { try { return { content: await this.databaseTools.listTables(...args) }; } catch (error) { throw new McpError(ErrorCode.InternalError, error.message); }