MCP Database Server
Planned integration to replace SQLite with PostgreSQL via SQLAlchemy for future data storage.
Provides read-only access to SQLite databases with an allowlist of tables and stored procedures, secured via SQLite's authorizer.
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 Server
Pillar: Protocols & Interoperability
Status: Month 1 - essential
Python MCP server to expose schemas, safe queries, and stored procedures to LLM clients.
Problem
LLMs need to consult corporate databases without receiving broad credentials or the freedom to execute destructive SQL.
Related MCP server: mcp-db-server
MVP
MCP server with FastMCP
Listing of allowed schemas
Read-only queries
Allowlist of stored procedures
Audit of calls
Architecture
MCP server (
mcp.server.MCPServer, tools registered via@mcp.tool())Schema registry (allowlist of tables/columns,
db.py)Read-only authorizer (
sqlite3.Connection.set_authorizer,security.py)Audit logger (trail in memory of each tool call,
audit.py)
Diagram
flowchart LR
A0[MCP client] --> A1[MCP server: list_tables / describe_table / run_readonly_query]
A1 --> A2[SQLite authorizer: allowlist + read-only]
A2 --> A3[SQLite: invoices]
A1 --> A4[Audit log]Stack
Python
mcp(official Model Context Protocol SDK)SQLite (
sqlite3from the stdlib, withset_authorizerfor access control)unittest
Docker Compose
How to run
Real implementation with the official MCP SDK. Access control does not use regex over SQL (easy to bypass) — it uses SQLite's own set_authorizer, which approves or denies each table/column read and each statement type before any row runs. To run the MCP server:
python3.12 -m venv .venv && source .venv/bin/activate
pip install -e .
python -m mcp_database_server # sobe o servidor MCP via stdio
python -m unittest discover -s testsTests
test_security.py: authorizer blocks INSERT/UPDATE/DROP/ALTER, ATTACH, tables outside the allowlist (e.g.,sqlite_master), and stacked statements (SELECT 1; DROP TABLE ...).test_server.py: logic of each tool called directly (without protocol), including that every call generates an audit event.test_integration.py: startspython -m mcp_database_serveras a real subprocess and talks to it viamcp.client.stdio+ClientSession— proves the server actually speaks MCP, not just that the Python functions work.
Risks and decisions
SQL injection and excessive permissions: solved via
set_authorizerat the driver level, not regex.A single SQLite connection is not thread-safe; the MCP server dispatches each tool call into a worker thread, so
ServerState.lockserializes access (real bug found and fixed during implementation, covered bytest_integration.py).MCP tools return
ValueErrorwith a clear message to the LLM client instead of leaking a stack trace.
Next steps
Replace SQLite with PostgreSQL via SQLAlchemy when real data is involved.
Add per-client authentication/allowlist (today any connected MCP client has access to the tools).
Persist the audit log outside the process (today it is only in memory).
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.
Governed SQL access to your databases: redaction, query review and an audit log.
Security layer for AI agents: Retrieve for controlled SQL reads, Guard for allow/deny writes.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to query SQL databases safely with read-only access, allowing schema discovery and SELECT queries while blocking writes and DDL operations.-
- AlicenseNot gradedqualityDmaintenanceEnables LLM clients to query SQL databases via natural language with read-only, AST-validated, and capped queries, ensuring safety guarantees.2MIT
- AlicenseNot gradedqualityCmaintenanceProvides read-only access to databases for MCP-compatible AI tools, allowing schema exploration and SELECT queries without exposing credentials or risking data changes.236 npm3MIT
- AlicenseAqualityCmaintenanceLets an LLM explore a cryptic legacy ERP schema in plain language through a semantic layer (table listing, column descriptions, published dictionary) and run single read-only SELECT queries that return capped results. Enforces safety at the database engine level: only reads are authorized, sensitive columns are masked to NULL, queries are aborted after a few seconds, and every call is written to an append-only audit log.3MIT