Skip to main content
Glama
K02D

MCP Tabular Data Analysis Server

by K02D

list_tables

Retrieve all table names and their schemas from a SQLite database file to understand its structure and available data.

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 handler function for the 'list_tables' MCP tool. It resolves the database path, connects to the SQLite database, queries sqlite_master for table names, and for each table retrieves PRAGMA table_info for schema and COUNT(*) for row count. Returns a structured dictionary with tables and their metadata.
    @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()
  • The @mcp.tool() decorator registers the list_tables function as an MCP tool with the name 'list_tables'.
    @mcp.tool()
  • Helper function used by list_tables to resolve the db_path relative to project root.
    def _resolve_path(file_path: str) -> Path: """ Resolve file path relative to project root if it's a relative path. Args: file_path: Absolute or relative file path Returns: Resolved absolute Path """ path = Path(file_path) # If absolute path, use as-is if path.is_absolute(): return path # Otherwise, resolve relative to project root resolved = _PROJECT_ROOT / path return resolved.resolve()
  • The docstring provides the input schema (db_path: str) and output format description for the tool.
    """ List all tables in a SQLite database. Args: db_path: Path to SQLite database file Returns: Dictionary containing table names and their schemas """

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