Skip to main content
Glama
devopam

MCPg - Production-grade PostgreSQL MCP Server

Detect n plus one

detect_n_plus_one
Read-only

Identify N+1 query loops in PostgreSQL by analyzing pg_stat_statements: hundreds of calls returning few rows, sorted by total time. Thresholds tunable. Results are candidates for investigation.

Instructions

Surface query templates in pg_stat_statements that look like an N+1 loop: hundreds of calls, each returning at most a row or two, with meaningful total wall-clock time spent. Returns the candidates sorted by total time descending so the worst offender appears first. Thresholds (min_calls, max_rows_per_call, min_total_ms) are tunable. Treat results as candidates for investigation, NOT verdicts — a hot cache-miss pattern on a primary-key lookup can trip the same shape. Reports availability=false if pg_stat_statements is not installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
databaseNoOptional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids.
min_callsNo
min_total_msNo
max_rows_per_callNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
availableYes
candidatesYes
thresholdsYes
Behavior4/5

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

Annotations declare readOnlyHint=true, and description adds behavioral context: results are candidates, can trip on cache-miss patterns, and reports availability if pg_stat_statements missing. This goes beyond annotations.

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?

Two sentences plus a brief note; front-loaded with main purpose. Every sentence adds value, no waste.

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 output schema exists, description explains key output ordering and false positive risk. Covers availability flag. Adequate for a diagnostic tool with moderate complexity.

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 low (20%), with only 'database' described. The description mentions tunable thresholds and gives examples ('hundreds of calls', 'row or two') linking to parameters, but lacks detailed explanations for all parameters.

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 tool surfaces query templates resembling an N+1 loop, specifying source (pg_stat_statements), criteria (many calls, few rows, significant time), and sort order. It distinguishes from sibling analysis tools by its specific purpose.

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 guides treatment of results as 'candidates, NOT verdicts' and gives a false positive example. It mentions availability condition but does not explicitly contrast with siblings or state when not to use.

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/devopam/MCPg'

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