DB-MCP
Supports MariaDB via the MySQL/MariaDB adapter, enabling schema exploration, bounded SQL execution, schema snapshots/diffs, and governed change workflows with audit.
Provides MySQL database integration through the MySQL/MariaDB adapter, enabling schema exploration, bounded SQL execution, schema snapshots/diffs, and governed change workflows with audit.
Provides PostgreSQL database integration with schema exploration, dependency and procedure call-graph analysis, bounded SQL execution and explain plans, health/workload diagnostics and index recommendations, schema snapshots/diffs, and governed change workflows with audit.
Provides SQLite database integration for schema exploration, bounded SQL execution, schema snapshots/diffs, and governed change workflows with audit.
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.
DB-MCP
Self-hosted database MCP server written in Rust for coding agents (Claude Code, Cursor, Windsurf, Claude Desktop, VS Code, any MCP client).
It combines, in one binary:
Capability | What the agent gets |
Schema exploration |
|
Lineage and call graphs |
|
Bounded SQL |
|
Declarative tools |
|
Database intelligence |
|
Governed changes |
|
Schema snapshots |
|
Governed ontology (v0.2) |
|
Audit | Structured JSONL + SQLite audit trail for every tool call, denial and admin action, with literal-free SQL fingerprints and secret redaction |
Engines:
SQLite: native.
MySQL 8: live server over plain TCP (
mysql_async). A read-only login (GRANT SELECT, SHOW VIEW) is enough; every session runsREAD ONLY.Microsoft SQL Server (2016+ for Query Store, any version detected at connect): live server over TDS with optional encryption (
tiberius+ rustls), named instances, SQL logins. Adb_datareaderlogin is enough; every statement runs insideBEGIN TRAN ... ROLLBACK.PostgreSQL: deterministic embedded simulation (no wire-protocol client yet). MySQL can also be simulated with
backend = "simulated", which the bundled example config uses. Simulated responses always carry a warning, so an agent never mistakes them for production data. Seeresearch/findings/capability-matrix.md.
A live connection that cannot be reached fails with CONNECTION_UNAVAILABLE. It never falls back to the simulation.
Check a connection before you point an agent at it: npx @vinoth_n_3000/db-mcp check-connection --config db-mcp.toml --connection <id>
prints server version, permissions, SELECT 1, object count and a warning if the account can write. Setup, DSN format and
grants per feature: docs/CLIENT-SETUP.md ("Connect to MySQL", "Connect to SQL Server").
Transports: stdio (local agents) and Streamable HTTP JSON-RPC (POST /mcp, Bearer auth, /health, /metrics, /admin/approve, /admin/ontology/review, /admin/ontology/publish).
Quick start
Option A: npx (no Rust toolchain needed)
npx @vinoth_n_3000/db-mcp init # writes ./db-mcp.toml starter config
npx @vinoth_n_3000/db-mcp verify-config --config ./db-mcp.toml
npx @vinoth_n_3000/db-mcp serve --transport stdio --config ./db-mcp.tomlOn first run the launcher downloads the prebuilt db-mcp-server binary for your platform from the
GitHub release matching the package version, verifies its SHA-256,
and caches it under ~/.db-mcp/bin/. If no prebuilt binary exists for your platform it falls back to
cargo install from this repository (requires Rust), or to a binary you point at with DB_MCP_BINARY_PATH. If the .sha256 file cannot be fetched the launcher refuses to install (fail closed); set
DB_MCP_ALLOW_UNVERIFIED=1 to override at your own risk.
Option B: cargo
cargo install --git https://github.com/vinothhacks/db-mcp --locked db-mcp-server
db-mcp-server serve --transport stdio --config ./db-mcp.tomlVerify your install
npx @vinoth_n_3000/db-mcp selftestRuns an end-to-end check of every feature (all tools, HTTP, audit, governed ontology) against a temporary copy of the bundled example config. It never touches your own config, databases or audit logs.
Option C: Docker (self-hosted HTTP)
docker compose up --build # db-mcp on :8080 with the bundled example config
curl -s http://127.0.0.1:8080/healthOption D: from source
git clone https://github.com/vinothhacks/db-mcp && cd db-mcp
npm run build # cargo build --release -p db-mcp-server
npm test # stdio + HTTP + CLI approval end-to-end
npm run verify:features # exercises all 24 tools and prints a feature matrixRelated MCP server: PGScope MCP
Connect your coding agent
The server speaks MCP over stdio. Point your client at the launcher (or the binary) and a config file.
Claude Code
claude mcp add db-mcp -- npx -y @vinoth_n_3000/db-mcp serve --transport stdio --config /abs/path/db-mcp.tomlCursor / Windsurf / Claude Desktop (mcp.json, claude_desktop_config.json)
{
"mcpServers": {
"db-mcp": {
"command": "npx",
"args": ["-y", "@vinoth_n_3000/db-mcp", "serve", "--transport", "stdio", "--config", "/abs/path/db-mcp.toml"],
"env": { "DATABASE_URL": "postgres://user:pass@host:5432/app" }
}
}
}VS Code uses a different shape: .vscode/mcp.json with a top-level "servers" key and "type": "stdio" per
server (not mcpServers). See the VS Code recipe.
More client recipes, HTTP mode and the admin approval flow: docs/CLIENT-SETUP.md.
Configuration
config/db-mcp.example.toml is a complete, validated example. The important parts:
server_name = "db-mcp"
default_mode = "ReadOnly" # Development | ReadOnly | GovernedProduction
active_profiles = ["Explore", "Query", "Diagnose", "Change", "Schema"]
[http]
bind = "127.0.0.1:8080"
auth_token = "env:DB_MCP_AUTH_TOKEN" # Bearer token for POST /mcp (optional)
admin_token = "env:DB_MCP_ADMIN_TOKEN" # Bearer token for POST /admin/approve
[audit]
jsonl_path = "research/traces/audit.jsonl"
sqlite_path = "research/traces/audit.db"
[changes]
storage_path = "research/traces/changes.db"
policy_revision = "policy_v1"
default_ttl_seconds = 3600
approval_key = "env:DB_MCP_APPROVAL_KEY" # HMAC key signing approvals (required for GovernedProduction apply)
[[connections]]
id = "prod-postgres"
engine = "Postgres" # Postgres | MySql | Sqlite
dsn = "env:DATABASE_URL" # literal DSN, env:VAR, or file:/path
mode = "GovernedProduction"
read_only = false
timeout_ms = 10000
max_rows = 500
max_bytes = 1048576
restricted_tables = ["internal_secrets"]
sensitive_columns = ["password_hash", "api_key", "secret_token"]
allowed_roles = ["agent", "developer", "dba", "admin"]
[[named_tools]]
name = "get_user_by_id"
connection = "prod-postgres"
statement = "SELECT id, email, role FROM users WHERE id = ?1"
read_only = true
[[named_tools.parameters]]
name = "user_id"
param_type = "integer"
required = trueValidate any config with db-mcp verify-config --config <file>. Secrets are never echoed: DSNs resolve through
env: / file: references and are redacted in logs, errors and audit records.
Operating modes
Mode | Reads | Writes / DDL | Notes |
| yes | direct | local fixtures, still bounded by limits |
| yes | denied ( | mutating CTEs and privileged functions blocked |
| yes | only via approved | self-approval, replay, hash tampering and schema drift are rejected |
Governed change flow
agent: propose_change -> chg_123 (PENDING, approval_hash)
admin: db-mcp approve --change-id chg_123 --approver release-admin # CLI, or POST /admin/approve
agent: apply_change -> executes once, re-verifies hash + schema fingerprint, auditedpropose_change applies the same connection policy as execute_query (restricted tables, multi-statement,
ReadOnly connections, privileged and administrative statements) and refuses plain reads (NOT_A_CHANGE);
apply_change checks the policy again. Only a pending proposal can be approved, once (CHANGE_NOT_PENDING).
Approvals are signed with an HMAC key (changes.approval_key or DB_MCP_APPROVAL_KEY, same key for the server
and db-mcp approve); without a key, GovernedProduction connections refuse apply_change (APPROVAL_KEY_REQUIRED).
Governed ontology (semantic layer)
The ontology turns schema objects into certified business definitions and answers questions only from them. It never lets a model write free-form SQL.
agent: discover_ontology -> unverified candidates (entities, attributes, FK relationships, metrics)
agent: propose_semantic_definition -> typed drafts ("order value" = SUM(orders.total_cents), filters, joins)
reviewer: db-mcp ontology review ... -> certify one exact version (reviewer != proposer, admin/dba role)
reviewer: db-mcp ontology publish ... -> immutable revision pinned to the schema fingerprint
agent: plan_semantic_query -> answerable | not_answerable | ambiguous | stale, with SQL + provenance
agent: ask_semantic_question -> runs the validated plan through the governed executorDefinitions are versioned and immutable; only their lifecycle status changes (
discovered -> proposed -> certified -> published -> stale/deprecated, orrejected).Certifications bind the definition content hash, schema fingerprint, reviewer and expiry (optionally HMAC-signed with
ontology.review_key).Plans refuse instead of guessing: no certified metric, ambiguous metric names, unknown dimensions, sensitive columns and one-to-many joins that would double count all return
not_answerableorambiguous.Schema drift (dropped or retyped columns) marks dependent definitions
stale; they stop generating SQL until re-certified, and pinnedplan_hashvalues stop matching.Restricted tables never enter the ontology; sensitive columns can be described but never used as filters, metrics or grouping keys.
Store: a dedicated SQLite metadata database (
[ontology] storage_path), never the business database.
Admin channel (never exposed to agents):
db-mcp ontology list --connection local-sqlite --status discovered --config db-mcp.toml
db-mcp ontology review --connection local-sqlite --def-id metric:order_value --version 1 --action approve --reviewer alice --config db-mcp.toml
db-mcp ontology publish --connection local-sqlite --reviewer alice --config db-mcp.toml
db-mcp ontology eval --connection local-sqlite --cases research/ontology/golden-local-sqlite.json --config db-mcp.toml
# or over HTTP with the admin token: POST /admin/ontology/review, POST /admin/ontology/publishDesign, security model and contracts: docs/ontology/architecture.md, docs/ontology/security.md, docs/ontology/contract.md.
Tool reference
Explore:
list_connections,search_objects,describe_object,trace_table_dependencies,get_procedure_call_graphQuery:
execute_query,explain_query,run_named_toolDiagnose:
database_health,analyze_workload,recommend_indexesChange:
propose_change,get_change,apply_changeSchema:
capture_schema,diff_schemaOntology:
ontology_status,discover_ontology,search_terms,describe_term,trace_semantic_relationships,propose_semantic_definition,plan_semantic_query,ask_semantic_question
Every success response carries the same envelope: request_id, connection, status, columns, rows,
returned_rows, truncated, warnings, schema_version, plus _meta.provenance.untrusted_content = true so
agents treat database content as data, not instructions. Denials are structured: status: "denied", code,
message, next_action. Full contracts: research/contracts/tool-contracts.json.
Call any tool from a shell for debugging:
node scripts/mcp-call.js --config config/db-mcp.example.toml trace_table_dependencies '{"connection":"local-sqlite","table_name":"users","target_table":"order_items"}'
node scripts/mcp-call.js --raw tools/listRepository layout
crates/ 16 Rust crates (core, secrets, sql, catalog, policy, audit, executor, tools,
sqlite, postgres, mysql, pg-insights, changes, ontology, mcp, server)
npm/bin/db-mcp.js npx launcher: resolves, downloads or builds the native binary
npm/test/ Node end-to-end suite (stdio, HTTP, CLI approval)
scripts/ mcp-call.js (ad-hoc client), feature-smoke.js (all-feature verification)
config/ example configuration
docs/ client setup, feature verification report
research/ contracts, capability matrix, provenance, license inventory
tests/ contract, integration and adversarial-security suite indexes (run by cargo)Development
cargo test --workspace # unit + contract + adversarial security + runtime integration
npm test # Node E2E over the npx launcher
npm run verify:features # feature matrix (used by CI)License
Dual-licensed under MIT or Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.
Reference projects studied during design (DBHub, Postgres MCP Pro, Google MCP Toolbox, Bytebase) are documented in
research/licenses/license-inventory.md; DB-MCP is a clean-room Rust implementation.
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
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Database intelligence, AST SQL injection auditing, query optimization & schema guards.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to execute SQL queries and introspect PostgreSQL schemas, tables, and indexes with read-only safety by default. Supports optional write operations and works with Claude, LangChain, and other agents via stdio or HTTP transports.-
- AlicenseAqualityCmaintenanceEnables AI agents to explore PostgreSQL schemas, run read-only queries, inspect execution plans, and receive evidence-backed SQL diagnostics with reproducible optimization benchmarks over local stdio.51MIT
- AlicenseAqualityBmaintenanceEnables LLM agents to explore schemas, run guarded read-only queries, inspect execution plans and check database health across a fleet of PostgreSQL databases, selecting a connection by id while credentials stay on the server. Supports multiple databases in one session, exposing schema search, table descriptions, health checks and cross-database relationship lookups over stdio MCP.12MIT
- AlicenseNot gradedqualityBmaintenanceLets coding agents run governed SQL against a Databricks SQL warehouse and inspect Unity Catalog metadata over stdio or Streamable HTTP, with persistent operational logs stored in SQLite. Access is read-only by default and bounded by the configured identity's Unity Catalog permissions.MIT