td_list_tables
List tables in a Treasure Data database to explore data structure and find datasets. Shows table names or detailed schemas, sizes, and record counts for data discovery and query planning.
Instructions
List tables in a database to explore data structure and find datasets.
Shows all tables within a specific database. Returns table names for quick
scanning, or set verbose=True for schemas, sizes, and record counts.
Common scenarios:
- Explore available data in a database
- Find specific tables by scanning names
- Check table schemas before writing queries
- Audit table sizes and record counts
- Verify table exists before querying
Supports pagination (limit/offset) or all_results=True for complete list.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| all_results | No | ||
| database_name | Yes | ||
| limit | No | ||
| offset | No | ||
| verbose | No |
Implementation Reference
- td_mcp_server/mcp_impl.py:231-292 (handler)The td_list_tables tool handler decorated with @mcp.tool(), which registers the tool and defines its input schema via type annotations and defaults. Implements validation, client creation, database check, table listing with pagination support, verbose output, and error handling using TreasureDataClient.@mcp.tool() async def td_list_tables( database_name: str, verbose: bool = False, limit: int = DEFAULT_LIMIT, offset: int = 0, all_results: bool = False, ) -> dict[str, Any]: """List tables in a database to explore data structure and find datasets. Shows all tables within a specific database. Returns table names for quick scanning, or set verbose=True for schemas, sizes, and record counts. Common scenarios: - Explore available data in a database - Find specific tables by scanning names - Check table schemas before writing queries - Audit table sizes and record counts - Verify table exists before querying Supports pagination (limit/offset) or all_results=True for complete list. """ # Input validation if not database_name or not database_name.strip(): return _format_error_response("Database name cannot be empty") client = _create_client() if isinstance(client, dict): return client try: # First, verify that the database exists database = client.get_database(database_name) if not database: return _format_error_response(f"Database '{database_name}' not found") # Get tables for the database tables = client.get_tables( database_name, limit=limit, offset=offset, all_results=all_results ) if verbose: # Return full table details return { "database": database_name, "tables": [table.model_dump() for table in tables], } else: # Return only table names return { "database": database_name, "tables": [table.name for table in tables], } except (ValueError, requests.RequestException) as e: return _format_error_response( f"Failed to retrieve tables from database '{database_name}': {str(e)}" ) except Exception as e: return _format_error_response( f"Unexpected error while retrieving tables from database " f"'{database_name}': {str(e)}" )
- td_mcp_server/mcp_impl.py:231-231 (registration)The @mcp.tool() decorator registers the td_list_tables function as an MCP tool in the FastMCP server.@mcp.tool()
- td_mcp_server/mcp_impl.py:232-238 (schema)Input schema defined by function parameters: required database_name (str), optional verbose (bool), limit (int=30), offset (int=0), all_results (bool=False). Output: dict[str, Any] with 'database' and 'tables'.async def td_list_tables( database_name: str, verbose: bool = False, limit: int = DEFAULT_LIMIT, offset: int = 0, all_results: bool = False, ) -> dict[str, Any]: