Skip to main content
Glama
devopam

MCPg - Production-grade PostgreSQL MCP Server

Retrieve with context

retrieve_with_context
Read-only

Retrieve rows similar to a query vector using k-NN, then expand each hit with its parent and child records via foreign keys for context-rich results.

Instructions

Context-packed k-NN retrieval (a one-shot RAG building block). Runs a pgvector k-NN against schema.table.embedding_column for a caller-supplied query_vector (no embedding model needed), then expands each hit one hop along foreign keys and returns the hit row + its related parent / child records in one object. Parents (when include_parents, default true) are the rows a hit references via outbound FKs; children (when include_children, default true) are rows referencing the hit via inbound FKs, capped at max_related (default 5) per FK. Limitations: 1 hop only; inbound (child) expansion is same-schema only. The embedding column is dropped from every returned row. Requires the vector extension. Returns available, dimension, detail, and hits (each with distance, row, and related — a list of fk_name/direction/related_schema/related_table/rows).

Example: retrieve_with_context(schema='public', table='docs', embedding_column='embedding', query_vector=[0.1, 0.2, 0.3], k=5)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kNo
tableYes
metricNol2
schemaYes
databaseNoOptional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids.
max_relatedNo
query_vectorYes
include_parentsNo
embedding_columnYes
include_childrenNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsYes
detailNo
availableYes
dimensionYes
Behavior5/5

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

The description reveals behaviors beyond annotations (readOnlyHint, openWorldHint): it explains the one-hop expansion logic, default parameter behaviors, the dropping of the embedding column, and the requirement for the vector extension. This is thorough and adds significant value.

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 description is well-structured and front-loaded with a clear summary, but it is somewhat lengthy. Every sentence adds value, though minor pruning could improve conciseness.

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 complex tool with 10 parameters and a rich output schema, the description covers the algorithm, parameter behaviors, limitations, dependency, and return structure. It provides an example and is sufficient for an agent to use the tool correctly.

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 10% schema description coverage, the description compensates well by explaining key parameters (query_vector, include_parents, include_children, max_related) and their defaults. It also provides an example. However, it does not explain optional parameters like metric or the meaning of k in detail.

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 clearly states its function as 'Context-packed k-NN retrieval (a one-shot RAG building block)' that runs vector search and expands results one hop along foreign keys. This distinguishes it from sibling tools like vector_search which likely perform plain vector search without context expansion.

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?

The description frames usage as a RAG building block and lists limitations ('1 hop only', 'inbound expansion same-schema only'), helping an agent decide when to use it. However, it does not explicitly name alternative tools or state when not to use it, leaving some ambiguity.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/devopam/MCPg'

If you have feedback or need assistance with the MCP directory API, please join our Discord server