list_tables
Retrieve table names and schemas from a SQLite database to understand its structure before analysis.
Instructions
List all tables in a SQLite database.
Args:
db_path: Path to SQLite database file
Returns:
Dictionary containing table names and their schemas
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| db_path | Yes |
Implementation Reference
- src/mcp_tabular/server.py:432-487 (handler)The @mcp.tool()-decorated function implementing the list_tables tool. Connects to SQLite DB, queries sqlite_master for table names, fetches PRAGMA table_info for schema and COUNT(*) for row counts per table.@mcp.tool() def list_tables(db_path: str) -> dict[str, Any]: """ List all tables in a SQLite database. Args: db_path: Path to SQLite database file Returns: Dictionary containing table names and their schemas """ path = _resolve_path(db_path) if not path.exists(): raise FileNotFoundError( f"Database not found: {db_path}\n" f"Resolved to: {path}\n" f"Project root: {_PROJECT_ROOT}" ) conn = sqlite3.connect(str(path)) try: # Get table names tables = pd.read_sql_query( "SELECT name FROM sqlite_master WHERE type='table'", conn ) result = {"tables": {}} for table_name in tables["name"]: # Get schema for each table schema = pd.read_sql_query( f"PRAGMA table_info({table_name})", conn ) # Get row count count = pd.read_sql_query( f"SELECT COUNT(*) as cnt FROM {table_name}", conn ).iloc[0]["cnt"] result["tables"][table_name] = { "row_count": int(count), "columns": [ { "name": row["name"], "type": row["type"], "nullable": not row["notnull"], "primary_key": bool(row["pk"]), } for _, row in schema.iterrows() ] } return result finally: conn.close()