Skip to main content
Glama
K02D

MCP Tabular Data Analysis Server

by K02D

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
NameRequiredDescriptionDefault
db_pathYes

Implementation Reference

  • 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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/K02D/mcp-tabular'

If you have feedback or need assistance with the MCP directory API, please join our Discord server