AgentSQL logo

AgentSQL

Secures AI-agent access to PostgreSQL, MySQL, and other data systems with authorization, approvals, masking, and audit controls.

Install AgentSQL

Run the project’s own setup commands, in order.

Setup steps from the project

AgentSQL installs with its own steps rather than a config we can generate, so these are copied as-is. Follow them in order and run the commands in a terminal. Source: github.com

  1. 1. Install
    curl -fsSL https://github.com/cuipengdba/agentsql/releases/download/v4.8.1/install.sh | sudo sh -s -- install --version v4.8.1
    
  2. 2. Install
    curl -fsSL https://raw.githubusercontent.com/cuipengdba/agentsql/v4.8.1/scripts/quickstart.sh -o quickstart.sh && sh quickstart.sh --version v4.8.1
    

Overview

AgentSQL is a database security gateway and MCP server that places authentication, SQL parsing, authorization, rule evaluation, execution controls, masking, and auditing between an AI agent and data sources. It supports local stdio and Streamable HTTP at `/mcp`, with controlled database tools, approval workflows, query limits, and fail-closed errors. PostgreSQL and MySQL are core targets, while additional verified paths cover selected MongoDB, Redis/Valkey, ClickHouse, Milvus, Oracle, SQL Server, and other databases. Reach for it when agents need governed database access rather than direct credentials.

Use cases

  • Gate AI-agent queries to production PostgreSQL or MySQL
  • Require approval before selected database writes
  • Mask sensitive columns before returning query results
  • Audit and review agent database activity
  • Expose bounded reads from Redis, MongoDB, ClickHouse, or Milvus

Key features

  • PostgreSQL and MySQL MCP access controls
  • Local stdio and Streamable HTTP transports
  • SQL authorization, risk checks, and fail-closed handling
  • Column masking and result protection
  • Human approval and agent identity binding
  • Persistent audit, metrics, and security notifications

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

14/14 checks healthy over the last 46d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars24Stargazers on the source repository.
Last commitTodayMost recent push to the default branch.
Directory activity12 viewsConfig copies, upvotes, and views on AllMCPs.

How AgentSQL works

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.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about AgentSQL

AgentSQL is an MCP server that connects AI agents to governed database access through PostgreSQL, MySQL, and selected other data systems. Its main tools provide controlled SQL and bounded reads, while the gateway applies authentication, authorization, approvals, masking, execution limits, and persistent auditing before returning results.

Run AgentSQL as a local stdio service or expose its Streamable HTTP MCP endpoint at `/mcp`. It supports a zero-configuration SQLite control store or PostgreSQL 15+ for control-plane metadata and auditing. Set `AGENTSQL_SECRET` to encrypt stored data-source passwords.

Yes, AgentSQL supports controlled writes and manual approval for selected operations. Policies can combine read-only protection, dangerous-SQL blocking, Explain risk evaluation, identity binding, delegated approvals, timeouts, and result limits before execution.

Yes, AgentSQL masks results at the column level before delivery. Available approaches include partial masking, keyed HMAC fingerprints, full-value blocking, and coarse numeric or date ranges, with policies evaluated as part of the request path.

AgentSQL primarily supports PostgreSQL and MySQL, with controlled paths for selected MongoDB, Redis, Valkey, ClickHouse, Milvus, Oracle, SQL Server, openGauss, YashanDB, Dameng, Kingbase, Vastbase, and Highgo deployments. Each path is limited to its tested versions, topology, and operation subset.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewAgentSQL AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/agentsql?style=directory)](https://allmcps.com/mcp/agentsql)
HTML Embed
<a href="https://allmcps.com/mcp/agentsql"><img src="https://allmcps.com/api/badge/agentsql?style=directory" alt="AgentSQL on AllMCPs" /></a>