Skip to main content
Glama
Teja-sudo

postgres-mcp-server

by Teja-sudo

execute_sql

Execute SQL queries with parameterized statements to prevent injection. Supports transactions, multiple statements, and schema hints for database management.

Instructions

Execute SQL queries. Supports SELECT, INSERT, UPDATE, DELETE (if not in readonly mode). Use $1, $2 placeholders with params array to prevent SQL injection. Use allowMultipleStatements to run multiple statements separated by semicolons. Use transactionId to run within a transaction. Optionally use server/database/schema params for one-time execution on a different server without changing the main connection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL statement(s). Use $1, $2, etc. for parameterized queries.
paramsNoParameters for $1, $2, etc. placeholders (e.g., [123, 'value']). Not supported with allowMultipleStatements.
maxRowsNoMax rows to return (default: 1000, max: 100000)
offsetNoSkip rows for pagination
allowLargeScriptNoBypass 100KB SQL limit for deployment scripts
includeSchemaHintNoInclude schema info (columns, PKs, FKs) for tables in the query.
allowMultipleStatementsNoAllow multiple SQL statements separated by semicolons. Returns results for each statement.
transactionIdNoExecute within an active transaction. Get this from begin_transaction.
maxEstimatedRowsNoSP-7 query budget: refuse to run if the planner estimates more than this many rows. Pre-EXPLAIN check on read-only queries only. Useful as a backstop for AI-generated queries.
maxEstimatedCostNoSP-7 query budget: refuse to run if the planner estimates total cost above this. Read-only queries only.
serverNoOne-time server override. Execute on this server without changing main connection. Cannot be used with transactionId.
databaseNoOne-time database override. Uses this database for execution without changing main connection.
schemaNoOne-time schema override. Sets search_path for this execution only.
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses support for different SQL types, parameterization, multiple statements, transactions, and query budget controls. However, it does not describe return format (e.g., array of objects for SELECT, affected rows for DML), error behavior, or the 100KB limit for large scripts, which are important for agent decision-making.

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 a single paragraph that is front-loaded with the core purpose and then expands on key details. It is concise but packed with information. Could benefit from bullet points or sectioning for clarity, but remains efficient.

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?

Given 13 parameters and no output schema, the description covers most behavioral aspects: parameterization, multiple statements, transactions, overrides, query budgets. It lacks explanation of return types or error handling, and could mention restrictions like server/database not usable with transactionId. Fairly complete for a complex tool.

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

Parameters5/5

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

Schema description coverage is 100%, and the description adds significant meaning beyond the schema: explains $1, $2 placeholders, incompatibility of params with allowMultipleStatements, default/max for maxRows, bypass for allowLargeScript, schema info via includeSchemaHint, SP-7 query budget for maxEstimatedRows/Cost, and one-time overrides for server/database/schema. This enriches the agent's understanding.

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?

Description clearly states it executes SQL queries with support for SELECT, INSERT, UPDATE, DELETE, parameterized queries, multiple statements, transactions, and one-time overrides. It differentiates from sibling tools like analyze, explain, and file-based executors by focusing on raw SQL execution.

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?

Provides guidance on using $1, $2 placeholders with params array to prevent SQL injection, allowMultipleStatements for multiple semicolon-separated statements, transactionId for transactional execution, and one-time server/database/schema overrides. Does not explicitly exclude alternatives but implicitly distinguishes from sibling tools.

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/Teja-sudo/postgres-mcp-server'

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