Skip to main content
Glama
santosh07401

Redshift MCP Server

by santosh07401

redshift_get_sample_data

Retrieve sample rows from Amazon Redshift tables to preview data structure and content before analysis or query execution.

Instructions

Get sample rows from a table.

Args:
    table_name: Name of the table
    limit: Number of rows to return (default: 5)
    schema: Schema name (default: "public")

Returns:
    JSON sample data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
limitNo
schemaNopublic

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), defining the input schema via type hints and docstring, and implementing the logic to fetch sample data by calling redshift_query with a generated SQL query.
    @mcp.tool()
    def redshift_get_sample_data(table_name: str, limit: int = 5, schema: str = "public") -> str:
        """
        Get sample rows from a table.
        
        Args:
            table_name: Name of the table
            limit: Number of rows to return (default: 5)
            schema: Schema name (default: "public")
        
        Returns:
            JSON sample data
        """
        sql = f"SELECT * FROM {schema}.{table_name} LIMIT {limit}"
        return redshift_query(sql)
  • Supporting helper tool 'redshift_query' that executes arbitrary SQL using pandas and returns JSON, called by redshift_get_sample_data.
    @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)}"
  • Utility function to establish database connection, used indirectly by redshift_query.
    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 the full burden of behavioral disclosure. It mentions the tool returns 'JSON sample data' but doesn't specify behavioral traits such as whether this is a read-only operation, potential rate limits, authentication requirements, error handling, or how it interacts with large tables. This leaves significant gaps in understanding the tool's operational characteristics.

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 highly concise and well-structured, with a clear purpose statement followed by bullet points for arguments and returns. Every sentence earns its place by directly contributing to understanding the tool's functionality without unnecessary elaboration or redundancy.

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 moderate complexity (3 parameters, no annotations) and the presence of an output schema (which handles return values), the description is partially complete. It covers basic purpose and parameters but lacks behavioral context and usage guidelines, making it adequate for simple use but insufficient for robust agent decision-making in more complex scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema by explaining each parameter's purpose: 'table_name' as the table to sample from, 'limit' as the number of rows (with a default), and 'schema' as the schema name (with a default). Since schema description coverage is 0%, this compensates well, though it could provide more context like valid schema formats or limit constraints.

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 with a specific verb ('Get') and resource ('sample rows from a table'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'redshift_query' or 'redshift_describe_table', which could also retrieve data or metadata from tables, leaving some ambiguity about when this specific sampling function is preferred.

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_query' for custom queries or 'redshift_describe_table' for metadata. It lacks context about typical use cases (e.g., quick data inspection vs. detailed analysis) or prerequisites, leaving the agent to infer usage based on the tool name alone.

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