Skip to main content
Glama
avantifellows

Avanti Fellows PostgreSQL MCP Server

Official

count_rows

Count rows in PostgreSQL tables for Avanti Fellows database, with optional filtering using WHERE clauses to analyze data volume.

Instructions

Count rows in a table, optionally with a WHERE clause.

Args:
    table_name: Name of the table
    schema_name: Schema name (default: public)
    where: Optional WHERE clause (without 'WHERE' keyword)

Returns:
    JSON with count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
schema_nameNopublic
whereNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'count_rows' MCP tool. It is registered via the @mcp.tool() decorator. Constructs and executes a safe COUNT(*) query on the specified table, optionally with a validated WHERE clause, and returns the row count as JSON.
    @mcp.tool()
    async def count_rows(table_name: str, schema_name: str = "public", where: str = None) -> str:
        """Count rows in a table, optionally with a WHERE clause.
    
        Args:
            table_name: Name of the table
            schema_name: Schema name (default: public)
            where: Optional WHERE clause (without 'WHERE' keyword)
    
        Returns:
            JSON with count
        """
        sql = f'SELECT COUNT(*) as count FROM "{schema_name}"."{table_name}"'
    
        if where:
            # Basic validation - only allow read operations in WHERE
            if not is_read_only(f"SELECT * FROM t WHERE {where}"):
                return json.dumps({"error": "Invalid WHERE clause"})
            sql += f" WHERE {where}"
    
        try:
            async with get_connection() as conn:
                row = await conn.fetchrow(sql)
                return json.dumps({"count": row["count"]})
        except Exception as e:
            return json.dumps({"error": str(e)})
Behavior3/5

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

With no annotations provided, the description carries full burden. It states the basic operation and return format ('JSON with count'), but doesn't disclose permissions needed, rate limits, error conditions, or whether it's a read-only operation (though implied by 'Count').

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?

Perfectly structured: purpose statement first, then Args and Returns sections. Every sentence earns its place with no wasted words. The formatting makes it easy to scan.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no annotations, but has output schema), the description is mostly complete. It covers parameters well and mentions the return format. However, it lacks behavioral context like permissions or limitations that would be helpful for a database tool.

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 compensate. It clearly explains all 3 parameters: table_name, schema_name (with default), and where (with syntax guidance 'without WHERE keyword'). This adds significant value beyond the bare schema.

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?

The description clearly states the specific action ('Count rows') and resource ('in a table'), with optional filtering via WHERE clause. It distinguishes from siblings like query (which returns data) and list_tables (which lists tables).

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?

The description implies usage for counting rows with optional filtering, but doesn't explicitly state when to use this vs. alternatives like query (which could also count) or describe_table (for metadata). No explicit exclusions or prerequisites are mentioned.

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/avantifellows/mcp-postgres'

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