Skip to main content
Glama
stinkgen

Trino MCP Server

by stinkgen

cancel_query

Stop a running query in Trino by providing its query ID to manage query execution and optimize resource usage.

Instructions

    Cancel a running query.
    
    Args:
        query_id: ID of the query to cancel.
        
    Returns:
        Dict[str, Any]: Result of the cancellation operation.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_idYes

Implementation Reference

  • MCP tool handler for cancel_query: calls TrinoClient.cancel_query and formats response.
    def cancel_query(query_id: str) -> Dict[str, Any]:
        """
        Cancel a running query.
        
        Args:
            query_id: ID of the query to cancel.
            
        Returns:
            Dict[str, Any]: Result of the cancellation operation.
        """
        logger.info(f"Cancelling query: {query_id}")
        
        try:
            success = client.cancel_query(query_id)
            
            if success:
                return {
                    "success": True,
                    "message": f"Query {query_id} cancelled successfully"
                }
            else:
                return {
                    "success": False,
                    "message": f"Failed to cancel query {query_id}"
                }
        
        except Exception as e:
            error_msg = str(e)
            logger.error(f"Query cancellation failed: {error_msg}")
            return {
                "success": False,
                "error": error_msg,
                "query_id": query_id
            }
  • Registration of Trino tools (including cancel_query) via register_trino_tools call during app lifespan.
    register_trino_resources(mcp, trino_client)
    register_trino_tools(mcp, trino_client)
  • TrinoClient helper method implementing query cancellation via Trino system procedure.
    def cancel_query(self, query_id: str) -> bool:
        """
        Cancel a running query.
        
        Args:
            query_id: The ID of the query to cancel.
            
        Returns:
            bool: True if the query was successfully canceled, False otherwise.
        """
        self.ensure_connection()
        
        try:
            # Use system procedures to cancel the query
            self.execute_query(f"CALL system.runtime.kill_query(query_id => '{query_id}')")
            return True
        except Exception as e:
            logger.error(f"Failed to cancel query {query_id}: {e}")
            return False
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/stinkgen/trino_mcp'

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