先ほど一般提供になった Amazon Aurora DSQL が MCP サーバーに対応しているので試してみた

先ほど一般提供になった Amazon Aurora DSQL が MCP サーバーに対応しているので試してみた

Amazon Aurora DSQL に一般提供の開始時から MCP サーバがあるので試してみました。

ウィスキー、シガー、パイプをこよなく愛する大栗です。

先ほど Amazon Aurora DSQL が一般提供になりました。AWS の公式ブログを読んでいると最後に MCP サーバが追加されたと書いているではないですか。これは試さねばとやってみました。

Aurora DSQL now provides a Model Context Protocol (MCP) server to improve developer productivity by making it easy for your generative AI models and database to interact through natural language.

https://dev.classmethod.jp/articles/amazon-aurora-dsql-generally-available/

Aurora DSQL 自体は一般提供のレポートブログをご覧下さい。

https://dev.classmethod.jp/articles/amazon-aurora-dsql-generally-available/

Amazon Aurora DSQL MCP Server

Amazon Aurora DSQL MCP Server のドキュメントは以下です。

Aurora dsql mcp server - AWS MCP Servers

特徴

Amazon Aurora DSQL MCP Server は以下の特徴があります。

  • 人間が読める質問やコマンドを構造化された PostgreSQL 互換の SQL クエリに変換して、設定された Aurora DSQL データベースへ実行します。
  • デフォルトでは読み取り専用ですが、--allow-writes でトランザクションが有効になります。
  • パフォーマンス向上の為にコネクションは再利用します。

前提条件

Amazon Aurora DSQL MCP Server を利用するには以下の前提条件があります。

  1. Aurora DSQL がある AWS アカウント
  2. この MCP サーバーは LLM クライアントと同じホストでローカルのみ実行可能
  3. AWS サービスにアクセスするための AWS 認証情報を設定する
  • 適切な権限を持つ AWS アカウントが必要
  • aws configure か環境変数で AWS 認証情報を設定

やってみた

ここでは MCP クライアントに Amazon Q Developer CLI を利用します。Amazon Q Developer CLI での MCP 設定方法はこちらのエントリを御覧ください。

また現在の Aurora DSQL のテーブル構造とデータは、このエントリーを実行した後の状態です。

Amazon Q Developer CLI では ~/.aws/amazonq/mcp.json に MCP サーバーの設定を行います。--cluster_endpoint の引数 [your dsql cluster endpoint] に対象の Aurora DSQL のエンドポイント、--region の引数 [your dsql cluster region, e.g. us-east-1] に対象 Aurora DSQL のリージョン、--database_user の引数 [your dsql username] に対象 Aurora DSQL のユーザー (通常の管理ユーザーは admin です) を設定します。

~/.aws/amazonq/mcp.json
{
  "mcpServers": {
    "awslabs.aurora-dsql-mcp-server": {
      "command": "uvx",
      "args": [
        "awslabs.aurora-dsql-mcp-server@latest",
        "--cluster_endpoint",
        "[your dsql cluster endpoint]",
        "--region",
        "[your dsql cluster region, e.g. us-east-1]",
        "--database_user",
        "[your dsql username]",
        "--profile", "default"
      ],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

q chat コマンドを実行すると awslabsaurora_dsql_mcp_server がロードされていることを確認できます。

% q chat
To learn more about MCP safety, see https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-security.html

⚠ 0 of 1 mcp servers initialized. Servers still loading:
 - awslabsaurora_dsql_mcp_server

    ⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
 ⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
 ⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
 ⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
 ⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
 ⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧

╭─────────────────────────────── Did you know? ────────────────────────────────╮
│                                                                              │
│     You can resume the last conversation from your current directory by      │
│                        launching with q chat --resume                        │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

/help all commands  •  ctrl + j new lines  •  ctrl + s fuzzy search
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
>

テーブル一覧を確認してみます。

テーブルの一覧を見せて

途中でアクションの許可を求められるので t でセッション中は信頼します。

> テーブルの一覧を見せて
I'll help you see a list of tables in the database. Let me query the database to get that information for you.

🛠️  Using tool: readonly_query from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') ORDER BY table_schema, table_name;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.764s

データベース内のテーブル一覧は以下の通りです:

スキーマ: public
• items

スキーマ: sys
• iam_auth_member
• iam_identity
• iam_pg_role_mappings
• job
• jobs
• roles
• viewdef

publicスキーマには「items」というテーブルが1つあり、sysスキーマには7つのシステムテーブルがあります。何か特定のテーブルの詳細を確認したい場合は、お知らせください。

items テーブルの構造を確認してみます。

public スキーマの items の構造を教えて

一度うまく行かなかったので、別の方法で確認しているようです。

> public スキーマの items の構造を教えて
public スキーマの items テーブルの構造を確認します。

🛠️  Using tool: get_schema from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running get_schema with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "table_name": "public.items"
 ⋮    },
 ⋮    "name": "get_schema"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.117s

テーブル名を完全修飾形式で指定してみましたが、結果が得られませんでした。別の方法で確認してみます。

🛠️  Using tool: readonly_query (trusted) from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT column_name, data_type, character_maximum_length, is_nullable FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'items' ORDER BY ordinal_position;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
 ⋮
 ● Completed in 0.95s

public スキーマの items テーブルの構造は以下の通りです:

| カラム名 | データ型 | 最大長 | NULL許可 |
|---------|---------|-------|----------|
| item_id | integer | - | YES |
| item_cat | character varying | - | YES |
| val | integer | - | YES |
| item | text | - | YES |

このテーブルは:
• item_id: 整数型の項目ID
• item_cat: 可変長文字列型のカテゴリ
• val: 整数型の値
• item: テキスト型の項目内容

全てのカラムでNULL値が許可されています。character varying型のitem_catには最大長の指定がないようです。

データの内容を確認してみます。

データの内容をみせて

> データの内容をみせて
データの内容を確認します。items テーブルのデータを表示します。

🛠️  Using tool: readonly_query (trusted) from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT * FROM public.items;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
 ⋮
 ● Completed in 0.191s

public.items テーブルのデータ内容は以下の通りです:

| item_id | item_cat | val | item |
|---------|----------|-----|------|
| 5 | EEE | 101 | 111 |
| 3 | CCC | 103 | 333 |
| 1 | AAA | 101 | 111 |
| 2 | BBB | 102 | 222 |
| 8 | HHH | 104 | 444 |
| 6 | FFF | 102 | 222 |
| 4 | DDD | 104 | 444 |
| 7 | GGG | 103 | 333 |

テーブルには8つのレコードがあり、item_idは1から8まで、item_catはアルファベット3文字、valは101から104の値、itemは全角数字で構成されています。データはitem_idの順番ではなく、ランダムな順序で表示されています。

データを挿入してみます。

item_id を 10 に、他のカラムを NULL でデータを追加して

デフォルトでは読み取り専用なので成功しません。

> item_id を 10 に、他のカラムを NULL でデータを追加して
I'll help you add a new record to the items table with item_id set to 10 and all other columns set to NULL.

🛠️  Using tool: transact from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running transact with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql_list": [
 ⋮        "INSERT INTO public.items (item_id, item_cat, val, item) VALUES (10, NULL, NULL, NULL);"
 ⋮      ]
 ⋮    },
 ⋮    "name": "transact"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.22s

申し訳ありませんが、現在のMCPサーバー設定では書き込み操作(データの追加)が許可されていないようです。エラーメッセージによると、「Your mcp server does not allow writes. To use transact, change the MCP
configuration per README.md」(MCPサーバーが書き込みを許可していません。transactを使用するには、README.mdに従ってMCP設定を変更してください)と表示されています。

データを追加するためには、MCPサーバーの設定を変更して書き込み権限を有効にする必要があります。README.mdファイルに記載されている手順に従って設定を変更した後、再度試すことができます。

設定変更方法についてさらに詳しい情報が必要でしたら、お知らせください。

一度セッションを終了して、~/.aws/amazonq/mcp.json--allow-writes 追加します。

~/.aws/amazonq/mcp.json
{
  "mcpServers": {
    "awslabs.aurora-dsql-mcp-server": {
      "command": "uvx",
      "args": [
        "awslabs.aurora-dsql-mcp-server@latest",
        "--cluster_endpoint",
        "[your dsql cluster endpoint]",
        "--region",
        "[your dsql cluster region, e.g. us-east-1]",
        "--database_user",
        "[your dsql username]",
        "--allow-writes",
        "--profile", "default"
      ],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

改めてデータを挿入してみます。--allow-writes パラメータを追加しているので、意図しないデータ変更がされないか操作内容を確認するようにして下さい。

public スキーマの items に対して、item_id を 10 に、他のカラムを NULL でデータを追加して

正常にデータを挿入しています。念の為 psql コマンドでログインしてデータを確認しましたが問題ありませんでした。

> public スキーマの items に対して、item_id を 10 に、他のカラムを NULL でデータを追加して
I'll help you add a record to the items table in the public schema with item_id set to 10 and all other columns set to NULL. First, let me check the schema of the table to understand its structure.

🛠️  Using tool: get_schema from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running get_schema with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "table_name": "public.items"
 ⋮    },
 ⋮    "name": "get_schema"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.257s
It seems I couldn't retrieve the schema information for the table. Let me try to query the table structure first to understand what columns it has.

🛠️  Using tool: readonly_query from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'items' ORDER BY ordinal_position;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.93s
Now I have the table structure. The public.items table has the following columns:
• item_id (integer)
• item_cat (character varying)
• val (integer)
• item (text)

Let me insert a record with item_id set to 10 and all other columns set to NULL:

🛠️  Using tool: transact from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running transact with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql_list": [
 ⋮        "INSERT INTO public.items (item_id, item_cat, val, item) VALUES (10, NULL, NULL, NULL);"
 ⋮      ]
 ⋮    },
 ⋮    "name": "transact"
 ⋮  }
Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> t

 ⋮
 ● Completed in 0.135s

🛠️  Using tool: readonly_query (trusted) from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT * FROM public.items WHERE item_id = 10;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
 ⋮
 ● Completed in 0.61s
データを正常に追加しました。public.itemsテーブルにitem_idが10で、他のすべてのカラム(item_cat、val、item)がNULLの新しいレコードが挿入されました。

確認のために実行したクエリでも、期待通りのデータが追加されていることが確認できました。

内容を確認します。

データの内容をみせて

item_id が 10 のレコードが挿入されていることを確認できました。

> データの内容をみせて

🛠️  Using tool: readonly_query (trusted) from mcp server awslabsaurora_dsql_mcp_server
 ⋮
 ● Running readonly_query with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "sql": "SELECT * FROM public.items ORDER BY item_id;"
 ⋮    },
 ⋮    "name": "readonly_query"
 ⋮  }
 ⋮
 ● Completed in 0.78s
public.itemsテーブルの全データは以下の通りです:

1. item_id: 1, item_cat: "AAA", val: 101, item: "111"
2. item_id: 2, item_cat: "BBB", val: 102, item: "222"
3. item_id: 3, item_cat: "CCC", val: 103, item: "333"
4. item_id: 4, item_cat: "DDD", val: 104, item: "444"
5. item_id: 5, item_cat: "EEE", val: 101, item: "111"
6. item_id: 6, item_cat: "FFF", val: 102, item: "222"
7. item_id: 7, item_cat: "GGG", val: 103, item: "333"
8. item_id: 8, item_cat: "HHH", val: 104, item: "444"
9. item_id: 10, item_cat: null, val: null, item: null

先ほど追加したitem_id: 10のレコードが、他のカラムがすべてNULLの状態で正しく登録されていることが確認できます。

この様に自然言語で Aurora DSQL にアクセスできます。

さいごに

SQL が分かるのであれば簡単な操作は自分で SQL を書いたほうが速いですが、情報を探索しつつ操作する場合にはかなり楽をできそうです。

新サービスで一般提供の開始時から MCP サーバーを用意するというのは、生成 AI に対する AWS の本気度を伺えます。今後の新サービスでも MCP サーバーが標準装備されると面白いなと思いました。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.