Skip to main content
Glama
DeepaRajareddy

Redshift MCP Server

redshift_query

Execute SQL queries on Amazon Redshift databases to retrieve data in JSON format for analysis and reporting purposes.

Instructions

Execute a SQL query on Redshift and return results as JSON.

Args:
    sql: The SQL query to execute

Returns:
    JSON string of the query results or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'redshift_query' tool. It executes the provided SQL query on a Redshift (or local Postgres) database using pandas.read_sql and returns the results as a formatted JSON string. Includes error handling.
    def redshift_query(sql: str) -> str:
        """
        Execute a SQL query on Redshift and return results as JSON.
        
        Args:
            sql: The SQL query to execute
        
        Returns:
            JSON string of the query results or error message
        """
        try:
            with get_connection() as conn:
                df = pd.read_sql(sql, conn)
                return df.to_json(orient="records", indent=2)
        except Exception as e:
            return f"Error executing query: {str(e)}"
  • Supporting helper function used by redshift_query to establish a database connection, supporting both Redshift and local Postgres for testing.
    def get_connection():
        """Create a connection to Redshift or local Postgres."""
        try:
            # If host is localhost and port is 5432, assume local Postgres for testing
            if REDSHIFT_HOST == "localhost" and REDSHIFT_PORT == 5432:
                import psycopg2
                return psycopg2.connect(
                    host=REDSHIFT_HOST,
                    port=REDSHIFT_PORT,
                    database=REDSHIFT_DATABASE,
                    user=REDSHIFT_USER,
                    password=REDSHIFT_PASSWORD
                )
            else:
                return redshift_connector.connect(
                    host=REDSHIFT_HOST,
                    port=REDSHIFT_PORT,
                    database=REDSHIFT_DATABASE,
                    user=REDSHIFT_USER,
                    password=REDSHIFT_PASSWORD
                )
        except Exception as e:
            logger.error(f"Connection error: {e}")
            raise
  • The @mcp.tool() decorator registers the redshift_query function as an MCP tool.
    def redshift_query(sql: str) -> str:
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. It states the tool executes a SQL query and returns results or errors, but lacks details on permissions needed, rate limits, query timeouts, transaction handling, or data modification effects (e.g., whether it can perform INSERT/UPDATE). For a database query tool with zero annotation coverage, this is a significant gap in transparency.

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 appropriately sized and front-loaded, with the core purpose in the first sentence and additional details in a structured format (Args and Returns sections). There's no wasted text, though the structure could be more integrated (e.g., merging into prose). It efficiently conveys key information in three sentences.

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 tool's complexity (executing arbitrary SQL on Redshift), the description is moderately complete. It covers the basic action and output, and an output schema exists (though not provided here), reducing the need to detail return values. However, with no annotations and incomplete behavioral details, it lacks context on safety, performance, and integration with sibling tools, leaving gaps 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 description adds minimal semantic context for the single parameter 'sql', stating it's 'The SQL query to execute.' The input schema has 0% description coverage, so this provides basic meaning. However, it doesn't elaborate on SQL syntax requirements, supported Redshift features, or parameterization options. With one parameter and low schema coverage, the description compensates slightly but not fully.

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 states the tool's purpose: 'Execute a SQL query on Redshift and return results as JSON.' It specifies the verb (execute), resource (SQL query on Redshift), and output format (JSON). However, it doesn't explicitly differentiate from sibling tools like redshift_describe_table or redshift_get_sample_data, which might also execute queries but for specific purposes.

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. It doesn't mention sibling tools like redshift_describe_table for metadata queries or redshift_get_sample_data for data sampling, nor does it specify prerequisites such as requiring an active Redshift connection or appropriate permissions. Usage is implied only by the general purpose.

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/DeepaRajareddy/redshift_mcp_server'

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