Skip to main content
Glama

execute_sql

Run SQL queries directly on the Postgres MCP server to interact with and manage databases efficiently during development, testing, and deployment.

Instructions

Execute any SQL query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlNoSQL to runall

Implementation Reference

  • The main handler function for the 'execute_sql' tool. It executes the provided SQL query using the sql_driver determined by the current access mode, returns formatted results or an error message.
    async def execute_sql(
        sql: str = Field(description="SQL to run", default="all"),
    ) -> ResponseType:
        """Executes a SQL query against the database."""
        try:
            sql_driver = await get_sql_driver()
            rows = await sql_driver.execute_query(sql)  # type: ignore
            if rows is None:
                return format_text_response("No results")
            return format_text_response(list([r.cells for r in rows]))
        except Exception as e:
            logger.error(f"Error executing query: {e}")
            return format_error_response(str(e))
  • Registers the execute_sql tool dynamically based on the access mode (unrestricted or restricted/read-only), adding it to the MCP server with an appropriate description.
    if current_access_mode == AccessMode.UNRESTRICTED:
        mcp.add_tool(execute_sql, description="Execute any SQL query")
    else:
        mcp.add_tool(execute_sql, description="Execute a read-only SQL query")
Behavior2/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 of behavioral disclosure. 'Execute any SQL query' implies a write-capable operation but doesn't specify permissions needed, whether it's read-only or can modify data, transaction handling, error behavior, or output format. The description is minimal and fails to address critical behavioral aspects for a SQL execution tool.

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 extremely concise with just three words, front-loading the core action. There's no wasted language or redundancy. For a simple tool with one parameter, this brevity is appropriate and efficient.

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

Completeness2/5

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

Given the complexity of SQL execution (potential for data mutation, security implications) and lack of annotations or output schema, the description is incomplete. It doesn't cover return values, error handling, safety warnings, or differentiation from sibling tools. For a tool that could perform destructive operations, this minimal description poses significant risks for an AI agent.

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?

The input schema has 100% description coverage for its single parameter 'sql', documented as 'SQL to run'. The description adds no additional meaning beyond this, such as SQL dialect, supported commands, or examples. With high schema coverage and only one parameter, the baseline score of 3 is appropriate as the schema adequately documents the parameter.

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

Purpose3/5

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

The description 'Execute any SQL query' states the verb ('Execute') and resource ('SQL query'), making the basic purpose clear. However, it's vague about scope and doesn't differentiate from siblings like analyze_db_health or explain_query, which also involve SQL operations. The description lacks specificity about what types of queries are supported or what database system is targeted.

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. With siblings like explain_query (for query analysis) and list_objects (for metadata retrieval), there's no indication that this is the primary tool for running arbitrary SQL commands versus more specialized tools. No prerequisites, exclusions, or context for selection are mentioned.

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

Related 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/crystaldba/postgres-mcp'

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