> 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/developer-and-mcp/ai-agent-access/pam-database-queries-with-mcp.md).

# Query PAM Databases with MCP

Use Keeper MCP to run governed queries against PAM-managed databases.

An approved AI agent can use Keeper MCP to query PAM-managed databases within the capabilities and resource scopes configured in Keeper Desktop. This workflow uses the **Execute KeeperPAM Database queries on PAM Databases** capability. It is distinct from the separate MCP connection to the KeeperDB desktop application.

## Prerequisites

* Keeper MCP is installed and connected to the AI client. See [Set Up Keeper MCP](https://docs.keeper.io/keeperpam/developer-and-mcp/ai-agent-access/keeper-mcp-setup.md).
* The target database is configured as a [PAM Database](https://docs.keeper.io/keeperpam/privileged-access-manager/getting-started/pam-resources/pam-database.md), with the required PAM configuration, Gateway connectivity, database protocol, and linked credentials.
* The user has the required access to the PAM Database resource, including approval when the configured workflow requires it.
* Database-query access is enabled and scoped to the intended PAM Database record.

The presence of a PAM Database record in a search result does not establish that the database is reachable or that queries are authorized.

## Configure database-query guardrails

1. Open **Developer Center > AI Agent Access**.
2. Find **Execute KeeperPAM Database queries on PAM Databases**.
3. Open its **Guardrails** dialog.
4. Leave **Allow write queries** off for a read-only workflow.
5. Set **Maximum Rows per Query**, or leave it blank to use the built-in 10,000-row limit.
6. Enable **Close tunnels** to allow cleanup after the task.
7. Select only the required database records or folders.
8. Click **Update**, then verify that the capability is enabled.

Enable and scope **Read records** if the agent needs to discover the database by title. Configure the PAM access-management capability if the workflow also requires the permitted status, start, or end access actions.

## Add AI Context to a PAM Database

AI Context provides resource-specific information the agent reads before starting a session. It can explain the database's purpose, table locations, metric definitions, and the expected task.

1. Open the PAM Database record in **My Vault** and click **Edit**.
2. Open **PAM Settings**.
3. Select **MCP Access**.
4. Enter the database guidance in **AI Context**. The field supports up to **2,000 characters**.
5. Click **Update** in PAM Settings, then save the record.

<figure><img src="https://762006384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJXOXEifAmpyvNVL1to%2Fuploads%2FFrfzxRGcQWIVHpeeqDls%2FScreenshot%202026-11-05%20at%201.48.54%E2%80%AFPM.png?alt=media&amp;token=0b6270f1-567e-430d-99d8-d5f766ec676f" alt=""><figcaption></figcaption></figure>

For example:

```
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.
```

These table names and calculations are examples. Replace them with definitions for your own database. Do not store credentials or unrelated sensitive data in AI Context.

**AI Context is guidance, not a permission boundary.** Writing "read-only" in this field does not enforce read-only access. Enforce access through AI Agent Access guardrails, PAM controls, and the database account's permissions.

## Discover the database

Start with a record-discovery request:

```
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.
```

Review the selected resource before requesting a query. Use record titles in the conversation to avoid selecting the wrong environment.

## Run a read-only analysis

Use a prompt that identifies the database, the time period, the requested output, and the permitted operations:

```
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.
```

The screenshot example shows the agent inspecting column metadata and the available invoice dates, calculating monthly revenue from `Invoice.Total`, returning a text-based chart, and closing the tunnel. The example uses the Chinook sample database; it is not an ARR calculation.

The corresponding MySQL aggregation can be expressed as:

```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;
```

Review the generated SQL, selected database, date range, and metric definition before relying on the result. Use explicit dates instead of phrases such as "last year" when the reporting period matters.

<figure><img src="https://762006384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJXOXEifAmpyvNVL1to%2Fuploads%2FxxCDtvtd2zdiu112khHo%2FScreenshot%202026-11-05%20at%201.35.15%E2%80%AFPM.png?alt=media&amp;token=8398d835-8e45-43e5-9b6e-10d668d94d1b" alt=""><figcaption><p>Example of AI Agent Access to a PAM Database</p></figcaption></figure>

## Data handling and cleanup

Database-query output can contain sensitive information even when no credentials are returned. Prefer aggregates, restrict the columns and rows retrieved, and use a database account with the minimum required permissions. Review the AI client's provider and data-handling settings before allowing query results into its conversation.

Ask the agent to close the database tunnel after the task. If the workflow starts approved PAM access, end that access when it is no longer needed. Query cleanup and PAM access lifecycle management are separate actions.


---

# 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/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.
