mcp-database
Connects to MariaDB databases and provides schema discovery, table inspection, row sampling, and read-only parameterised SQL queries, with optional guarded writes when --read-write is enabled.
Connects to MySQL databases and provides schema discovery, table inspection, row sampling, and read-only parameterised SQL queries, with optional guarded writes when --read-write is enabled.
Connects to PostgreSQL databases and provides schema discovery, table inspection, row sampling, and read-only parameterised SQL queries, with optional guarded writes when --read-write is enabled.
Connects to SQLite database files and provides schema discovery, table inspection, row sampling, and read-only parameterised SQL queries, with optional guarded writes when --read-write is enabled.
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
A safe-by-default Model Context Protocol server for PostgreSQL, MySQL/MariaDB and SQLite. Let Claude (or any MCP client) explore your schema and answer questions from your data — without handing it a loaded gun.
Read-only by default. Writes need an explicit
--read-writeflag, and theexecutetool does not even exist until you pass it.Defence in depth. Every query is checked by a SQL guard and runs inside a read-only transaction / read-only connection, so a guard bypass still cannot write.
Built for LLMs. Schema discovery tools, parameterised queries, row caps, statement timeouts, compact JSON output, errors that explain what to do next.
Zero native dependencies. SQLite uses Node's built-in
node:sqlite; Postgres and MySQL use pure-JS drivers.npxjust works.One server, three engines. The connection string decides the dialect.
Quick start
Use a database account that can only SELECT (see Create a read-only role).
Claude Desktop — claude_desktop_config.json:
{
"mcpServers": {
"database": {
"command": "npx",
"args": ["-y", "@aranshayan/mcp-database"],
"env": { "DATABASE_URL": "postgres://readonly:secret@localhost:5432/mydb" }
}
}
}Claude Code:
claude mcp add database --env DATABASE_URL=postgres://readonly:secret@localhost:5432/mydb -- npx -y @aranshayan/mcp-databaseCursor / VS Code / any MCP client: run npx -y @aranshayan/mcp-database as a stdio server with DATABASE_URL in its environment.
Engine |
|
PostgreSQL |
|
MySQL / MariaDB |
|
SQLite |
|
Requires Node.js 22.13+.
Related MCP server: mcp-sqlite-insights
Tools
Tool | What it does |
| Schemas / databases on the connection. |
| Tables and views with type and estimated row count. |
| Columns (type, nullability, default, primary key, comment), indexes, foreign keys. |
| Preview the first 1–100 rows of a table. |
| Run one read-only statement ( |
| Only with |
All read tools are annotated readOnlyHint; execute is annotated destructiveHint so clients can ask for confirmation.
Options
Flag | Environment | Default | |
(url) / |
| — | Connection string. Prefer the environment variable: command-line arguments are visible in process lists. |
|
| off | Enables |
|
| off | With |
|
| 200 | Rows returned per query (max 5000). |
|
| 15000 | Statement timeout. |
Safety model
Three independent layers, so no single bug is fatal:
SQL guard (
src/sql-guard.ts). Comments, string literals and quoted identifiers are stripped per dialect (MySQL#and--␠comments, PostgreSQL dollar-quoting and nested comments, SQLite[brackets]…), then the statement must be a single statement of an allowed kind. Rejected outright: multiple statements,COPY,CALL,SET,ATTACH,SELECT … INTO OUTFILE,LOAD_FILE(),pg_read_file(),load_extension(), SQLitePRAGMAassignment, MySQL/*! … */executable comments, and more.UPDATE/DELETEwithoutWHEREis refused in read-write mode.Engine-level read-only.
PostgreSQL:
BEGIN READ ONLY+SET LOCAL statement_timeout, results streamed through a cursor.MySQL:
SET SESSION TRANSACTION READ ONLY+START TRANSACTION READ ONLY+MAX_EXECUTION_TIME. (The session-level setting matters: MySQL DDL commits implicitly and would otherwise escape a plain read-only transaction. This is covered by a test.)SQLite: the file is opened
readOnlyandPRAGMA query_only = ON.
Your database account. The guard and read-only mode are defences, not a substitute for least privilege. Connect with a role that can only read what the model should see.
Errors are scrubbed of the connection string and password before they reach the model, and the server never logs to stdout (reserved for the protocol).
Create a read-only role
-- PostgreSQL
CREATE ROLE mcp_readonly LOGIN PASSWORD 'change-me';
GRANT CONNECT ON DATABASE mydb TO mcp_readonly;
GRANT USAGE ON SCHEMA public TO mcp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mcp_readonly;
-- MySQL
CREATE USER 'mcp_readonly'@'%' IDENTIFIED BY 'change-me';
GRANT SELECT ON mydb.* TO 'mcp_readonly'@'%';Known limits
SQLite has no query timeout.
node:sqliteruns synchronously and cannot interrupt a statement; a runaway recursive CTE blocks the server. The row cap bounds memory, not time.MySQL buffers a result set before the row cap is applied (
mysql2has no server-side cursor). Keep aLIMITin large queries.MAX_EXECUTION_TIMEbounds time.Only the first statement type is classified; the engine-level read-only layer is what ultimately prevents writes through exotic constructs.
EXPLAIN ANALYZEactually executes the statement. It is classified by the statement it wraps, and in read-only mode a wrapped write is rejected.
What is tested
npm test runs 100+ tests, including:
the SQL guard against comment/string/dollar-quote smuggling tricks, per dialect;
SQLite through
node:sqlite;PostgreSQL against a real Postgres engine (PGlite behind a TCP socket) through the real
pgdriver, including cursors;MySQL against a real server (set
TEST_MYSQL_URLto a scratch database; skipped otherwise). Developed against MySQL 9.3;the built CLI over stdio, exactly as an MCP client launches it.
Not covered by automated tests: PostgreSQL statement_timeout enforcement (PGlite is single-threaded and cannot interrupt a statement; the test verifies the limit is applied to the session) and MariaDB-specific code paths (max_statement_time, schemas without STATISTICS.EXPRESSION).
Development
npm install
npm test # unit + integration + e2e
npm run typecheck
npm run build # bundles to dist/index.js
# optional: also run the MySQL suite against a scratch database
TEST_MYSQL_URL=mysql://user:pass@127.0.0.1:3306/scratch npm testLicense
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
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables read-only, SELECT-only querying of any Postgres database through MCP-compatible clients like Claude, with schema introspection and guarded SQL execution.MIT
- AlicenseNot gradedqualityBmaintenanceEnables Claude and other MCP clients to map a SQLite database's schema and run read-only SQL queries against it, with writes blocked at the SQLite level through multiple enforcement layers. Results come back as context-friendly Markdown tables with row caps and a query timeout.2MIT
- AlicenseNot gradedqualityCmaintenanceEnables Claude and other MCP clients to inspect a local SQLite database's tables, columns, and schema, and run safe read-only SQL queries with capped JSON results.MIT
- AlicenseAqualityCmaintenanceEnables Claude to discover PostgreSQL schemas and run validated, read-only analytical SQL across independent databases through MCP tools with bounded results.5MIT