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

MCPg - Production-grade PostgreSQL MCP Server

Cluster vectors

cluster_vectors
Read-only

Run k-means clustering on a pgvector embedding column to group similar vectors, returning cluster centroids and per-row assignments with distances for analysis.

Instructions

k-means cluster a pgvector column. Samples up to sample_size (default 5000) non-NULL rows of schema.table.embedding_column, runs Lloyd's algorithm with k-means++ seeding (seed for determinism), and returns centroids (one per cluster, with size) + assignments (per-row cluster index + distance). When id_column is set each assignment carries that column's value; otherwise the row's positional sample index. metric='l2' (default — squared Euclidean) or 'cosine' (vectors normalised; centroids re-normalised every iteration). k >= 2 and there must be at least 2k parseable rows. Reports available=false if pgvector is not installed.

Example: cluster_vectors(schema='public', table='docs', embedding_column='embedding', k=8, metric='cosine')

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>",
      "embedding_column": "<embedding_column>",
      "k": "<k>"
    },
    "name": "cluster_vectors"
  }
}

Input Schema

NameRequiredDescriptionDefault
kYes
seedNo
tableYes
metricNol2
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.
id_columnNo
sample_sizeNo
max_iterationsNo
embedding_columnYes

Output Schema

NameRequiredDescriptionDefault
metricYes
inertiaYes
availableYes
centroidsYes
convergedYes
dimensionYes
iterationsYes
assignmentsYes
sampled_rowsYes

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

A3.9/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, and the description still adds substantial context: sampling cap of sample_size non-NULL rows, k-means++ seeding with seed for determinism, per-iteration re-normalisation under cosine, and a graceful available=false path. It stops short of describing cost/latency or iteration behaviour at the max-iterations cutoff.

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 the core operation, then mechanics, then constraints, then a runnable example. Dense but almost every clause adds operational meaning; the parenthetical defaults are slightly redundant with the schema but serve as a quick reference.

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 10-parameter analytical tool with an output schema present, the description covers the essential mechanics, metric semantics, constraints and failure mode. The one real hole is max_iterations, which affects runtime and result quality but is never described.

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 only 10%, so the description carries most of the burden and does well for sample_size (default 5000), seed, metric ('l2' squared Euclidean vs 'cosine' normalised), k (>= 2) and id_column (assignment identity vs positional sample index). However max_iterations is never mentioned and the sampling/failure semantics of the remaining params are thin, so it only partly compensates for a 10% coverage 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?

States a specific verb and resource: 'k-means cluster a pgvector column' on schema.table.embedding_column. An agent can tell this apart from retrieval siblings like vector_search or diagnostic siblings like detect_vector_outliers without opening 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 Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied rather than stated: it covers preconditions (pgvector required, k >= 2, at least 2k parseable rows, available=false otherwise) which tells the agent when it will fail, but never says when to pick this over sibling tools such as analyze_distance_metric or detect_vector_outliers. No explicit when-to-use/when-not guidance.

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