Skip to main content
Glama
startreedata

StarTree MCP Server for Apache Pinot

Official
by startreedata

read-query

Execute SELECT SQL queries on Apache Pinot databases via the StarTree MCP Server to retrieve and analyze data efficiently.

Instructions

Execute a SELECT query on the Pinot database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSELECT SQL query to execute

Implementation Reference

  • The core handler function for the 'read-query' MCP tool. It validates that the query is a SELECT statement, executes the query using the PinotClient instance, formats the results as indented JSON, and handles errors.
    @mcp.tool
    def read_query(query: str) -> str:
        """Execute a SELECT query on the Pinot database"""
        try:
            if not query.strip().upper().startswith("SELECT"):
                raise ValueError("Only SELECT queries are allowed for read-query")
            results = pinot_client.execute_query(query=query)
            return json.dumps(results, indent=2)
        except Exception as e:
            return f"Error: {str(e)}"
  • Supporting method in PinotClient that implements the actual query execution. Prefers HTTP POST to Pinot broker endpoint, with fallback to pinotdb driver. Preprocesses query and handles timeouts.
    def execute_query(
        self,
        query: str,
        params: dict[str, Any] | None = None,
    ) -> list[dict[str, Any]]:
        logger.debug(f"Executing query: {query[:100]}...")  # Log first 100 chars
    
        # Use HTTP as primary method since it works reliably with authenticated clusters
        try:
            return self.execute_query_http(query)
        except Exception as e:
            logger.warning(f"HTTP query failed: {e}, trying PinotDB fallback")
            try:
                return self.execute_query_pinotdb(query, params)
            except Exception as pinotdb_error:
                error_msg = (
                    f"Both HTTP and PinotDB queries failed. "
                    f"HTTP: {e}, PinotDB: {pinotdb_error}"
                )
                logger.error(error_msg)
                raise
  • HTTP-based query execution helper called by execute_query. Sends POST to Pinot broker /query/sql endpoint with authentication, parses resultTable into list of dicts.
    def execute_query_http(self, query: str) -> list[dict[str, Any]]:
        """Alternative query execution using HTTP requests directly to broker"""
        broker_url = f"{self.config.broker_scheme}://{self.config.broker_host}:{self.config.broker_port}/{PinotEndpoints.QUERY_SQL}"
        logger.debug(f"Executing query via HTTP: {query[:100]}...")
    
        payload = {
            "sql": query,
            "queryOptions": f"timeoutMs={self.config.query_timeout * 1000}",
        }
    
        response = self.http_request(broker_url, "POST", payload)
        result_data = response.json()
    
        # Check for query errors in response
        if "exceptions" in result_data and result_data["exceptions"]:
            raise Exception(f"Query error: {result_data['exceptions']}")
    
        # Parse the result into pandas-like format
        if "resultTable" in result_data:
            columns = result_data["resultTable"]["dataSchema"]["columnNames"]
            rows = result_data["resultTable"]["rows"]
    
            # Convert to list of dictionaries
            result = [dict(zip(columns, row)) for row in rows]
            logger.debug(f"HTTP query returned {len(result)} rows")
            return result
        else:
            logger.warning("No resultTable in response, returning empty result")
            return []
  • FastMCP decorator that registers the read_query function as an MCP tool, automatically generating schema from signature and exposing it as 'read-query'.
    @mcp.tool
  • Prompt template that describes the 'read-query' tool for the AI assistant, aiding in tool usage.
    1. read-query: Execute a SQL query on Pinot and return the results
    2. list-tables: List all available tables in Pinot
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Execute a SELECT query' implies a read-only operation, it doesn't specify permissions needed, query limitations (e.g., timeout, result size), error handling, or what the response looks like. This leaves significant gaps for a database query tool.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded with the core action.

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

Completeness2/5

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

Given no annotations, no output schema, and a database query tool that could have complex behaviors (e.g., SQL syntax, result format, error cases), the description is incomplete. It doesn't address what the tool returns, how to handle queries, or any constraints, leaving the agent with insufficient context.

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%, with the single parameter 'query' documented as 'SELECT SQL query to execute' in the schema. The description adds no additional parameter information beyond what's already in the schema, so it meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Execute') and target ('SELECT query on the Pinot database'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling query execution tools (though none are listed among siblings), keeping it from a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'list-tables' or 'table-details' that might provide related data, there's no indication of when a SELECT query is preferred over those structured retrieval methods.

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

Related 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/startreedata/mcp-pinot'

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