Skip to main content
Glama
barkya28

pg-inspect-mcp

by barkya28

pg-inspect-mcp

A read-only Postgres schema-inspection MCP server. Point an MCP client (Claude Desktop, Claude Code, or anything speaking MCP) at a database and explore schemas, tables, indexes, sizes, sample data and query plans in natural language.

Design principle: impossible, not forbidden

Most "read-only" AI database tools are read-only because a prompt says so. That is a warning label, not a constraint — prompt injection or model error walks straight through it.

This server enforces read-only access structurally, in two independent layers, neither of which trusts the model:

  1. The connection itself is read-only. Every connection is opened with default_transaction_read_only=on, so Postgres rejects any write — even one that somehow reaches the database.

  2. A SQL guard rejects writes before the database sees them. Free-form input (only accepted by explain_query) must be a single SELECT/WITH statement; stacked statements, writing CTEs, and DDL/DML keywords are refused. All identifier inputs are validated against a strict pattern and quoted with psycopg.sql.Identifier.

No amount of clever input produces a write, because no code path can perform one.

Related MCP server: PostgreSQL MCP Server

Tools

Tool

What it does

list_schemas

Non-system schemas

list_tables

Tables/views in a schema with estimated row counts

describe_table

Columns, types, nullability, defaults

list_indexes

Index definitions

table_stats

On-disk size, index size, live/dead tuples, last vacuum/analyze

sample_rows

Up to 50 sample rows

explain_query

EXPLAIN (FORMAT JSON) for a SELECT/WITH query — plan only, never executed

Setup

pip install -e .
export DATABASE_URL=postgresql://user:pass@host:5432/dbname
pg-inspect-mcp

For extra safety in shared environments, connect as a Postgres role that has only SELECT grants — then the least-privilege credential is a third independent layer.

Claude Desktop / Claude Code config

{
  "mcpServers": {
    "pg-inspect": {
      "command": "pg-inspect-mcp",
      "env": { "DATABASE_URL": "postgresql://user:pass@host:5432/dbname" }
    }
  }
}

Local database for development

docker compose up -d
export DATABASE_URL=postgresql://postgres:postgres@localhost:5433/postgres

Tests

The safety layer is the point of the server, so it is what gets tested:

pip install pytest && pytest

Covers identifier injection shapes, stacked statements, writing CTEs (WITH x AS (DELETE ...)), EXPLAIN DELETE, COPY, and the read-only connection option.

Failure modes considered

  • Prompt injection via table contents — sampled rows may contain hostile text; the guard doesn't care what the model wants, only what the connection can do.

  • Writing CTEsWITH x AS (DELETE ... RETURNING *) is valid SQL that begins with an allowed keyword; explicitly rejected.

  • EXPLAIN ANALYZE — actually executes the query; this server only ever issues plain EXPLAIN.

  • Stacked statementsSELECT 1; DELETE ... refused before parsing.

License

MIT

Available Tools

7 tools
describe_tableA

Show columns, types, nullability and defaults for a table.

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYes
schemaNopublic

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior3/5

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

No annotations are provided, so the description carries the burden of behavioral disclosure. 'Show' implies a read-only introspection operation, but the description does not explicitly state side-effect-free behavior, error handling for missing tables, or schema resolution behavior. It is minimally transparent but not misleading.

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 description is a single front-loaded sentence that names the action and the specific output fields. Every word earns its place and there is no redundant or vague content.

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 simple read-only metadata tool with an output schema present, the description is nearly complete for invocation: the agent knows what the tool returns and can infer the required table parameter. It lacks guidance on optional schema handling and sibling-tool differentiation, but those are not blockers for a correct basic call.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description only says 'for a table,' giving partial meaning to the table parameter. It does not explain the optional schema parameter or its default value. The parameter names are self-explanatory, which prevents a score of 1, but the description does not compensate for the lack of schema-level documentation.

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 begins with 'Show columns, types, nullability and defaults for a table,' which names a specific verb and resource. This clearly differentiates the tool from siblings like list_tables or list_indexes by describing exactly what kind of metadata it returns.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives such as list_tables, list_indexes, or table_stats. There are no explicit conditions, exclusions, or workflow hints, leaving the agent to infer usage from the tool name and sibling list.

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

explain_queryA

Return the JSON query plan (EXPLAIN, no execution) for a SELECT/WITH query.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

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

No annotations are provided, so the description carries the burden. It discloses the most important behavioral trait: the query is not executed, only explained. It also states the output is a JSON plan and limits input to SELECT/WITH queries, which is meaningful behavioral context.

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?

One compact sentence conveys the action, the output format, the non-execution guarantee, and the accepted query type. There is no filler or redundant restating of the tool name.

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 one-parameter tool with an output schema available, the description is complete: it states what input is accepted, what behavior to expect (EXPLAIN only), and what output is returned. No critical information is missing for correct invocation.

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?

Schema description coverage is 0%, so the description must compensate. It does by identifying the single parameter as a SELECT/WITH query for which the plan is returned. This gives the parameter functional meaning beyond the bare schema type 'string'.

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 uses a specific verb ('Return') and a concrete resource ('JSON query plan'), and explicitly notes 'EXPLAIN, no execution' for 'SELECT/WITH' queries. This clearly distinguishes the tool from schema/table inspection siblings like describe_table or list_tables.

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 gives clear context: use this to get an EXPLAIN plan without executing the query, and it is scoped to SELECT/WITH queries. It does not explicitly name alternative tools or exclusions, but the sibling set is different enough that the intended use is reasonably clear.

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

list_indexesB

List indexes on a table with their definitions.

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYes
schemaNopublic

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior3/5

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

No annotations are present, so the description carries the transparency burden. 'List' implies a read-only operation and 'with their definitions' indicates return content, but permissions, error behavior, and schema resolution are not disclosed.

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?

One short, front-loaded sentence with no filler. The verb, target, and output content are all conveyed efficiently.

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?

The tool is simple and has an output schema, but the description omits guidance on the optional schema parameter and does not orient the agent among the sibling tools. It is minimally viable but leaves clear gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description only references 'table' generically. It does not explain the 'schema' parameter, its default of 'public', or how table/schema qualification works, so the description fails to compensate for the missing parameter documentation.

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 uses a specific verb ('List') and resource ('indexes on a table'), and explicitly states that definitions are included. This clearly differentiates it from siblings like list_schemas, list_tables, and table_stats.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

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

The description gives no guidance on when to use this tool versus alternatives such as describe_table or explain_query. It only states the action, leaving the agent to infer the appropriate invocation context.

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

list_schemasA

List non-system schemas in the connected database.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.3/5.0
Behavior4/5

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

With no annotations, the description carries the behavioral disclosure burden. It clearly discloses that system schemas are excluded and that the scope is the connected database, which is valuable filtering/scope behavior. For a read-only listing operation, this is sufficient transparency.

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 description is a single, front-loaded sentence with no wasted words. Every element adds meaning: the action, the filtering behavior, and the connection scope.

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 zero-parameter, read-only listing tool with an output schema, the description is complete. An agent knows exactly what to invoke and what to expect at a conceptual level; the output schema covers the return structure.

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?

The tool has zero parameters, so the description has no parameter semantics to explain. The baseline of 4 applies, and the description correctly adds no unnecessary parameter 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 uses a specific verb ('List') and a clear resource ('non-system schemas in the connected database'), making the tool's function immediately obvious. It also differentiates from sibling tools like list_tables and list_indexes by targeting schemas rather than tables or indexes.

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 implies when to use the tool: when a list of non-system schemas is needed. However, it provides no explicit guidance about when to prefer this over sibling tools, nor any mention of typical workflows such as discovering schemas before listing tables.

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

list_tablesA

List tables and views in a schema, with estimated row counts.

ParametersJSON Schema
NameRequiredDescriptionDefault
schemaNopublic

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.9/5.0
Behavior3/5

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

There are no annotations, so the description carries the full burden. It communicates a read-only action and the 'estimated' nature of row counts, but it does not mention any other behavioral traits such as permission requirements, default schema behavior, or limitations. This is adequate but not rich.

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 description is one compact, front-loaded sentence with no padding. It conveys the core operation and a valuable detail in minimal words.

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 simple, single-parameter listing tool with an output schema present, the description is nearly complete. It could benefit from a brief note about the default schema or an explicit read-only statement, but the essential usage context is covered.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description adds little meaning beyond the schema: it mentions 'a schema' without explaining the parameter's allowed values, default, or required behavior. The schema's 'default: public' provides more actionable information than the description does.

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 states a specific verb ('List'), a concrete resource ('tables and views in a schema'), and an informative detail ('estimated row counts'). It is clearly distinct from sibling tools like list_schemas, describe_table, and list_indexes, which target different resources or operations.

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 gives clear context: use this tool when you want tables or views in a schema. It does not explicitly contrast with alternatives, but the resource scope is narrow enough that an agent can infer the appropriate use case without confusion.

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

sample_rowsA

Fetch up to 50 sample rows from a table.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
tableYes
schemaNopublic

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior2/5

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

No annotations are provided, so the description carries full burden. It discloses a 50-row cap but does not explain whether rows are random, first N, or otherwise ordered, or whether there are any side effects or permissions. For a data-fetching operation, the sampling behavior is crucial for accurate expectations.

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?

A single, front-loaded sentence that states the action, object, and a key constraint. Every word earns its place and there is no redundancy.

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?

The tool is simple and an output schema exists, so return shape is covered. However, the lack of parameter explanations and sampling behavior leaves minor gaps, and there is no usage differentiation from siblings. Still, an agent could likely call it correctly for a basic preview task.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaning for 'table' and implicitly for 'limit' via 'up to 50', but does not mention the 'schema' parameter or explain the relationship between 'limit' and its default value. The description does not fully cover the parameter set.

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 uses a specific verb ('Fetch') and resource ('sample rows from a table'), and clearly conveys that it retrieves table data rather than metadata, distinguishing it from siblings like list_tables and table_stats. The 'up to 50' constraint adds important scope information.

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 implies a clear context: use when you need a quick preview of actual rows from a table. It does not explicitly mention when not to use it or name alternatives, but the niche is evident from the tool name and description.

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

table_statsB

Table size on disk, index size, and live/dead tuple estimates.

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYes
schemaNopublic

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.1/5.0
Behavior3/5

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

With no annotations, the description carries the burden of behavioral disclosure. It honestly says 'estimates' for live/dead tuples, which is a useful caveat, and the metrics list clarifies what the tool returns. However, it does not mention permissions, whether the operation is read-only, or any cost/performance considerations.

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 description is a single compact phrase with no filler or redundant wording. Every word contributes to understanding what the tool returns, and the most important information is front-loaded.

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?

Given the low complexity and presence of an output schema, the description names the key metrics and is minimally sufficient for invocation. However, it lacks usage context and does not explain parameter formats, leaving an agent with only partial guidance for selecting and calling the tool confidently.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for the lack of parameter documentation. The word 'Table' in the description gestures at the table parameter, but it adds no meaning about table qualification, naming format, or how the schema parameter interacts, beyond what the schema already exposes.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the resource (table) and the specific metrics returned: disk size, index size, and live/dead tuple estimates. This distinguishes it from siblings like list_tables or describe_table, though it does not explicitly name the sibling it is not.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

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

No guidance is given about when to use this tool versus alternatives such as describe_table, list_indexes, or explain_query. The intended use is implied by the name and metrics, but no explicit context or exclusions are provided.

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

TDQS

A3.8/5.0
Disambiguation5/5

Each tool targets a distinct aspect of database inspection: schemas, tables, table structure, indexes, table statistics, sample data, and query plans. There is minimal overlap between them, and an agent can easily select the right tool based on the task.

Naming Consistency4/5

The names mostly follow a consistent verb_noun pattern (list_schemas, list_tables, describe_table, list_indexes, sample_rows, explain_query). table_stats breaks the pattern slightly, being noun_noun rather than verb_noun, but it is still readable and predictable.

Tool Count5/5

Seven tools is well-scoped for a PostgreSQL inspection server. Each tool serves a clear purpose without unnecessary redundancy, and the count fits comfortably within the ideal range.

Completeness4/5

The tool surface covers the primary inspection workflow: discovering schemas/tables, examining columns, viewing indexes, retrieving table statistics, sampling rows, and explaining queries. Minor gaps like constraint/foreign key information or listing database objects beyond tables exist, but they are not critical for basic inspection.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • -
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables secure read-only interactions with PostgreSQL databases through natural language. Provides database inspection, table listing, and SQL query execution with built-in security validation.
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.
    121
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables secure read-only access to PostgreSQL databases, allowing users to list tables, query schemas, execute SELECT statements, and inspect table structures through natural language interactions.
    751
    4
    MIT

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/barkya28/pg-inspect-mcp'

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