Skip to main content
Glama
truaxki
by truaxki

read_query

Execute SELECT queries on a SQLite database that logs statistical variations in conversation structure and unusual events for analysis.

Instructions

Execute a SELECT query on the SQLite database

            Schema Reference:
            Table: chat_monitoring
            Fields:
            - log_id (INTEGER PRIMARY KEY)
            - timestamp (DATETIME)
            - session_id (TEXT)
            - user_id (TEXT)
            - interaction_type (TEXT)
            - probability_class (TEXT: HIGH, MEDIUM, LOW)
            - message_content (TEXT)
            - response_content (TEXT)
            - context_summary (TEXT)
            - reasoning (TEXT)

            Example:
            SELECT timestamp, probability_class, context_summary 
            FROM chat_monitoring 
            WHERE probability_class = 'LOW'
            LIMIT 5;
            

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSELECT SQL query to execute

Implementation Reference

  • Handler logic for the 'read_query' tool within the @server.call_tool() dispatcher. Validates the presence and SELECT prefix of the query argument, executes it via the database helper, and returns the results as TextContent.
    elif name == "read_query":
        if not arguments or "query" not in arguments:
            raise ValueError("Missing query argument")
        query = arguments["query"].strip()
        if not query.upper().startswith("SELECT"):
            raise ValueError("Only SELECT queries are allowed")
        results = db._execute_query(query)
        return [types.TextContent(type="text", text=str(results))]
  • JSON schema defining the input for the 'read_query' tool: an object with a required 'query' string property.
    inputSchema={
        "type": "object",
        "properties": {
            "query": {
                "type": "string",
                "description": "SELECT SQL query to execute"
            }
        },
        "required": ["query"]
    }
  • Registration of the 'read_query' tool returned by the @server.list_tools() handler, including name, detailed description with schema reference, and input schema.
    types.Tool(
        name="read_query",
        description="""Execute a SELECT query on the SQLite database
    
            Schema Reference:
            Table: chat_monitoring
            Fields:
            - log_id (INTEGER PRIMARY KEY)
            - timestamp (DATETIME)
            - session_id (TEXT)
            - user_id (TEXT)
            - interaction_type (TEXT)
            - probability_class (TEXT: HIGH, MEDIUM, LOW)
            - message_content (TEXT)
            - response_content (TEXT)
            - context_summary (TEXT)
            - reasoning (TEXT)
    
            Example:
            SELECT timestamp, probability_class, context_summary 
            FROM chat_monitoring 
            WHERE probability_class = 'LOW'
            LIMIT 5;
            """,
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "SELECT SQL query to execute"
                }
            },
            "required": ["query"]
        }
    ),
  • Private helper method of LogDatabase class that executes arbitrary SQL queries (read or write), handles parameters, commits writes, and returns results as list of dictionaries. Used by read_query and other tools.
    def _execute_query(self, query: str, params: dict[str, Any] | None = None) -> list[dict[str, Any]]:
        """Execute a SQL query and return results as a list of dictionaries"""
        logger.debug(f"Executing query: {query}")
        try:
            with closing(sqlite3.connect(self.db_path)) as conn:
                conn.row_factory = sqlite3.Row
                with closing(conn.cursor()) as cursor:
                    if params:
                        cursor.execute(query, params)
                    else:
                        cursor.execute(query)
    
                    if query.strip().upper().startswith(('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'ALTER')):
                        conn.commit()
                        affected = cursor.rowcount
                        logger.debug(f"Write query affected {affected} rows")
                        return [{"affected_rows": affected}]
    
                    results = [dict(row) for row in cursor.fetchall()]
                    logger.debug(f"Read query returned {len(results)} rows")
                    return results
        except Exception as e:
            logger.error(f"Database error executing query: {e}")
            raise
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. It discloses that this tool executes SELECT queries (implying read-only behavior), provides a detailed schema reference for the main table, and includes a concrete example showing query structure and limitations (LIMIT 5). However, it doesn't mention potential errors, performance considerations, or authentication requirements.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the core purpose. The schema reference and example are useful additions, though the example could be more concise. Every sentence earns its place by providing necessary context for query construction.

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

Completeness4/5

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

Given the tool's complexity (executing arbitrary SELECT queries), no annotations, and no output schema, the description does well by providing a detailed table schema and example. However, it lacks information about return format, error handling, or query limitations beyond the example, leaving some gaps for a tool with significant behavioral implications.

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

Parameters3/5

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

Schema description coverage is 100% (the single parameter 'query' is fully described in the schema as 'SELECT SQL query to execute'), so the baseline is 3. The description adds value by providing a schema reference and example query that clarifies what constitutes a valid query, but doesn't add syntax or format details beyond what the schema implies.

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 SELECT query') and resource ('on the SQLite database'), distinguishing it from sibling tools like write_query (which presumably handles writes) and list_tables/describe_table (which handle metadata). The description explicitly mentions SELECT queries, which helps differentiate from other database operations.

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

Usage Guidelines3/5

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

The description implies usage through the example (showing a SELECT query on the chat_monitoring table), but doesn't explicitly state when to use this tool versus alternatives like read-logs or log-query (which might be for specific log access). There's no guidance on prerequisites, error conditions, or explicit exclusions.

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/truaxki/mcp-variance-log'

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