Redshift MCP Server

Redshift MCP Server

A secure, read-only MCP server for Amazon Redshift that enables AI assistants to discover, query, and export data through natural language via 10 specialized tools, with schema allowlisting and row limits for safety.

Category
访问服务器

README

Redshift MCP Server

This MCP (Model Context Protocol) server provides secure, read-only access to Amazon Redshift databases for use with Claude Desktop and other MCP-compatible clients. It acts as an intelligent bridge, empowering AI assistants to independently navigate, understand, and extract insights directly from your data warehouse.

✨ Key Features

  • 10 Specialized Tools: A full suite of tools for data discovery, metadata extraction, querying, and exporting.
  • Dynamic Configuration: Fully configurable via .env (allowlists, row limits, connection parameters).
  • Transport Modes: Supports both stdio (for local clients like Claude Desktop) and sse (Server-Sent Events over HTTP for remote connections).
  • Connection Caching: Efficient connection management with single long-lived health-checked connections to Redshift.
  • Enterprise Security:
    • Strictly read-only SQL validation.
    • Schema allowlisting (restricts AI to pre-approved schemas).
    • Hard caps on query and export row counts to protect database performance.
  • SSH Tunnel Support: Connects seamlessly to private VPC Redshift clusters via an integrated sshtunnel.

🛠️ MCP Tools Available

Data Discovery & Navigation

  1. get_allowed_schemas: Return the server's schema access configuration (allowlist, default schema, limits).
  2. list_schemas: Discover accessible schemas in the database (filtered by the configured allowlist).
  3. list_tables: List all tables in a schema. Only schemas in the allowlist are accessible.
  4. describe_table: Get column names, data types, nullability, and defaults for a table.
  5. search_columns: Search for columns whose name matches a keyword (case-insensitive) across all tables in allowed schemas.

Data Analysis & Extraction

  1. sample_data: Return a quick sample of rows from a table for data exploration.
  2. table_row_count: Get the exact row count for a table using COUNT(*).
  3. query_data: Run a read-only SELECT query. Automatically wraps and limits results based on server configuration.
  4. explain_query: Show the EXPLAIN plan for a query to understand performance before executing.
  5. export_to_csv: Export query results to CSV format with a higher dedicated row limit (MAX_EXPORT_ROWS).

🚀 Setup & Installation

1. Install Dependencies

# Clone the repository
git clone <repository-url>
cd redshift-mcp-server

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

2. Configure Environment

Copy the example environment file and edit with your credentials:

cp .env.example .env

Edit the .env file to configure your Redshift connection and server limits:

# --- Redshift Connection ---
RS_HOST=your-cluster.region.redshift.amazonaws.com
RS_DB=your_database_name
RS_USER=your_readonly_user
RS_PASS=your_password
RS_PORT=5439

# --- Security & Limits ---
ALLOWED_SCHEMAS=gold_capsaai,report_capsaai
DEFAULT_SCHEMA=gold_capsaai
MAX_ROWS=500
MAX_EXPORT_ROWS=5000

# --- SSH Tunnel (For Private VPCs) ---
SSH_TUNNEL=false
# If true, provide SSH_HOST, SSH_USER, SSH_KEY_FILE, etc.

3. Start the Server

Mode 1: stdio (Default) Best when the MCP Client (e.g. Claude Desktop) is running on the same machine.

python server.py

Mode 2: sse (HTTP) Best for accessing the server remotely via HTTP or tunnels.

# Start SSE on port 8000
python server.py --sse --host 0.0.0.0 --port 8000

🔌 Connecting to the Server

Option A: Local Claude Desktop (stdio)

If your Claude Desktop is running on the same machine as the server, edit your Claude Desktop configuration file:

  • Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "redshift": {
      "command": "/absolute/path/to/redshift-mcp-server/.venv/bin/python",
      "args": ["/absolute/path/to/redshift-mcp-server/server.py"]
    }
  }
}

Option B: Remote Connection (SSE + IDE)

If the server is running on a remote EC2 instance, start the server in --sse mode.

For IDEs that support direct SSE connections (like VS Code with Cline):

  1. Add a new MCP server.
  2. Set transport type to SSE.
  3. Use the URL: http://<EC2-IP>:8000/sse (or your tunnel URL).

🧪 Testing & Validation

The repository includes a comprehensive testing suite and diagnostic tools:

  • client.py: A CLI client that runs an end-to-end smoke test against all 10 tools.
  • test_connection.py: Basic connectivity validation.
  • test_restricted_access.py: Ensures schema security restrictions are working properly.
  • monitor_mcp.sh: Production-ready monitoring with auto-restart, health checks, and logging.

🏗️ Architecture

graph TB
    subgraph "Client Layer"
        CD["Claude Desktop / MCP Client"]
    end
    
    subgraph "MCP Server Layer"
        MCP["FastMCP Server"]
        CONFIG["config.py / .env"]
        VALIDATION["SQL & Schema Validation"]
    end
    
    subgraph "Network Layer"  
        SSH["SSH Tunnel<br/>(Optional)"]
        CONN["Connection Cache"]
    end
    
    subgraph "Database Layer"
        RS["Amazon Redshift"]
        SCHEMA["Allowed Schemas"]
    end
    
    CD -->|"JSON-RPC (stdio/sse)"| MCP
    MCP --> CONFIG
    MCP --> VALIDATION
    VALIDATION --> CONN
    CONN --> SSH
    SSH --> RS
    RS --> SCHEMA

🔐 Security Considerations

  • Read-Only: The _validate_read_only_sql wrapper severely restricts queries to SELECT and EXPLAIN statements.
  • Limits Engine: Double LIMIT syntax bugs are prevented through regex parsing in _apply_limit, guaranteeing large table scans are capped at your .env threshold.
  • Schema Isolation: The AI cannot view or query tables outside the ALLOWED_SCHEMAS comma-separated list.
  • Keep Credentials Safe: Never commit your .env or .json configuration files to version control. They are ignored in .gitignore by default.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选