SQLGuardLLM
SQL firewall for LLM agents: validates and rewrites model-written SQL to read-only
SQLGuardLLM is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- API, CLI, Self-hosted
- Runs
- Locally
- Access
- Needs a secret key or token
- Version
- 1.0.0
- Listing updated
Similar MCP servers
Install
Add with the CLI
Run in a terminal
claude mcp add sqlguardllm --env DATABASE_URL='<DATABASE_URL>' -- uvx sqlguardllmAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"sqlguardllm": {
"command": "uvx",
"args": [
"sqlguardllm"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"sqlguardllm": {
"command": "uvx",
"args": [
"sqlguardllm"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.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.
Add to ~/.copilot/mcp-config.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.
Add with the CLI
Run in a terminal
codex mcp add sqlguardllm --env DATABASE_URL='<DATABASE_URL>' -- uvx sqlguardllmOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.sqlguardllm]
command = "uvx"
args = ["sqlguardllm"]
env = { DATABASE_URL = "<DATABASE_URL>" }Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"sqlguardllm": {
"command": "uvx",
"args": [
"sqlguardllm"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.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
Antigravity
Add to ~/.gemini/config/mcp_config.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 (formerly Windsurf)
Add to ~/.config/devin/mcp_config.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
Add to cline_mcp_settings.json
{ "mcpServers": { "sqlguardllm": { "command": "uvx", "args": [ "sqlguardllm" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.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
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "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.
Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "sqlguardllm": { "command": "uvx", "args": [ "sqlguardllm" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "sqlguardllm": { "command": "uvx", "args": [ "sqlguardllm" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
Configuration
DATABASE_URLSQLAlchemy URL for a least-privilege read-only database accountRequired
About SQLGuardLLM
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.
What it does
- 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
Pricing
Open source
Free open-source library under Apache-2.0.
Prices change. Check jmmana.github.io before you buy.
SQLGuardLLM 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.