Skip to main content
Glama
Moonlight-CL

Redshift MCP Server

by Moonlight-CL

execute_sql

Execute SQL queries on Amazon Redshift databases to retrieve, analyze, or modify data directly from AI assistants.

Instructions

Execute a SQL Query on the Redshift cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL to Execute

Implementation Reference

  • The @server.call_tool() decorator registers this as the tool handler. It dispatches based on the tool name. For 'execute_sql', it retrieves the 'sql' parameter from args, validates it, connects to Redshift using config from env vars, executes the SQL, fetches results if query returns columns, formats as CSV-like text, and returns as TextContent. Handles errors and closes connection.
    @server.call_tool()
    async def call_tool(name: str, args: dict) -> list[TextContent]:
        """Execute SQL"""
        config=get_redshift_config()
        sql = ''
    
        if name == "execute_sql":
            sql = args.get("sql")
            if not sql:
                raise ValueError("sql parameter is required when calling execute_sql tool")
        elif name == "analyze_table":
            schema = args.get("schema")
            table = args.get("table")
            if not all([schema, table]):
                raise ValueError("'schema' and 'table' parameters are required when calling analyze_table tool")
            sql = f"ANALYZE {schema}.{table}"
        elif name == "get_execution_plan":
            sql = args.get("sql")
            if not sql:
                raise ValueError("sql parameter is required when calling get_query_plan tool")
            sql = f"EXPLAIN {sql}"
    
        try:
            conn = redshift_connector.connect(
                host=config['host'],
                port=int(config['port']),
                user=config['user'],
                password=config['password'],
                database=config['database'],
            )
            conn.autocommit = True
    
            with conn.cursor() as cursor:
                cursor.execute(sql)
                if name == "analyze_table":
                    return [TextContent(type="text", text=f"Successfully analyzed table {schema}.{table}")]
    
                if cursor.description is None:
                    return [TextContent(type="text", text=f"Successfully execute sql {sql}")]
    
                columns = [desc[0] for desc in cursor.description]
                rows = cursor.fetchall()
                result = [",".join(map(str, row)) for row in rows]
                return [TextContent(type="text", text="\n".join([",".join(columns)] +  result ))]
        except Exception as e:
            return [TextContent(type="text", text=f"Error executing query: {str(e)}")]
        finally:
            conn.close()
  • Pydantic-like JSON schema for 'execute_sql' tool input, defining an object with a required 'sql' string property.
    inputSchema={
        "type": "object",
        "properties": {
            "sql": {
                "type": "string",
                "description": "The SQL to Execute"
            }
        },
        "required": ["sql"]
    }
  • The Tool object registration for 'execute_sql' returned by @server.list_tools(), including name, description, and input schema.
    Tool(
        name="execute_sql",
        description="Execute a SQL Query on the Redshift cluster",
        inputSchema={
            "type": "object",
            "properties": {
                "sql": {
                    "type": "string",
                    "description": "The SQL to Execute"
                }
            },
            "required": ["sql"]
        }
    ),
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It doesn't address critical aspects such as whether the query is read-only or mutating data, authentication needs, rate limits, error handling, or the format of results. The description merely states what the tool does without revealing operational traits.

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 a single, efficient sentence that directly conveys the tool's function without unnecessary words. It is front-loaded with the core action and resource, making it easy to understand at a glance. Every part of the sentence earns its place by defining the tool's purpose clearly.

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?

For a tool that executes SQL queries with no annotations and no output schema, the description is insufficient. It lacks details on behavioral aspects like data mutation risks, result formats, error conditions, and usage constraints. Given the complexity of SQL execution and the absence of structured data to compensate, the description does not provide enough context for safe and effective use.

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, with the 'sql' parameter documented as 'The SQL to Execute'. The description adds no additional meaning beyond this, such as SQL dialect specifics, query length limits, or supported operations. Given the high schema coverage, a baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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 action ('Execute a SQL Query') and target resource ('on the Redshift cluster'), making the purpose unambiguous. It distinguishes from siblings like 'analyze_table' and 'get_execution_plan' by focusing on direct query execution rather than analysis or planning operations.

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?

No explicit guidance is provided on when to use this tool versus alternatives. While the description implies it's for executing SQL queries, it doesn't specify scenarios where 'analyze_table' or 'get_execution_plan' might be more appropriate, nor does it mention prerequisites like database permissions or connection requirements.

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/Moonlight-CL/redshift-mcp-server'

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