Redshift MCP Server

Redshift MCP Server

site icon
2025.05.08 0
Python数据库服务数据查询数据分析数据库
Redshift MCP Server 是一个基于 Python 的 Model Context Protocol (MCP) 服务器,专门用于与 Amazon Redshift 数据库进行交互。它允许 AI 助手通过 MCP 协议访问和操作 Redshift 数据库,包括列出模式和表、获取表定义脚本、执行 SQL 查询、分析表统计信息以及获取查询执行计划等功能。
View on GitHub

Overview

产品定位

Redshift MCP Server 是一个专为 Amazon Redshift 数据库设计的 MCP 服务器,旨在通过 MCP 协议为 AI 助手提供与 Redshift 数据库交互的能力。

核心功能

  • 列出数据库中的模式和表
  • 获取表的 DDL(数据定义语言)脚本
  • 获取表的统计信息
  • 执行 SQL 查询
  • 分析表以收集统计信息
  • 获取 SQL 查询的执行计划

适用场景

  • AI 助手需要与 Amazon Redshift 数据库进行交互的场景
  • 需要自动化执行 SQL 查询和分析表统计信息的场景
  • 开发人员需要快速获取数据库结构和查询执行计划的场景

工具列表及能力

  • execute_sql: 在 Redshift 集群上执行 SQL 查询
  • analyze_table: 分析表以收集统计信息
  • get_execution_plan: 获取 SQL 查询的执行计划及运行时统计信息

常见问题解答

  • 需要确保 Python 3.13 或更高版本
  • 需要配置正确的 Redshift 集群连接信息(主机、端口、用户名、密码、数据库)
  • 可选配置模式(默认为 "public")

使用教程

使用依赖

  • Python 3.13 或更高版本
  • Amazon Redshift 集群
  • Redshift 凭据(主机、端口、用户名、密码、数据库)

安装教程

# 克隆仓库
git clone https://github.com/aws-samples/sample-amazon-redshift-MCP-server.git
cd sample-amazon-redshift-MCP-server

# 安装依赖
uv sync

配置

需要设置以下环境变量以连接到 Redshift 集群:

RS_HOST=your-redshift-cluster.region.redshift.amazonaws.com
RS_PORT=5439
RS_USER=your_username
RS_PASSWORD=your_password
RS_DATABASE=your_database
RS_SCHEMA=your_schema  # 可选,默认为 "public"

启动服务器

# 启动服务器
uv run --with mcp python-dotenv redshift-connector mcp
mcp run src/redshift_mcp_server/server.py

调试方式

  • 确保环境变量正确配置
  • 检查 Redshift 集群连接是否正常
  • 使用示例命令测试服务器功能

示例

列出模式

access_mcp_resource("redshift-mcp-server", "rs:///schemas")

列出模式中的表

access_mcp_resource("redshift-mcp-server", "rs:///public/tables")

获取表 DDL

access_mcp_resource("redshift-mcp-server", "rs:///public/users/ddl")

执行 SQL

use_mcp_tool("redshift-mcp-server", "execute_sql", {"sql": "SELECT * FROM public.users LIMIT 10"})

分析表

use_mcp_tool("redshift-mcp-server", "analyze_table", {"schema": "public", "table": "users"})

获取执行计划

use_mcp_tool("redshift-mcp-server", "get_execution_plan", {"sql": "SELECT * FROM public.users WHERE user_id = 123"})

许可证

该项目遵循 MIT-0 开源许可条款,请参阅 MIT-0 了解完整条款。