Skip to main content
Glama

Count rows

count
Read-onlyIdempotent

Get the exact number of rows in a table, optionally filtered, to size a result before fetching it or answer "how many" questions.

Instructions

Return the exact number of rows in a table, optionally filtered — use it to size a result before fetching it or to answer 'how many' questions. Use query instead for grouped counts (GROUP BY) or counts over joins. Returns a single line: count: N. May be slow on very large unindexed filters (timeout from settings). On failure returns isError with 'error: ' (e.g. refused statement, unknown table, SQL error).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable or view name as returned by `tables`. PostgreSQL tables outside `public` are written schema.table.
whereNoOptional SQL boolean expression WITHOUT the WHERE keyword, e.g. status = 'paid' AND total > 100.
databaseNoOptional database to use instead of the connection's default (names from `databases`). Omit to use the default.
connectionYesConnection name exactly as returned by `connections` (e.g. "shop"). Unknown or unexposed names return an error.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.2.2
    • changedInput schema / properties / connection / description
      Previous value: -"Connection name (from `connections`)"New value: +"Connection name exactly as returned by `connections` (e.g. \"shop\"). Unknown or unexposed names return an error."
    • changedInput schema / properties / database / description
      Previous value: -"Database name to use instead of the connection's default (optional)"New value: +"Optional database to use instead of the connection's default (names from `databases`). Omit to use the default."
    • changedInput schema / properties / table / description
      Previous value: -"Table name"New value: +"Table or view name as returned by `tables`. PostgreSQL tables outside `public` are written schema.table."
    • changedInput schema / properties / where / description
      Previous value: -"SQL boolean expression without WHERE"New value: +"Optional SQL boolean expression WITHOUT the WHERE keyword, e.g. status = 'paid' AND total > 100."
  2. 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 cover the safety profile (readOnly, idempotent, non-destructive, closed-world), and the description goes further by disclosing the return format ('count: N'), a performance caveat about slow large unindexed filters with possible timeouts, and the failure contract (isError with 'error: <reason>' plus example reasons). That is genuine behavioral context beyond the structured fields.

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?

Three tight sentences with the core purpose front-loaded, followed by the sibling disambiguation and then behavioral caveats. No filler and nothing repeated from the schema.

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?

There is no output schema, but the description compensates by stating the exact return shape and the error shape, plus a performance caveat. For a read-only count tool, an agent has everything needed to call it and interpret the result.

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 description coverage is 100%, so all four parameters are already documented in the schema, including the WHERE-without-keyword convention and schema.table notation. The description adds no per-parameter syntax or default semantics beyond what the schema supplies, so the baseline 3 applies.

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 ('Return the exact number of rows in a table, optionally filtered') with an explicit scope qualifier, and names the sibling `query` as the alternative for grouped/joined counts. An agent can distinguish it from every sibling without opening the schema.

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

Usage Guidelines5/5

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

Gives two concrete use cases (sizing a result before fetching, answering 'how many' questions) and an explicit exclusion routing to `query` for GROUP BY or joins. The when-to-use and when-not-to-use are both spelled out.

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