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

MCPg - Production-grade PostgreSQL MCP Server

Cross table similarity

cross_table_similarity
Read-only

Find the k most similar rows in a target table to a source row by matching pgvector embeddings across tables, enabling entity resolution and linking with dimension checks.

Instructions

Find the k rows in target_schema.target_table most similar to a specific row in source_schema.source_table. Locates the source row via source_id_column = source_id_value, reads its embedding from source_embedding_column, then issues a pgvector k-NN query against target_embedding_column. Both columns must be vector(N) of the same N — verified from the catalog up front so a mismatch fails with a clear error rather than a cast error. Useful for entity-resolution / linking across tables whose embeddings come from different models but share a dimension. Returns source_embedding_found=false when no row matches the id value. Reports available=false if pgvector 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": {
      "source_schema": "<source_schema>",
      "source_table": "<source_table>",
      "source_embedding_column": "<source_embedding_column>",
      "source_id_column": "<source_id_column>",
      "source_id_value": "<source_id_value>",
      "target_schema": "<target_schema>",
      "target_table": "<target_table>",
      "target_embedding_column": "<target_embedding_column>"
    },
    "name": "cross_table_similarity"
  }
}

Input Schema

NameRequiredDescriptionDefault
kNo
metricNol2
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.
source_tableYes
target_tableYes
source_schemaYes
target_schemaYes
source_id_valueYes
source_id_columnYes
source_embedding_columnYes
target_embedding_columnYes

Output Schema

NameRequiredDescriptionDefault
matchesYes
availableYes
source_dimensionYes
source_embedding_foundYes

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
Behavior5/5

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

Well beyond the readOnlyHint/openWorldHint annotations, it discloses the internal sequence (locate source row by id, read embedding, issue k-NN against target), the up-front dimension validation that converts a silent cast error into a clear failure, and the two sentinel outcomes (source_embedding_found=false, available=false when pgvector is missing). That is exactly the failure-mode information an agent needs.

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?

The primary action is front-loaded in the first sentence and each subsequent sentence adds a distinct, non-redundant fact: mechanism, validation guarantee, intended use, and return flags. No filler or restatement of the title.

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 an 11-parameter tool with an output schema, the description covers the workflow, the dimension precondition, and the noteworthy return flags. The remaining gap is the distance-metric parameter and its allowed values, which an agent must still guess at.

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 9%, so the description must carry parameter meaning, and it does explain the role of source_id_column, source_id_value, source_embedding_column, target_embedding_column and both schema/table pairs through the narrative. However, `metric` is never mentioned and no supported values are given, and `k` is only implied by "the k rows" with no note that it defaults to 10.

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?

"Find the k rows in target_schema.target_table most similar to a specific row in source_schema.source_table" gives a concrete verb, both resources, and the direction of the join. The description then names the exact mechanism (id lookup, embedding read, pgvector k-NN), which separates it from siblings like vector_search or mmr_search that operate within a single table.

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 states the intended use case explicitly: "Useful for entity-resolution / linking across tables whose embeddings come from different models but share a dimension." That gives a clear context for reaching for this tool, but it never names an alternative tool or says when not to use it (e.g. same-table search should go to vector_search).

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