> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/developer-and-mcp/ai-agent-access/pam-database-queries-with-mcp.md).

# MCPによるPAMデータベースのクエリ

Keeper MCPを使用して、PAMで管理されるデータベースに対し、統制されたクエリを実行

承認されたAIエージェントは、Keeper MCPを使用して、Keeperデスクトップで構成された機能とリソースのスコープの範囲内で、PAMで管理されるデータベースにクエリを実行できます。このワークフローでは、**PAMデータベースでKeeperPAMのデータベースクエリを実行**の機能を使用します。KeeperDBデスクトップアプリケーションへの個別のMCP接続とは異なります。

## 要件 <a href="#prerequisites" id="prerequisites"></a>

* Keeper MCPがインストールされ、AIクライアントに接続されていること。[Keeper MCPのセットアップ](https://docs.keeper.io/keeperpam/jp/developer-and-mcp/ai-agent-access/keeper-mcp-setup.md)をご参照ください。
* 対象のデータベースが、必要なPAM構成、ゲートウェイの接続、データベースプロトコル、リンクされた認証情報とともに、[PAMデータベース](https://docs.keeper.io/keeperpam/jp/privileged-access-manager/getting-started/pam-resources/pam-database.md)として構成されていること。
* ユーザーが、PAMデータベースリソースへの必要なアクセス権を持っていること。構成されたワークフローで承認が必要な場合は、その承認も含みます。
* データベースクエリのアクセスが有効で、対象のPAMデータベースレコードにスコープが限定されていること。

検索結果にPAMデータベースレコードが表示されていても、そのデータベースに到達できること、またはクエリが認可されていることを意味するわけではありません。

## データベースクエリのガードレールの構成 <a href="#configure-database-query-guardrails" id="configure-database-query-guardrails"></a>

1. **\[開発者センター]** > **\[AIエージェントアクセス]** を開きます。
2. **PAMデータベースでKeeperPAMのデータベースクエリを実行**を探します。
3. **\[ガードレール]** ダイアログを開きます。
4. 読み取り専用のワークフローでは、**\[書き込みクエリを許可]** をオフのままにします。
5. **\[クエリあたりの最大行数]** を設定します。空欄の場合は、組み込みの上限である10,000行が使用されます。
6. **\[トンネルを閉じる]** を有効にして、タスクの完了後にクリーンアップできるようにします。
7. 必要なデータベースレコードまたはフォルダのみを選択します。
8. **\[更新]** をクリックし、機能が有効になっていることを確認します。

エージェントがタイトルでデータベースを検索する必要がある場合は、**レコードの読み取り**を有効にしてスコープを設定します。ワークフローで、許可されたアクセスの確認、開始、終了の操作も必要な場合は、PAMアクセス管理の機能を構成します。

## PAMデータベースへのAIコンテキストの追加 <a href="#add-ai-context-to-a-pam-database" id="add-ai-context-to-a-pam-database"></a>

AIコンテキストは、エージェントがセッションを開始する前に読み取る、リソース固有の情報です。データベースの用途、テーブルの場所、指標の定義、期待されるタスクなどを説明できます。

1. **\[マイボルト]** でPAMデータベースレコードを開き、**\[編集]** をクリックします。
2. **\[PAM設定]** を開きます。
3. **\[MCPアクセス]** を選択します。
4. **\[AIコンテキスト]** にデータベースに関するガイダンスを入力します。このフィールドには**2,000文字**まで入力できます。
5. PAM設定で **\[更新]** をクリックし、レコードを保存します。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2Fgit-blob-7c6f9880ca1e1b67b6f4da34455d2f05193d58f5%2FScreenshot%202026-11-05%20at%201.48.54%E2%80%AFPM.png?alt=media" alt=""><figcaption></figcaption></figure>

以下は、入力例です。

```
For ARR (Annual Recurring Revenue), use the arr_metrics table and the
arr_snapshot column. Filter snapshot_type = 'month_end'.

For net new ARR:
new_business_arr + expansion_arr - contraction_arr - churn_arr.
```

これらのテーブル名と計算式は例です。ご利用のデータベースの定義に置き換えてください。AIコンテキストには、認証情報や無関係な機密データを保存しないでください。

**AIコンテキストはガイダンスであり、権限の境界ではありません。** このフィールドに「読み取り専用」と記載しても、読み取り専用のアクセスが強制されるわけではありません。アクセスの制御には、AIエージェントアクセスのガードレール、PAMの制御、データベースアカウントの権限を使用してください。

## データベースの検出 <a href="#discover-the-database" id="discover-the-database"></a>

最初に、レコード検出のリクエストを行います。

```
Find the PAM Database record named Finance Database in my allowed folders.
Return its title and record type. Do not retrieve credentials or run queries yet.
```

クエリをリクエストする前に、選択されたリソースを確認します。誤った環境を選択しないよう、会話ではレコードのタイトルを使用してください。

## 読み取り専用の分析の実行 <a href="#run-a-read-only-analysis" id="run-a-read-only-analysis"></a>

データベース、期間、必要な出力、許可する操作を明記したプロンプトを使用します。

```
Using the Finance Database PAM resource, inspect the Chinook Invoice schema
and generate a text chart of monthly revenue for calendar year 2025.
Use read-only queries. Explain the date range and revenue calculation.
Close the database tunnel when finished.
```

スクリーンショットの例では、エージェントが列のメタデータと利用可能な請求日を調べ、`Invoice.Total` から月別の売上を計算し、テキストベースのグラフを返したうえで、トンネルを閉じています。この例ではChinookサンプルデータベースを使用しており、ARRの計算ではありません。

対応するMySQLの集計は、以下のように表せます。

```sql
SELECT
    DATE_FORMAT(InvoiceDate, '%Y-%m') AS month,
    SUM(Total) AS revenue,
    COUNT(*) AS invoice_count
FROM Chinook.Invoice
WHERE InvoiceDate >= '2025-01-01'
  AND InvoiceDate < '2026-01-01'
GROUP BY DATE_FORMAT(InvoiceDate, '%Y-%m')
ORDER BY month;
```

結果を利用する前に、生成されたSQL、選択されたデータベース、日付範囲、指標の定義を確認してください。集計期間が重要な場合は、「昨年」などの表現ではなく、明示的な日付を使用してください。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2Fgit-blob-d2d2d9d1e9558a37fbfd47740489c52e48a0d9a5%2FScreenshot%202026-11-05%20at%201.35.15%E2%80%AFPM%20(1).png?alt=media" alt=""><figcaption><p>PAMデータベースへのAIエージェントアクセスの例</p></figcaption></figure>

## データの取り扱いとクリーンアップ <a href="#data-handling-and-cleanup" id="data-handling-and-cleanup"></a>

認証情報が返されない場合でも、データベースクエリの出力には機密情報が含まれる可能性があります。集計値を優先し、取得する列と行を制限し、必要最小限の権限を持つデータベースアカウントを使用してください。クエリ結果をAIクライアントの会話に含める前に、クライアントのプロバイダーとデータの取り扱いに関する設定を確認してください。

タスクの完了後は、エージェントにデータベーストンネルを閉じるよう依頼します。ワークフローで承認済みのPAMアクセスを開始した場合は、不要になった時点でそのアクセスを終了します。クエリのクリーンアップとPAMアクセスのライフサイクル管理は、別の操作です。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keeper.io/keeperpam/jp/developer-and-mcp/ai-agent-access/pam-database-queries-with-mcp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
