# run_query

Execute a read-only SELECT query and return structured rows (FR-003)

Agent View of the PolicyLayer registry record for `run_query`. HTML page: https://policylayer.com/tools/allensandiego-postgres-mcp-server/run-query

## Facts

- Tool: `run_query`
- Server: Postgres (`@allensandiego/postgres-mcp-server`) — https://policylayer.com/tools/allensandiego-postgres-mcp-server.md
- Install: `npx -y @allensandiego/postgres-mcp-server`
- Homepage: https://www.npmjs.com/package/@allensandiego/postgres-mcp-server
- Risk category: Execute (High risk)
- Registry record: grade F, identity unverified
- Server rate-limited: no
- Parameters: 5 (1 required)
- Recommended policy verdict: Rate-limited

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `sql` | string | yes | Read-only SQL query to execute (e.g. SELECT) |
| `role` | string | no | Optional PostgreSQL role to assume (SET ROLE) for this query only |
| `limit` | integer | no | Maximum number of rows to return (capped by server maxRowLimit) |
| `offset` | integer | no | Number of rows to skip before returning results |
| `params` | array | no | Optional parameterized query values ($1, $2, etc.) |

Parameters from the server's own tool schema.

## Example call (MCP tools/call, JSON-RPC 2.0)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run_query",
    "arguments": {
      "sql": "<sql>"
    }
  }
}
```

## Why run_query is rated High

run_query triggers real processes with real consequences. An agent gone sideways doesn't fire it once. It starts dozens of builds, sends mass notifications, or burns through compute before anyone looks up.

Risk signals: Accepts freeform code/query input (sql)

## Use case

AI agents invoke run_query to trigger actions in Postgres. What it does depends on the arguments the agent supplies, and its effects often reach beyond the immediate call: builds kicked off, notifications sent, workflows started.

## Recommended policy (PolicyLayer)

Verdict: **Rate-limited**. Enforced by the PolicyLayer MCP gateway (https://policylayer.com/mcp-gateway) before a call reaches Postgres:

```json
{
  "version": "1",
  "default": "deny",
  "tools": {
    "run_query": {
      "limits": [
        {
          "counter": "run_query_rate",
          "window": "minute",
          "max": 10,
          "scope": "grant"
        }
      ]
    }
  }
}
```

## Other tools on Postgres (7)

- `run_write_query` — Execute — https://policylayer.com/tools/allensandiego-postgres-mcp-server/run-write-query.md
- `describe_table` — Read — https://policylayer.com/tools/allensandiego-postgres-mcp-server/describe-table.md
- `list_databases` — Read — https://policylayer.com/tools/allensandiego-postgres-mcp-server/list-databases.md
- `list_permissions` — Read — https://policylayer.com/tools/allensandiego-postgres-mcp-server/list-permissions.md
- `list_roles` — Read — https://policylayer.com/tools/allensandiego-postgres-mcp-server/list-roles.md
- `list_tables` — Read — https://policylayer.com/tools/allensandiego-postgres-mcp-server/list-tables.md
- `set_role` — Write — https://policylayer.com/tools/allensandiego-postgres-mcp-server/set-role.md

## For agents

This record is a snapshot. Live verdicts and the full registry:

- Check every server in your MCP config at once: `npx -y policylayer stack`
- Vet a server before you add it: install the mcp-precheck skill — `npx skills add https://policylayer.com` (skill text: https://policylayer.com/skill.md)
- Query the registry over MCP: endpoint `https://api.policylayer.com/mcp` — tools `check_mcp_server`, `check_mcp_stack`, `check_tool`, `search_registry`, `get_change_events`

---

Source: the PolicyLayer MCP registry — one continuously verified record per MCP server. Full record: https://policylayer.com/registry?q=allensandiego-postgres-mcp-server · API: https://policylayer.com/registry/api · Policy library: https://policylayer.com/policies/allensandiego-postgres-mcp-server
