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

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

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