# SQLGuardLLM

> SQLGuardLLM is an open-source MCP server for databases. SQL firewall for LLM agents: validates and rewrites model-written SQL to read-only. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** API, CLI, Self-hosted, VS Code
- **Website:** https://jmmana.github.io/sqlguardllm/
- **Repository:** https://github.com/jmmana/sqlguardllm
- **MCP Registry name:** io.github.jmmana/sqlguardllm
- **Categories:** [databases](https://ai-powered.com/categories/databases), [security](https://ai-powered.com/categories/security)
- **Listing updated:** 2026-11-30

## About

Language models that generate SQL can be tricked into writing destructive or over-broad queries. This open-source Python library sits between the model and the database, parsing each statement into a syntax tree and deciding on that structure rather than on keyword matches. It accepts only a single read-only query, checks tables, columns and functions against a policy, and rewrites the query so it only sees rows the current user is allowed to access.

Beyond the core checks, a policy can cap joins and subquery depth, require filters on large tables, mask sensitive columns, or restrict a table to aggregate results with minimum group sizes. The library works across many SQL dialects through sqlglot, and it can translate the rewritten query into another dialect. Node.js and .NET clients are available, and the same engine can run as a local MCP server or HTTP sidecar.

It suits developers building text-to-SQL features, data agents or MCP database tools who want a guard layer in front of their read-only database account. The project is in alpha, so its API may change before 1.0.

## Features

- **Syntax-tree query validation:** Parses each statement with sqlglot and rejects anything other than one read-only query, including writes hidden inside CTEs.
- **Row-level filters per user:** Rewrites every reference to a filtered table as a derived table limited to the rows the current user may see.
- **Table and column allowlists:** Restricts which tables can be read and hides specified columns, rejecting queries that reach them.
- **Denied function lists:** Blocks dialect-specific functions for file access, sleeps, shell calls and network reads.
- **Optional complexity limits:** Caps joins, subquery depth and cartesian products, and can require filters on chosen columns.
- **Column masking and aggregate-only tables:** Returns sensitive columns masked and can force aggregate-only reads with minimum group sizes.
- **Multiple client options:** Usable as an embedded Python library, Node.js or .NET package, CLI, HTTP server or MCP server.

## Good for

- Letting an LLM agent answer questions from a production database without write access
- Adding a row-level tenant filter to text-to-SQL features in a multi-tenant app
- Exposing a safe read-only database tool to Claude Desktop, Cursor or VS Code via MCP
- Testing and linting database access policies in CI before deployment
- Translating model-written PostgreSQL into SQL Server or Oracle syntax

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add sqlguardllm --env DATABASE_URL='<DATABASE_URL>' -- uvx sqlguardllm
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

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

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add sqlguardllm --env DATABASE_URL='<DATABASE_URL>' -- uvx sqlguardllm
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.sqlguardllm]
command = "uvx"
args = ["sqlguardllm"]
env = { DATABASE_URL = "<DATABASE_URL>" }
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e DATABASE_URL='<DATABASE_URL>' sqlguardllm uvx -- sqlguardllm

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

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

```json
{
  "mcpServers": {
    "sqlguardllm": {
      "command": "uvx",
      "args": [
        "sqlguardllm"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}
```

## FAQ

### Does SQLGuardLLM replace a read-only database account?

No. The project recommends a read-only database user as the first layer, with sqlguardllm between the model and the database, plus statement timeouts and audit logs.

### Which database dialects are supported?

Any of the 32 dialects that sqlglot supports, with checks and rewrites expressed in each dialect's own syntax.

### What does the MCP server need to run?

It runs locally over stdio from the PyPI package sqlguardllm and requires a DATABASE_URL pointing to a least-privilege read-only account.

### Is SQLGuardLLM free to use?

It is open source under the Apache-2.0 licence and is installed with pip, npm or NuGet.

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

Run this command in your terminal: claude mcp add sqlguardllm --env DATABASE_URL='<DATABASE_URL>' -- uvx sqlguardllm

### What are the best alternatives to SQLGuardLLM?

The closest alternatives to SQLGuardLLM are SQLGuard — Execution Certificate Firewall, SQLGuard — permission before production writes, Pg Readonly MCP, SQL MCP Server and pgleash.

## Where this comes from

- Description: written from the project's README, the project's website and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [SQLGuard — Execution Certificate Firewall](https://ai-powered.com/mcp/sqlguard-execution-certificate-firewall): SQLGuard — Execution Certificate Firewall is a paid MCP server for databases.
- [SQLGuard — permission before production writes](https://ai-powered.com/mcp/sqlguard-permission-before-production-writes): SQLGuard — permission before production writes is a paid MCP server for security.
- [Pg Readonly MCP](https://ai-powered.com/mcp/pg-readonly-mcp): Pg Readonly MCP is an open-source MCP server for databases.
- [SQL MCP Server](https://ai-powered.com/mcp/sql-mcp-server): SQL MCP Server is an open-source MCP server for databases.
- [pgleash](https://ai-powered.com/mcp/pgleash): pgleash is an open-source MCP server for databases.
- [Orion Gate](https://ai-powered.com/mcp/orion-gate): Orion Gate is an open-source MCP server for databases.
- [mssql-readonly-mcp](https://ai-powered.com/mcp/mssql-readonly-mcp): mssql-readonly-mcp is an open-source MCP server for databases.
- [Lagaam](https://ai-powered.com/mcp/lagaam): Lagaam is an open-source MCP server for databases.

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