Skip to main content
Glama
alaturqua

MCP Trino Server

by alaturqua

execute_query

Execute SQL queries against Trino and Iceberg to retrieve data and return formatted results for analysis.

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 runs SQL queries against Trino using trino.dbapi.Cursor, fetches results, and returns them as JSON-formatted string.
    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)"
  • src/server.py:128-138 (registration)
    MCP tool registration for execute_query using the @mcp.tool decorator. This registers the tool with the MCP server, defining the external interface including the query parameter with its description.
    @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)
  • Schema definition for the execute_query tool's input parameter using Pydantic Field to provide the description for the query parameter.
    @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:
Behavior2/5

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

With no annotations provided, the description carries full burden of behavioral disclosure. It mentions 'readable format' for output but completely omits critical safety information: whether the tool supports write operations, requires specific permissions, has rate limits, or transaction boundaries. For a SQL execution tool, this is a significant gap.

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?

Extremely efficient single sentence with zero waste. Information is front-loaded with the action verb, and the length is appropriate for the simplicity of the parameter schema.

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?

Inadequate for a high-risk SQL execution tool with 20+ siblings. Despite having an output schema (excusing return value documentation), the description fails to address the tool's power and risks. Should specify read-only vs read-write capabilities, SQL dialect, or query constraints given the dangerous nature of arbitrary query execution.

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 coverage is 100% (the 'query' parameter is fully documented in the schema), establishing a baseline of 3. The description adds minimal semantic value about the parameter itself, though it implies string format via 'SQL query' reference.

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?

Clearly states the tool executes SQL queries and returns results, using specific verb ('Execute') and resource ('SQL query'). However, it fails to distinguish from sibling metadata tools like show_tables or show_catalogs, leaving ambiguity about when to use the generic query tool versus specific inspection commands.

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?

Provides no guidance on when to use this tool versus the numerous specialized show_* siblings (show_tables, show_catalogs, etc.). Missing critical safety guidance about whether this supports read-only queries or can execute destructive operations (INSERT, DELETE, DROP).

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