Skip to main content
Glama

Index advisor

pg_index_advisor
Read-onlyIdempotent

Suggests indexes for missing foreign-key support and large-table sequential scans, and compares query planner costs for hypothetical CREATE INDEX commands without creating them.

Instructions

Suggest indexes. Without sql it lists foreign keys with no supporting index (which make deletes and joins on the parent scan the child table) and large tables read almost only by sequential scans, each with a ready CREATE INDEX suggestion where one is clear. With sql and hypothetical_indexes (a list of CREATE INDEX commands) it compares the planner's estimated cost of the query before and after the indexes, without creating anything: it needs the hypopg extension.

table (name, schema.name or pattern) narrows the heuristics. The query is checked by the same rules as pg_query and is never executed, only planned. Indexes speed up reads and slow down writes: add only the ones a real query needs.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "pg_index_advisor"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlNo
limitNo
tableNo
connectionNo
hypothetical_indexesNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior4/5

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

Annotations already declare readOnlyHint/idempotent/non-destructive, and the description adds real behavioral context beyond them: nothing is created ("without creating anything"), the query is "never executed, only planned," and the hypopg extension is required. It also explains what the heuristic mode actually returns (FKs lacking a supporting index, large seq-scan tables, ready CREATE INDEX suggestions). It does not say what happens if hypopg is absent, which keeps it from a 5.

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?

Front-loaded with a two-word purpose statement, then organized by mode with the prerequisite and caveat in the right places. It is dense with parentheticals ("(which make deletes and joins on the parent scan the child table)", "(name, `schema.name` or pattern)") that add meaning but make it longer than strictly needed.

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?

For a read-only advisor with no output schema and 5 undocumented parameters, the description covers the essentials: both operating modes, the extension dependency, what results look like in the heuristic path, and the safety property that nothing is executed or created. Gaps are minor — no mention of behavior when hypopg is missing or what `limit` bounds — but nothing critical to a correct call is absent.

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

Parameters4/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 parameter burden, and it explains the three non-obvious ones: `sql` (validated like pg_query, planned not executed), `hypothetical_indexes` (a list of CREATE INDEX commands), and `table` (name, `schema.name`, or pattern) including its narrowing effect on the heuristics. Only `limit` and `connection` go unmentioned, and those are largely self-evident from their defaults.

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 concrete verb+resource ("Suggest indexes") and then splits into two clearly named modes: heuristic missing-index detection when `sql` is absent, and hypothetical-index cost comparison when `sql` plus `hypothetical_indexes` are given. It also pins its relationship to a sibling by saying the query is checked by the same rules as pg_query, so an agent can distinguish it from pg_query/pg_explain without opening schemas.

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?

Gives explicit mode-selection guidance ("Without `sql` it lists...", "With `sql` and `hypothetical_indexes` it compares...") plus a prerequisite ("it needs the hypopg extension") and a caution about write overhead. It stops short of explicit exclusions — it never says when to prefer pg_index_stats or pg_explain instead — so it is clear context rather than a full routing rule.

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