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

MCPg - Production-grade PostgreSQL MCP Server

PG search run

pg_search_run
Read-only

Run a BM25 keyword search against a pg_search-indexed table to retrieve ranked ids, scores, and optional highlighted snippets, with results limited to one column or the whole index.

Instructions

Run a BM25 keyword search against a pg_search-indexed table. Returns hits as {id, score, snippets} where id is the value of the caller-supplied key_field and score is pdb.score(t). columns=None searches the whole index; columns=["col"] restricts to a single text field. Multi-column search needs the pdb.parse per-field config JSON and is deferred to a follow-up phase. return_snippets=True requires snippet_field and projects pdb.snippets over that column. Requires the pg_search extension. SECURITY: snippet_start_tag / snippet_end_tag are not sanitized (they pass through to upstream as-is). The defaults match pg_search's HTML defaults; if callers forward untrusted values and a downstream consumer renders snippets as HTML, that's an XSS vector — output escaping is the renderer's responsibility.

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>",
      "query": "<query>",
      "key_field": "<key_field>",
      "limit": "<limit>"
    },
    "name": "pg_search_run"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitYes
queryYes
tableYes
schemaYes
columnsNo
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.
key_fieldYes
snippet_fieldNo
return_snippetsNo
snippet_end_tagNo</b>
snippet_start_tagNo<b>
snippet_max_num_charsNo

Output Schema

NameRequiredDescriptionDefault
resultYes

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, so the safety profile is covered; the description adds real value beyond that with an unsanitized snippet-tag/XSS warning and the downstream-rendering responsibility note. It also discloses the extension dependency and the deferred multi-column phase, which are behavioral facts not present in any structured field.

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?

Purpose is front-loaded in the first sentence, then return shape, then parameter scoping, then security. The security caveat is long but each clause adds an actionable fact (no sanitization, HTML default match, renderer's responsibility); only minor trimming is possible.

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 12-parameter search tool with an output schema, this covers the essentials: return shape, scoring source, column scoping, snippet wiring, extension prerequisite, and the security caveat. Gaps remain around limit behavior and result ordering, but nothing that would cause a wrong invocation.

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 8%, so the description carries most of the burden; it does explain the trickiest parameters well (columns semantics, return_snippets requiring snippet_field, key_field determining the returned id, snippet tag defaults). It is silent on limit, query syntax, and table/schema semantics, leaving several of the 12 parameters under-described.

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?

Names a specific verb and resource: 'Run a BM25 keyword search against a pg_search-indexed table.' This distinguishes it from siblings such as full_text_search, fuzzy_search, hybrid_bm25_vector_search, and pg_search_more_like_this, since BM25 scoring over a pg_search index is a precise scope an agent can match.

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?

The description gives useful preconditions ('Requires the pg_search extension') and a scoping rule ('columns=None searches the whole index'), plus an explicit exclusion that multi-column search is not yet supported. It stops short of routing guidance: nothing says when to prefer this over full_text_search, hybrid_bm25_vector_search, or pg_search_more_like_this.

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