cancel_query
Stop a running query in CockroachDB by providing its query ID to manage database performance and resource usage.
Instructions
Cancel a running query.
Args:
query_id: The query ID to cancel.
Returns:
Cancellation result.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query_id | Yes |
Implementation Reference
- src/cockroachdb_mcp/server.py:518-531 (handler)MCP tool handler for cancel_query, registered via @mcp.tool() decorator, handles errors and delegates to cluster.cancel_query implementation.@mcp.tool() async def cancel_query(query_id: str) -> dict[str, Any]: """Cancel a running query. Args: query_id: The query ID to cancel. Returns: Cancellation result. """ try: return await cluster.cancel_query(query_id) except Exception as e: return {"status": "error", "error": str(e)}
- Core helper function that executes the CANCEL QUERY SQL command on the CockroachDB connection.async def cancel_query(query_id: str) -> dict[str, Any]: """Cancel a running query. Args: query_id: The query ID to cancel. Returns: Cancellation result. """ conn = await connection_manager.ensure_connected() try: async with conn.cursor() as cur: await cur.execute(f"CANCEL QUERY '{query_id}'") return { "status": "success", "query_id": query_id, "message": "Query cancelled", } except Exception as e: return {"status": "error", "error": str(e)}