Skip to main content
Glama
foxter-io

PostgreSQL MCP Server

by foxter-io

Execute Read-Only SQL Query

pg_query
Read-only

Execute read-only SQL SELECT queries on a PostgreSQL database. Supports CTEs and EXPLAIN, with configurable row limit and timeout.

Instructions

Execute a read-only SQL SELECT query against the PostgreSQL database.

Only SELECT, WITH (CTE), TABLE, and EXPLAIN statements are allowed. Any attempt to execute INSERT, UPDATE, DELETE, DDL, or other mutating statements will be rejected.

Args:

  • sql: The SQL SELECT statement to execute (required)

  • limit: Maximum rows to return, 1-1000 (default: 100)

  • timeout_ms: Query timeout in milliseconds (default: 30000)

  • response_format: Output format

Returns: JSON: { rows: object[], row_count: number, column_names: string[] } Markdown: formatted table of results

Examples:

  • "SELECT * FROM users WHERE active = true" → rows with limit applied

  • "WITH stats AS (SELECT ...) SELECT * FROM stats" → CTE supported

  • "EXPLAIN SELECT * FROM orders" → query plan

Errors:

  • "Only read-only queries allowed" if non-SELECT statement attempted

  • PostgreSQL syntax/permission errors returned as-is

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSELECT SQL statement to execute
limitNoMaximum rows to return (default: 100, max: 1000)
timeout_msNoQuery timeout in milliseconds (default: 30000)
response_formatNoOutput format: 'markdown' for human-readable, 'json' for machine-readablemarkdown
Behavior5/5

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

Annotations already provide readOnlyHint=true. Description adds concrete constraints: allowed statements, limit bounds (1-1000), timeout (1000-300000), response formats, and error handling for disallowed queries. No contradictions.

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?

Description is well-organized with clear sections (Args, Returns, Examples, Errors). Every sentence adds value. Front-loaded with main action. Concise and to the point.

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?

Despite lacking output schema, the description comprehensively covers parameter details, allowed operations, return format, and error conditions. No missing information 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?

Schema coverage is 100% (baseline 3). Description adds value by reinforcing allowed SQL types, providing default values, adding examples, and clarifying error cases. Exceeds minimum.

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?

Title and description clearly state the tool executes read-only SQL SELECT queries. Lists allowed statement types (SELECT, WITH, TABLE, EXPLAIN) and explicitly excludes mutating statements. Distinguishes from siblings like pg_execute and pg_explain.

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?

Explicitly states when to use (read-only queries) and what statements are allowed. Implicitly guides not to use for writes. Could explicitly mention pg_execute as alternative for mutating queries, but context with siblings makes it clear.

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/foxter-io/mcp-postgresql'

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