Skip to main content
Glama
MCPg - Production-grade PostgreSQL MCP Server

MCPg - Production-grade PostgreSQL MCP Server

Analyze distance metric

analyze_distance_metric
Read-only

Recommends the right pgvector distance metric (cosine, l2, or inner_product) for a table column by sampling embeddings and analyzing their magnitude distribution, returning the metric plus rationale and stats.

Instructions

Recommend a pgvector distance metric (cosine | l2 | inner_product) from the embedding-magnitude distribution. Samples up to sample_size non-NULL rows of schema.table.column, computes each embedding's L2 norm, and applies a small heuristic: pre-normalised (CV < 5% and mean ≈ 1.0) → inner_product; nearly-constant magnitude but not unit-norm → cosine (same ranking as L2, safer default); variable magnitude → cosine (normalises out heterogeneous sources). Returns the metric + a rationale + the underlying distribution stats. Reports available=false if the pgvector extension is not installed.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "schema": "<schema>",
      "table": "<table>",
      "column": "<column>"
    },
    "name": "analyze_distance_metric"
  }
}

Input Schema

NameRequiredDescriptionDefault
tableYes
columnYes
schemaYes
databaseNoOptional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected.
sample_sizeNo

Output Schema

NameRequiredDescriptionDefault
availableYes
rationaleYes
magnitude_cvYes
sampled_rowsYes
magnitude_stdYes
mean_magnitudeYes
pre_normalisedYes
recommended_metricYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.4
    • changedInput schema / properties / database / description
      Previous value: -"Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids."New value: +"Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected."
  2. First observedv0.6.8

TDQS

A4.7/5.0
Behavior5/5

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

Annotations only declare readOnlyHint and openWorldHint; the description adds substantial behavior on top: it samples at most sample_size non-NULL rows, computes L2 norms, applies a named heuristic, and returns metric + rationale + distribution stats. It also discloses a degradation path ('Reports available=false if the pgvector extension is not installed'), which is exactly the kind of operational detail annotations cannot convey.

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 opening clause front-loads purpose, then mechanism, heuristic branches, return shape, and failure mode follow in a logical order with no filler sentences. The parenthetical heuristic chains are dense but every clause carries decision-relevant information, so the slight density is acceptable.

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?

An output schema exists, so return values did not need spelling out, yet the description still names the payload (metric + rationale + distribution stats). Combined with sampling behavior and the pgvector-unavailable case, an agent has everything needed to call this correctly and interpret the result.

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 coverage is only 20%, so the description must compensate, and it does: it explains that schema.table.column identifies the embedding column being profiled and that sample_size bounds the number of non-NULL rows sampled. The only gap is the optional 'database' parameter, which the schema itself already documents well.

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 opens with a specific verb and resource ('Recommend a pgvector distance metric') and immediately enumerates the three candidate metrics, so the agent knows exactly what comes back. This is clearly distinguishable from neighboring tools such as tune_vector_index or analyze_hnsw_recall, which tune indexes rather than choose a metric.

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?

It gives clear decision criteria for the metric choice itself (CV < 5% and mean ≈ 1.0 → inner_product; near-constant magnitude → cosine; variable magnitude → cosine), which is real guidance on the outcome. However, it never states when to reach for this tool versus siblings like tune_vector_index, vector_recall_at_k, or recommend_vector_quantization, nor any prerequisite such as the column being of type vector.

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

Deploy Server

Other Tools