# AgentSQL [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/cuipengdba/agentsql  
**GitHub Stars:** 24  
**Views:** 12  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/agentsql

## Description
Guard AI agents' PostgreSQL/MySQL access via MCP: SQL audit, auth, masking, write approval

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/cuipengdba/agentsql), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Install:

```sh
curl -fsSL https://github.com/cuipengdba/agentsql/releases/download/v4.8.1/install.sh | sudo sh -s -- install --version v4.8.1
```

2. Install:

```sh
curl -fsSL https://raw.githubusercontent.com/cuipengdba/agentsql/v4.8.1/scripts/quickstart.sh -o quickstart.sh && sh quickstart.sh --version v4.8.1
```

## Documentation

## What AgentSQL does

AgentSQL acts as a policy-enforcing gateway for MCP-based database access. Requests from an agent pass through authentication, agent and tenant checks, object or column authorization, SQL parsing, rule evaluation, controlled execution, result protection, and persistent audit logging before reaching a data source.

The main database scope includes PostgreSQL and MySQL, with additional controlled or read-only paths for selected versions and deployments of MongoDB, Redis, Valkey, ClickHouse, Milvus, Oracle, SQL Server, openGauss, YashanDB, Dameng, Kingbase, Vastbase, Highgo, and other registered database types. These paths are bounded by their tested versions, topologies, and feature subsets.

AgentSQL also includes a web console for agents, data sources, permissions, rules, approvals, masking policies, users, roles, tenants, audits, and onboarding. Its standalone features include natural-language querying, charts, dashboards, and embeddable applications.

## How it works

The request path is:

- AI agent and MCP client
- AgentSQL gateway
- Authentication, authorization, rules, approvals, and execution controls
- Data source
- Masked result and audit record

The gateway defaults to rejecting unauthorized operations. Controls include API keys, optional human-and-agent identity checks, SQL AST rules, read-only restrictions, dangerous-query blocking, Explain-based risk checks, timeouts, connection and QPS limits, result-row budgets, and manual approval for selected writes or delegated actions.

Column protection supports partial masking, keyed HMAC fingerprints, whole-value blocking, and coarse numeric or date ranges. Data-source passwords are encrypted using `AGENTSQL_SECRET`. Audit records can be exported as JSONL or protected CSV, and security events can be sent through Webhook or Syslog without replacing the primary audit trail.

## Setup and configuration

AgentSQL can run over local stdio or Streamable HTTP using the `/mcp` endpoint. A zero-configuration SQLite store is available for local operation. Deployments can instead use PostgreSQL 15 or newer for the control plane, with metadata and audit data placed in separate databases when needed.

The service provides health and readiness probes, Prometheus metrics, and an embedded web console. Optional HTTP protections include an external OIDC/OAuth authorization server through `/mcp/oauth`, with tokens bound to an agent key, user mapping, tenant, and local permissions.

Set `AGENTSQL_SECRET` to protect stored data-source credentials. Deployment and database support should be evaluated against the specific database version, topology, and feature subset being used; tested support does not automatically extend to untested variants.

## Tools and capabilities

The MCP interface provides 12 foundational database tools. PostgreSQL B5 sessions and planned transactions add eight more tools when that capability is enabled. Specialized controlled tools include:

- `find_documents` for bounded MongoDB reads
- `read_key` for restricted Redis or Valkey string reads
- `query_analytics` for constrained ClickHouse queries
- `search_vectors` for bounded Milvus vector searches

The gateway can expose controlled SQL, bounded SQL, dedicated read tools, and connection previews according to the data-source and policy configuration. Administrative functions cover policy review, table-level impact previews, signed policy delivery, audit export, approval decisions, and read-only diagnostics.

_Full upstream README: https://allmcps.com/mcp/agentsql/readme_

