Skip to main content
Glama
santosh07401

Redshift MCP Server

by santosh07401

redshift_query

Execute SQL queries on Amazon Redshift databases to retrieve data as JSON results for analysis and reporting.

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 core handler function for the 'redshift_query' MCP tool, decorated with @mcp.tool(). Executes the provided SQL query on a Redshift (or local Postgres) database using pandas.read_sql_query via a connection from get_connection(), converts results to JSON with orient='records', and returns it. Catches exceptions and returns an error message.
    @mcp.tool()
    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)}"
  • Helper function 'get_connection()' used by redshift_query and other tools to establish a connection to Redshift using redshift_connector or psycopg2 for local 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
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions that results are returned as JSON and errors are handled, it lacks critical behavioral details like authentication requirements, query timeout limits, result size constraints, whether queries are read-only or can modify data, or any rate limiting considerations.

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 with three clear sentences that each serve a purpose: stating the action, describing the parameter, and explaining the return. It's front-loaded with the core functionality. The only minor improvement would be integrating the parameter description more seamlessly rather than using 'Args:' formatting.

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 (database query execution), lack of annotations, and presence of an output schema, the description is minimally adequate. The output schema existence means the description doesn't need to detail return values, but it should provide more behavioral context about query execution constraints and safety considerations for a database operation.

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?

Schema description coverage is 0%, so the description must compensate. It provides basic semantic information about the single parameter ('The SQL query to execute'), which adds meaning beyond the bare schema. However, it doesn't elaborate on SQL dialect specifics, query validation, or parameter binding capabilities that would be helpful for proper usage.

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 clearly states the specific action ('Execute a SQL query on Redshift') and resource ('Redshift'), distinguishing it from sibling tools like redshift_list_tables or redshift_describe_table. It provides a complete verb+resource+scope statement that leaves no ambiguity about what this tool does.

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 like redshift_get_sample_data or redshift_describe_table. There's no mention of prerequisites, appropriate query types, or limitations that would help an agent choose between this and other data retrieval 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/santosh07401/redshift-mcp-server'

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