MCP Database Guardrail
Provides read-only schema inspection and safe SQL query execution against MySQL databases, with AST guardrails, automatic LIMIT enforcement, and execution timeouts.
Provides read-only schema inspection and safe SQL query execution against PostgreSQL databases, with configurable connection settings, AST guardrails, automatic LIMIT enforcement, and execution timeouts.
Provides read-only schema inspection and safe SQL query execution against SQLite databases, with AST guardrails, automatic LIMIT enforcement, and execution timeouts.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
π‘οΈ MCP Database Guardrail
Enterprise-grade Model Context Protocol (MCP) servers for secure, read-only database exploration (SQLite, PostgreSQL, MySQL) with AST guardrails and zero-trust controls.
Official companion open-source repository for the 4Ruy.com engineering series on AI Skills and Model Context Protocol:
Read the technical article: Β«CΓ³mo Darle Manos a tu IA: QuΓ© es Model Context Protocol (MCP) y GuΓa PrΓ‘ctica para Conectar Herramientas y Bases de DatosΒ»
English version: Β«Giving Hands to Your AI: What is Model Context Protocol (MCP) and a Practical Guide to Connect Tools and DatabasesΒ»
π‘ The Problem: The "House Key" vs. The "Hotel Keycard"
Giving Large Language Models (LLMs) direct, unconstrained database credentials is like handing a stranger the master key to your entire house: they can open personal drawers, read sensitive records, or demolish a wall with a sledgehammer.
MCP Database Guardrail implements the Hotel Keycard Architecture:
Scoped Room Access: The AI agent is only granted access to whitelisted tables and schemas, isolating internal administration and security metadata.
Read-Only Observation: The agent can inspect the table schema and execute analytical read operations (
SELECT,WITH), but is structurally blocked from destructive actions (INSERT,UPDATE,DELETE,DROP,ALTER,TRUNCATE).Resource Safeguards: Enforces hard limits (
LIMIT 50) and strict execution timeouts (10s) to prevent runaway Cartesian joins or memory exhaustion.
βββββββββββββββββββββββββββββββββββ
β AI Host / Agent Client β
β (Claude Desktop, Cursor, etc.) β
ββββββββββββββββββ¬βββββββββββββββββ
β JSON-RPC 2.0 (MCP Protocol)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Database Guardrail Server β
β β
β βββ Resource: Database Schema Inspection (Read-Only) β
β βββ Tool: Safe SQL Execution (AST Guardrail) β
β βββ Prompt: Business KPI Analysis Template β
ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β Strict SELECT / Read-Only Transaction
βΌ
βββββββββββββββββββββββββββββββββββ
β Target Database Engine β
β (SQLite / PostgreSQL / MySQL) β
βββββββββββββββββββββββββββββββββββRelated MCP server: sqlgate-mcp
π Key Features
Zero-Dependency Quickstart: Run locally in 10 seconds with
server_sqlite.py(automatically seeds anempresa_demo.dbdataset).Multi-Engine Support: Ready-to-use production servers for SQLite, PostgreSQL, and MySQL.
AST & Token Guardrails: Programmatic rejection of dangerous keywords, multi-statement injection attempts, and DDL mutations.
Automatic
LIMITEnforcement: AppendsLIMIT 50if omitted by the model, preventing buffer overflows.Native MCP Components:
Resources (
schema): Allows models to understand relational schemas without consuming execution tokens blindly.Tools (
ejecutar_consulta_segura): Controlled query execution returning structured JSON with latency metrics.Prompts (
asistente_kpis_negocio): Standard operating guidelines for autonomous data analysis.
π¦ Installation & Setup
1. Clone the repository
git clone https://github.com/ernestoh0183/mcp-database-guardrail.git
cd mcp-database-guardrail2. Create virtual environment & install dependencies
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Linux/macOS:
source .venv/bin/activate
pip install -e .π οΈ Configuration for AI Clients
Add the server to your favorite MCP-compatible client configuration file:
Claude Desktop (claude_desktop_config.json)
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"sqlite-guardrail": {
"command": "python",
"args": [
"/absolute/path/to/mcp-database-guardrail/server_sqlite.py"
],
"env": {
"SQLITE_DB_PATH": "empresa_demo.db"
}
}
}
}Cursor (.cursor/mcp.json or Settings -> Features -> MCP)
{
"mcpServers": {
"postgres-guardrail": {
"command": "python",
"args": [
"/absolute/path/to/mcp-database-guardrail/server_postgres.py"
],
"env": {
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_DATABASE": "empresa_prod",
"PG_USER": "readonly_ai_user",
"PG_PASSWORD": "your_secure_password_here",
"PG_SCHEMA": "public"
}
}
}
}π§ͺ Quick Test in Terminal
You can test the server directly with the official MCP Inspector:
npx @modelcontextprotocol/inspector python server_sqlite.pyThen ask your AI agent:
"Show me the top 3 best-selling products this month and their total revenue."
The model will:
Inspect
sqlite://schemato locate thepedidosandproductostables.Draft a
SELECTquery withJOINandGROUP BY.Invoke
ejecutar_consulta_segurathrough the MCP protocol.Return an executive summary with verified, grounded figures.
π License & Attribution
This project is licensed under the MIT License - see the LICENSE file for details.
Author: Rodrigo Ernesto HernΓ‘ndez Buitrago
Website: https://www.4ruy.com
LinkedIn: Rodrigo Ernesto HernΓ‘ndez Buitrago
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor β on any device. Read-only, encrypted, audited.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query databases across SQLite, PostgreSQL, MySQL, and MSSQL, with schema introspection, natural language queries, and data profiling.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.484 PyPIMIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to explore and query PostgreSQL or SQLite databases read-only, with SQL allow-listing, automatic row limits, statement timeouts, column masking, per-tool rate limits and JSONL audit logging.MIT