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

MCPg - Production-grade PostgreSQL MCP Server

MMR search

mmr_search
Read-only

Ranks vector-search candidates with Maximal Marginal Relevance to return relevant, non-duplicate rows for richer LLM context; tune relevance versus diversity with lambda_mult.

Instructions

Diversity-aware vector search: fetch fetch_k nearest candidates by pgvector distance, then re-rank with Maximal Marginal Relevance to return k rows that are relevant but not near-duplicates — better LLM context than raw top-k. lambda_mult in [0,1] trades relevance (1.0) for diversity (0.0); default 0.5. Relevance + diversity are cosine similarities computed over candidate embeddings, so the result is independent of the recall-pass metric. Each hit carries its relevance, mmr_score, and selection rank. Reports available=false if the pgvector extension is not installed.

Example: mmr_search(schema='public', table='docs', column='embedding', query_vector=[0.1, ...], k=10, lambda_mult=0.5)

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>",
      "query_vector": "<query_vector>"
    },
    "name": "mmr_search"
  }
}

Input Schema

NameRequiredDescriptionDefault
kNo
tableYes
columnYes
metricNol2
schemaYes
fetch_kNo
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.
lambda_multNo
query_vectorYes

Output Schema

NameRequiredDescriptionDefault
matchesYes
availableYes

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.4/5.0
Behavior4/5

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

Beyond the readOnlyHint/openWorldHint annotations, it discloses the two-stage execution (fetch_k recall pass, then rerank), the degradation path ('available=false if the pgvector extension is not installed'), and what each hit contains (relevance, mmr_score, selection rank). The one notable gap is that it does not explain the fetch_k default or any cost/latency implication of a large recall pass.

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?

It is front-loaded with the core mechanic and the lambda_mult tradeoff, and the conditional-failure note plus worked example both earn their place. The sentences are long and multi-clause, so the metric-independence point is easy to skim past, but there is no filler.

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?

For a 9-parameter algorithmic search tool with an output schema, the description covers the pipeline, the tuning knob, the failure mode, and the result shape, leaving only minor dimension-matching detail unstated. Anything an agent needs to call it correctly is either here or in the schema.

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?

With only 11% schema description coverage (only `database` is documented), the description carries the burden and does it well: it defines fetch_k's role, k's role, lambda_mult's range, endpoints and default, and clarifies that the reported relevance/diversity are cosine-based so the `metric` argument does not affect scoring. It does not add anything about `schema`/`table`/`column`/`query_vector` dimensions-matching, which is the most likely source of invocation error.

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 states a specific verb and resource ('Diversity-aware vector search' with MMR re-ranking) and immediately contrasts it with 'raw top-k', which is what the sibling vector_search does. An agent can tell which of the several vector-search siblings to pick without inspecting any schema.

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 a clear selection rationale ('better LLM context than raw top-k') and explains how to steer behaviour via lambda_mult, which is effectively usage guidance. It never explicitly names vector_search or hybrid_search as the alternative or says when NOT to use MMR, so this falls short of a full when/when-not treatment.

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