- 開発技術
Amazon Redshift MCP Serverを使ってRedshiftでText-to-SQLを試す
- #MCP Server
- #Redshift
- #AWS
- #AI

はじめに
【エンジニア募集中】フルリモート可◎、売上/従業員数9年連続UP、平均残業8時間、有給取得率90%、年休124日以上 etc. 詳細はこちらから>
AWS MCP Servers( https://github.com/awslabs/mcp )では、AWSサービス向けのさまざまなMCPサーバが公開されています。ここではその中のRedshift MCP Serverを用い、RedshiftでText-to-SQLを試してみます。
インストール&設定
Cursor、VSCodeのワンクリックインストールを使う場合は、リポジトリのREADME「Installation and Setup」に従えば構築できます。
今回はCursor、VSCodeを使用しないため、以下の手順で構築を行いました。
1.uvをインストール
公式手順: https://docs.astral.sh/uv/getting-started/installation/
2.uvを用いて、Python 3.10以上をインストール
uv python install 3.10
3.Redshift MCP Serverのソースを取得
awslabs/mcpリポジトリ内のsrc/redshift-mcp-serverディレクトリを取得
https://github.com/awslabs/mcp
4.IAMユーザを作成
以下の権限を付与したIAMユーザを作成し、アクセスキーを取得
※Resourceは環境に合わせて絞り込み推奨
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "redshift:DescribeClusters", "redshift:GetClusterCredentialsWithIAM", "redshift-serverless:ListWorkgroups", "redshift-serverless:GetWorkgroup", "redshift-data:ExecuteStatement", "redshift-data:BatchExecuteStatement", "redshift-data:DescribeStatement", "redshift-data:GetStatementResult" ], "Resource": "*" } ] } |
5..envを作成
redshift-mcp-server下に.envを作成し、IAMユーザのアクセスキー等を記載
1 2 3 4 5 6 |
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx AWS_REGION=ap-northeast-1 # ログレベル: DEBUG/INFO/WARNING/ERROR FASTMCP_LOG_LEVEL=INFO |
6.依存パッケージをインストール
redshift-mcp-server直下で uv sync コマンドを実行
C:\mcp\redshift-mcp-server> uv sync
7.MCPサーバを実行
C:\mcp\redshift-mcp-server> uv run --env-file .env python awslabs\redshift_mcp_server\server.py
Streamable HTTPの設定
Redshift MCP Serverは現在stdioのみ対応しているため、Streamable HTTPを使用したい場合、awslabs\redshift_mcp_server\server.py
のmcp.run()を次のように修正します。
1 2 3 4 |
def main(): """Run the MCP server with CLI argument support.""" - mcp.run() + mcp.run(transport="streamable-http") |
Text-to-SQL実行
エージェントにMCPを接続し、事前に用意したusersテーブルのユーザ数を問い合わせました。正確な回答が得られています。
1 2 3 |
> ユーザ数を教えてください > sample_dbスキーマには111人のユーザが登録されています。 |
MCPサーバ側のログ(一部抜粋)は以下のとおりで、list_clusters → list_databases → list_schemas → list_tables → execute_queryの順にツールが呼ばれていることがわかります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
INFO | __main__:list_clusters_tool:148 - Discovering Redshift clusters and serverless workgroups INFO | __main__:list_clusters_tool:157 - Successfully retrieved 1 clusters INFO | __main__:list_databases_tool:223 - Discovering databases on cluster: dev-sample INFO | __main__:list_databases_tool:232 - Successfully retrieved 6 databases from cluster dev-sample INFO | __main__:list_schemas_tool:304 - Discovering schemas in database sample_database on cluster dev-sample INFO | __main__:list_schemas_tool:315 - Successfully retrieved 1 schemas from database sample_database on cluster dev-sample INFO | __main__:list_tables_tool:395 - Discovering tables in schema sample_schema in database sample_database on cluster dev-sample INFO | __main__:list_tables_tool:408 - Successfully retrieved 1 tables from schema sample_schema in database sample_database on cluster dev-sample INFO | __main__:execute_query_tool:598 - Executing query on cluster dev-sample in database sample_database INFO | __main__:execute_query_tool:613 - Successfully executed query on cluster dev-sample: 1 rows returned in 3240ms |
※一部抜粋
おわりに
Redshift MCP Serverを使えば、エージェントから手軽にRedshiftへText-to-SQLを試せることが分かりました。
awslabs/mcpリポジトリにはRedshift MCP Server以外にも多様なMCPサーバが公開されています。要件に合うものを組み合わせると活用の幅が一気に広がるので、ぜひリポジトリを覗いて気になるサーバを試してみてください。
【エンジニア募集中】フルリモートも◎(リモート率85.7%)、平均残業8時間、年休124日以上、有給取得率90% etc. 詳細はこちらから>