Skip to main content
Glama
K02D

MCP Tabular Data Analysis Server

by K02D

query_sqlite

Execute SQL queries on SQLite databases to retrieve and analyze tabular data, supporting SELECT operations with configurable row limits for data exploration.

Instructions

Execute a SQL query on a SQLite database.

Args:
    db_path: Path to SQLite database file
    query: SQL query to execute (SELECT queries only for safety)
    limit: Maximum number of rows to return (default 100)

Returns:
    Dictionary containing:
    - query: The executed query
    - row_count: Number of rows returned
    - columns: List of column names
    - rows: Query results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
db_pathYes
queryYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'query_sqlite' MCP tool. It executes SELECT queries on a SQLite database, adds a LIMIT if not present, returns results as JSON-friendly dict with columns and rows. Includes safety checks for SELECT only and file existence. Uses pandas for query execution and _resolve_path helper.
    @mcp.tool()
    def query_sqlite(
        db_path: str,
        query: str,
        limit: int = 100,
    ) -> dict[str, Any]:
        """
        Execute a SQL query on a SQLite database.
        
        Args:
            db_path: Path to SQLite database file
            query: SQL query to execute (SELECT queries only for safety)
            limit: Maximum number of rows to return (default 100)
        
        Returns:
            Dictionary containing:
            - query: The executed query
            - row_count: Number of rows returned
            - columns: List of column names
            - rows: Query results
        """
        # Basic safety check - only allow SELECT
        query_upper = query.strip().upper()
        if not query_upper.startswith("SELECT"):
            raise ValueError("Only SELECT queries are allowed for safety")
        
        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:
            # Add LIMIT if not present
            if "LIMIT" not in query_upper:
                query = f"{query.rstrip(';')} LIMIT {limit}"
            
            df = pd.read_sql_query(query, conn)
            
            return {
                "query": query,
                "row_count": len(df),
                "columns": df.columns.tolist(),
                "rows": df.to_dict(orient="records"),
            }
        finally:
            conn.close()
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates safety constraints ('SELECT queries only for safety'), default behavior ('limit: default 100'), and the return structure. It lacks details on error handling or performance limits, but covers essential operational traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by organized sections for arguments and returns. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (SQL execution with safety constraints), no annotations, and a detailed output schema (implied by the Returns section), the description is complete. It covers purpose, usage guidelines, parameters, and return values, providing all necessary context for correct tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains each parameter's purpose: 'db_path' as the database file path, 'query' as the SQL to execute with safety restrictions, and 'limit' as a maximum row return with a default value. This fully compensates for the schema's lack of documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a SQL query') and resource ('on a SQLite database'), distinguishing it from sibling tools like 'list_tables' or 'describe_dataset' which perform different data operations. It precisely defines the tool's function without ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context by specifying 'SELECT queries only for safety,' which implicitly guides usage toward read-only operations. However, it does not explicitly mention when to use alternatives like 'filter_rows' or 'group_aggregate' for non-SQL operations, nor does it state exclusions for other query types.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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