# AgentSQL

> AgentSQL is an open-source MCP server for databases. Guard agents' PostgreSQL and MySQL access with SQL audit, masking and write approval. It runs as a hosted remote server, so there is nothing to install locally.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** self-hosted, Linux, API, Web
- **Website:** https://agentsql.cn
- **Repository:** https://github.com/cuipengdba/agentsql
- **MCP Registry name:** io.github.cuipengdba/agentsql
- **Categories:** databases, security
- **Listing updated:** 2026-11-16

## About

Every query from an external agent passes a six-stage chain: the API key is verified and agent, data source and policy are loaded (failing closed), SQL is parsed into an AST for the PostgreSQL or MySQL dialect, static checks run before any database contact, then read-only EXPLAIN and metadata checks. Decisions combine deny, approve, warn and allow into allow, alert, block or human review. Only allowed or warned statements execute, with limits on connections, timeouts and rows, and results are masked by column before return. Each decision is written to an application audit log, and audit failure also fails closed.

The project is also a standalone natural-language data-question agent with its own Go web page, so SQLBot is not required, though a version-pinned adapter can route SQLBot's database calls through the gateway. Both entry points share identity, authorization, execution control, masking and audit. A live demo runs on synthetic data only.

It is self-hosted, ships as a Go binary under Apache-2.0, supports stdio and HTTP MCP and exposes Prometheus metrics. The release notes caution that it has not been verified on users' real business systems. Documentation is mainly in Chinese.

## Features

- **Six-stage SQL gate:** Authenticates, parses, checks, decides, executes and audits each query.
- **Dangerous-statement rules:** Blocks writes without WHERE and unauthorized tables.
- **Result masking:** Masks sensitive columns such as phone and email.
- **Write approval:** Can route risky statements to human review.
- **Persistent audit:** Records decisions with matched rules and timeline.
- **Own query agent:** Ask questions in natural language without SQLBot.

## Good for

- Let an external AI agent query a production-like database safely
- Mask phone numbers and emails in results sent to a model
- Require approval before an agent runs an UPDATE
- Keep an audit trail of every agent query

## Install

### Claude Code (Terminal)

```sh
claude mcp add --transport http agentsql https://demo.agentsql.cn/mcp
```

### Claude Desktop (Settings → Connectors → Add custom connector)

```sh
https://demo.agentsql.cn/mcp
```

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "agentsql": {
      "url": "https://demo.agentsql.cn/mcp"
    }
  }
}
```

### VS Code (.vscode/mcp.json)

```json
{
  "servers": {
    "agentsql": {
      "type": "http",
      "url": "https://demo.agentsql.cn/mcp"
    }
  }
}
```

### Windsurf (~/.codeium/windsurf/mcp_config.json)

```json
{
  "mcpServers": {
    "agentsql": {
      "serverUrl": "https://demo.agentsql.cn/mcp"
    }
  }
}
```

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "agentsql": {
      "type": "http",
      "url": "https://demo.agentsql.cn/mcp"
    }
  }
}
```

## FAQ

### Which databases are supported?

PostgreSQL and MySQL dialects are parsed, with support levels listed in the project's compatibility matrix.

### Is it self-hosted?

Yes, as a Go binary or Docker image under Apache-2.0.

### Does it require SQLBot?

No. SQLBot is an optional client through a fixed-version adapter.

### Is it production verified?

The release notes say it has not been verified on users' real business systems.

### Is AgentSQL free?

Yes. AgentSQL is open source, so you can use and self-host it for free.

### How do I add AgentSQL to Claude Code?

Run this command in your terminal: claude mcp add --transport http agentsql https://demo.agentsql.cn/mcp

### What are the best alternatives to AgentSQL?

The closest alternatives to AgentSQL are REA, Agent Roast, Midplane, Leash and Tinplate Edge AI Safety, Security & EU Compliance.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [Agent Roast](https://ai-powered.com/mcp/agent-roast): Agent Roast is an open-source MCP server for developer tools.
- [Midplane](https://ai-powered.com/mcp/midplane): Midplane is an open-source MCP server for databases.
- [Leash](https://ai-powered.com/mcp/leash): Leash is a free MCP server for security.
- [Tinplate Edge AI Safety, Security & EU Compliance](https://ai-powered.com/mcp/tinplate-edge-ai-safety-security-and-eu-compliance): Tinplate Edge AI Safety, Security & EU Compliance is a freemium MCP server for security.
- [SecureCloud](https://ai-powered.com/mcp/securecloud): SecureCloud is a free MCP server for security.
- [Eikino](https://ai-powered.com/mcp/eikino): Eikino is a freemium MCP server for security.
- [SynomosAI Governance MCP](https://ai-powered.com/mcp/synomosai-governance-mcp-2): SynomosAI Governance MCP is an open-source MCP server for security.

---
Source: https://ai-powered.com/mcp/agentsql
