Skip to main content
Glama
alaturqua

MCP Trino Server

by alaturqua

execute_query

Execute SQL queries on Trino and Iceberg data sources and receive results in a clear, readable format.

Instructions

Execute a SQL query and return results in a readable format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to execute

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual implementation of execute_query that connects to Trino, executes the SQL, and returns results as JSON or a success message.
    def execute_query(self, query: str) -> str:
        """Execute a SQL query against Trino and return results as a formatted string.
    
        Args:
            query (str): The SQL query to execute.
            params (Optional[dict]): Dictionary of query parameters with primitive types.
    
        Returns:
            str: JSON-formatted string containing query results or success message.
        """
        cur: trino.dbapi.Cursor = self.client.cursor()
        cur.execute(query)
        if cur.description:
            return json.dumps(
                [dict(zip([col[0] for col in cur.description], row, strict=True)) for row in cur.fetchall()],
                default=str,
            )
        return "Query executed successfully (no results to display)"
  • The MCP tool handler function that registers 'execute_query' as a tool, accepting a SQL query string parameter and delegating to trino_client.execute_query.
    @mcp.tool(description="Execute a SQL query and return results in a readable format")
    def execute_query(query: str = Field(description="The SQL query to execute")) -> str:
        """Execute a SQL query and return formatted results.
    
        Args:
            query: The SQL query to execute
    
        Returns:
            str: Query results formatted as a JSON string
        """
        return client.execute_query(query)
  • src/server.py:128-138 (registration)
    Registration of the 'execute_query' tool via the @mcp.tool decorator with description 'Execute a SQL query and return results in a readable format'.
    @mcp.tool(description="Execute a SQL query and return results in a readable format")
    def execute_query(query: str = Field(description="The SQL query to execute")) -> str:
        """Execute a SQL query and return formatted results.
    
        Args:
            query: The SQL query to execute
    
        Returns:
            str: Query results formatted as a JSON string
        """
        return client.execute_query(query)
Behavior2/5

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

No annotations are provided, so the description must disclose behavioral traits. It does not specify whether the query can modify data, what happens on error, or the format of returned results. The phrase 'readable format' is vague.

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 a single, direct sentence. It is concise and front-loaded with the core action, though it could be expanded slightly without losing conciseness.

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 that an output schema exists and the single parameter is well-documented, the description is still insufficient. It lacks details on query constraints, safety (e.g., read-only vs. writable), and does not leverage the output schema to clarify return structure.

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% (one parameter with a clear description). The tool description adds no additional semantic context beyond what is already in the schema, so a baseline score of 3 is appropriate.

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 executes a SQL query and returns results, using a specific verb and resource. It distinguishes from sibling tools like 'show_tables' and 'describe_table' which are more specialized, though it does not explicitly state this distinction.

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?

No guidance is given on when to use this tool versus alternatives. Sibling tools like 'show_tables' or 'describe_table' are not mentioned, and there is no indication of recommended use cases or 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/alaturqua/mcp-trino-python'

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