Skip to main content
Glama

Search inside source code

pg_search_source
Read-onlyIdempotent

Search PostgreSQL function, procedure, view, materialized view, and trigger source code for text or regex patterns and return matching lines with line numbers to trace table/column usage.

Instructions

Find functions, procedures, views, materialized views and triggers whose source code contains a text, and return the matching lines with their line numbers.

Use it to answer "who uses this table or column?" in code that lives inside the database, or "where is this function called?". pattern is plain text (case insensitive); with regex=true it is a PostgreSQL regular expression. Line numbers count from the first line of a function body or view definition. Code that belongs to extensions is skipped. limit is the maximum number of objects.

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": {
      "pattern": "<pattern>"
    },
    "name": "pg_search_source"
  }
}

Input Schema

NameRequiredDescriptionDefault
kindsNo
limitNo
regexNo
schemaNo
patternYes
connectionNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4/5.0
Behavior4/5

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

Annotations already cover the safety profile (readOnly, idempotent, non-destructive, closed-world), and the description adds real behavior beyond them: matching is case-insensitive plain text unless `regex=true` switches to PostgreSQL regex syntax, line numbers are relative to each object's body/definition, and extension-owned code is excluded from results. It does not discuss cost or scan scope on large catalogs, which keeps it below a 5.

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 purpose sentence before use cases and then parameter notes, which is the right order. It is dense but every clause carries information; only the parameter notes at the end read as slightly tacked-on.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

It covers the return shape (matching lines plus line numbers) which matters with no output schema, and handles the two most-used parameters. For a six-parameter tool with zero schema descriptions, the silent `kinds`, `schema`, and `connection` parameters are a meaningful gap an agent would have to guess around.

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 0%, so the description carries the burden, and it does explain `pattern` (plain text, case insensitive), `regex` (PostgreSQL regex mode) and `limit` (maximum number of objects). It says nothing about `kinds`, `schema`, or `connection`, leaving three of six parameters with no semantics anywhere.

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 set ("Find functions, procedures, views, materialized views and triggers whose source code contains a text") and also declares the shape of the result ("matching lines with their line numbers"). This clearly separates it from a general object search like pg_search, since it searches inside stored DDL bodies rather than object names.

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?

Gives concrete motivating questions ("who uses this table or column?" and "where is this function called?") that map directly to when to reach for it. It stops short of naming an alternative or an exclusion (e.g. when to use pg_get_ddl or pg_search instead), so it is clear context rather than a full routing rule.

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