Skip to main content
Glama
andyWang1688

sql-query-mcp

cancel_query

Cancel a running asynchronous query by providing its query ID.

Instructions

Cancel a running asynchronous query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_idYes

Implementation Reference

  • The core handler method on AsyncQueryService that cancels a running query: sets job.status=CANCELLED, invokes the stored cancel_callback (if any), logs audit, and returns the updated job info.
    def cancel_query(self, query_id: str) -> Dict[str, object]:
        started = time.perf_counter()
        try:
            cancel_callback = None
            with self._lock:
                job = self._get_job_locked(query_id)
                if job.status == RUNNING:
                    job.status = CANCELLED
                    job.updated_at = time.time()
                    cancel_callback = job.cancel_callback
                    job.cancel_callback = None
                result: Dict[str, object] = {
                    "query_id": job.query_id,
                    "connection_id": job.connection_id,
                    "engine": job.engine,
                    "status": job.status,
                }
            cancel_error = None
            if cancel_callback is not None:
                try:
                    cancel_callback()
                except Exception as exc:
                    cancel_error = sanitize_error_message(str(exc))
            self._audit.log(
                tool="cancel_query",
                connection_id=job.connection_id,
                success=True,
                duration_ms=_elapsed_ms(started),
                sql_summary=job.sql_summary,
                extra={
                    "engine": job.engine,
                    "status": job.status,
                    "cancel_error": cancel_error,
                },
            )
            return result
        except Exception as exc:
            sanitized = sanitize_error_message(str(exc))
            self._audit.log(
                tool="cancel_query",
                connection_id=None,
                success=False,
                duration_ms=_elapsed_ms(started),
                error=sanitized,
                extra={"query_id": query_id},
            )
            if isinstance(exc, QueryExecutionError):
                raise
            raise QueryExecutionError(sanitized) from exc
  • Registers 'cancel_query' as an MCP tool via @mcp.tool() decorator in the FastMCP app, delegating to AsyncQueryService.cancel_query.
    @mcp.tool()
    def cancel_query(query_id: str) -> dict:
        """Cancel a running asynchronous query."""
    
        return _run_tool(lambda: async_queries.cancel_query(query_id))
  • Helper that builds the cancel callback for a job by checking adapter.cancel_query, cursor.cancel, conn.cancel, or conn.close in priority order.
    def _build_cancel_callback(adapter: Any, conn: Any, cursor: Any) -> Optional[Callable[[], None]]:
        if hasattr(adapter, "cancel_query"):
            return lambda: adapter.cancel_query(conn, cursor)
        if hasattr(cursor, "cancel"):
            return cursor.cancel
        if hasattr(conn, "cancel"):
            return conn.cancel
        if hasattr(conn, "close"):
            return conn.close
        return None
  • Data class for async query job state, including 'cancel_callback' field used by cancel_query to store the driver-level cancellation function.
    @dataclass
    class _AsyncQueryJob:
        query_id: str
        connection_id: str
        engine: str
        sql_text: str
        sql_summary: str
        applied_limit: int
        status: str = RUNNING
        active: bool = True
        columns: List[str] = field(default_factory=list)
        rows: List[object] = field(default_factory=list)
        row_count: int = 0
        truncated: bool = False
        duration_ms: Optional[int] = None
        error: Optional[str] = None
        created_at: float = field(default_factory=time.time)
        updated_at: float = field(default_factory=time.time)
        cancel_callback: Optional[Callable[[], None]] = None
Behavior2/5

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

With no annotations, the description must convey behavioral traits. It only states that it cancels a running query, but fails to mention side effects, authorization needs, or error conditions (e.g., trying to cancel a completed query).

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 sentence with no wasted words. It is appropriately sized for the tool's simplicity, though it could be slightly more detailed 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 the lack of annotations and output schema, the description is too minimal. It doesn't clarify the cancellation effect, return value, or constraints, leaving significant gaps for an agent to use correctly.

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

Parameters1/5

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

The input schema has one required parameter (query_id) with no description in the schema (0% coverage). The tool description adds no additional meaning beyond the parameter name, leaving the agent without guidance on how to obtain or format the query_id.

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 ('cancel') and the resource ('a running asynchronous query'). It effectively communicates the tool's purpose and distinguishes it from query-related sibling tools like start_query or run_select.

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 provided on when to use this tool versus alternatives, nor are there any prerequisites or exclusions mentioned. For instance, it doesn't specify whether the query must be in a particular state or what happens if it's already completed.

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/andyWang1688/sql-query-mcp'

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