Skip to main content
Glama
apache

IoTDB MCP Server

Official
by apache

read_query

Execute SELECT queries on IoTDB databases to retrieve time-series data using SQL with TABLE dialect and ISO 8601 time formatting.

Instructions

Execute a SELECT query on the IoTDB. Please use table sql_dialect when generating SQL queries.

Args: query_sql: The SQL query to execute (using TABLE dialect, time using ISO 8601 format, e.g. 2017-11-01T00:08:00.000)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_sqlYes

Implementation Reference

  • The handler function for the 'read_query' tool. It executes SELECT, DESCRIBE, or SHOW queries using IoTDB TableSessionPool in table SQL dialect and formats results using prepare_res.
    async def read_query(query_sql: str) -> list[TextContent]:
        """Execute a SELECT query on the IoTDB. Please use table sql_dialect when generating SQL queries.
    
        Args:
            query_sql: The SQL query to execute (using TABLE dialect, time using ISO 8601 format, e.g. 2017-11-01T00:08:00.000)
        """
        table_session = None
        try:
            table_session = session_pool.get_session()
            stmt = query_sql.strip().upper()
            
            # Regular SELECT queries
            if (
                stmt.startswith("SELECT")
                or stmt.startswith("DESCRIBE")
                or stmt.startswith("SHOW")
            ):
                res = table_session.execute_query_statement(query_sql)
                return prepare_res(res, table_session)
            else:
                table_session.close()
                raise ValueError("Only SELECT queries are allowed for read_query")
        except Exception as e:
            if table_session:
                table_session.close()
            logger.error(f"Failed to execute query: {str(e)}")
            raise
  • Helper function used by read_query (and other table tools) to convert query results into a list of TextContent with CSV-formatted data.
    def prepare_res(
        _res: SessionDataSet, _table_session: TableSession
    ) -> list[TextContent]:
        columns = _res.get_column_names()
        result = []
        while _res.has_next():
            row = _res.next().get_fields()
            result.append(",".join(map(str, row)))
        _table_session.close()
        return [
            TextContent(
                type="text",
                text="\n".join([",".join(columns)] + result),
            )
        ]
  • The @mcp.tool() decorator registers the read_query function as an MCP tool.
    async def read_query(query_sql: str) -> list[TextContent]:
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the SQL dialect and time format, which is useful context. However, it doesn't disclose critical behavioral traits: whether this is read-only (though implied by SELECT), authentication requirements, rate limits, error handling, result format, or pagination. For a query execution tool with zero annotation coverage, this leaves significant gaps.

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: the first sentence states the core purpose, followed by specific guidance and parameter details. The 'Args:' section is clear and adds necessary information. While efficient, it could be slightly more structured by separating usage guidelines from parameter documentation.

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

Completeness3/5

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

Given the tool's complexity (query execution with SQL), no annotations, no output schema, and 0% schema description coverage, the description is moderately complete. It covers the purpose, basic usage guidelines, and parameter semantics adequately. However, it lacks information about return values, error conditions, and behavioral constraints that would be needed for robust agent usage.

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

Parameters4/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains that 'query_sql' is 'The SQL query to execute' and provides crucial context about the TABLE dialect and ISO 8601 time format. With only one parameter and the schema providing no descriptions, the description effectively compensates by explaining the parameter's purpose and constraints.

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 tool's purpose: 'Execute a SELECT query on the IoTDB' - a specific verb (execute) and resource (SELECT query on IoTDB). It distinguishes itself from siblings like 'describe_table', 'export_table_query', and 'list_tables' by focusing on query execution rather than metadata or export operations. However, it doesn't explicitly differentiate itself from potential write operations or other query types beyond SELECT.

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 provides some usage context: 'Please use table sql_dialect when generating SQL queries' and mentions the TABLE dialect and ISO 8601 time format. However, it doesn't explicitly state when to use this tool versus alternatives like 'export_table_query' (which might handle results differently) or provide clear exclusion criteria for non-SELECT queries. The guidance is helpful but incomplete.

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/apache/iotdb-mcp-server'

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