Skip to main content
Glama

cancel_query

Destructive

Stop a running PostgreSQL query by backend PID to end long-running or blocking statements. Preview with dry-run; pid and query are logged for audit.

Instructions

[WRITE][risk=high] Cancel a backend's running query (pg_cancel_backend). No inverse.

Captures the backend's pid + query for audit; a cancel has no undo. Pass
dry_run=True to preview.

Refuses this tool's own backend pid — the query it would cancel is this very
call. Enforced under dry_run too.

Args:
    pid: Backend process id (from list_activity).
    dry_run: If True, preview without cancelling.
    target: Target name from config; omit for the default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYes
targetNo
dry_runNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.7/5.0
Behavior5/5

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

Annotations already declare destructiveHint=true and idempotentHint=false, but the description adds context the annotations cannot carry: there is no undo, the pid+query are captured for audit, and the tool self-protects by refusing to cancel its own backend pid even under dry_run. That last detail is a non-obvious behavioral guardrail that directly affects whether a call succeeds.

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 risk tag and the purpose are front-loaded, and the Args block is compact with no filler. Slightly verbose in the audit/no-inverse paragraph, but every sentence conveys decision-relevant behavior.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a high-risk, non-idempotent mutation with no output schema and no annotated permission model, the description supplies everything needed: irreversibility, preview path, audit side effect, parameter sources, and the self-pid refusal. Nothing material is missing for an agent to call it correctly.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must carry the burden, and it does: pid is sourced from list_activity, dry_run is defined as a preview flag, and target is explained as a config name with omission defaulting to the default target. All three parameters are covered with meaning beyond their bare types.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource (cancel a backend's running query) plus the underlying primitive (pg_cancel_backend), which immediately separates it from terminate_backend in the sibling list. 'No inverse' pins down the semantics precisely in four words.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tells the agent when to preview (dry_run=True) and where the pid comes from (list_activity), which is real routing guidance. It does not explicitly say when to choose this over terminate_backend, so an agent must infer the query-vs-session distinction on its own.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.