MCPBridge
Provides guarded read/write access to PostgreSQL databases, including query validation, schema exploration, two-phase write confirmation, and audit logging.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCPBridgedescribe the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCPBridge
A production-grade Model Context Protocol server that connects AI assistants (Claude Desktop, Cursor, Windsurf, Claude Code, โฆ) to PostgreSQL โ with the guardrails a real database deserves.

Features
Most database MCP servers are thin wrappers around pool.query(). MCPBridge adds the missing production layer:
๐ก๏ธ Query safety validation โ DDL and multi-statement payloads are blocked; comments, string literals and dollar-quoted strings are stripped before keyword analysis so nothing can be smuggled past the validator; reads additionally run inside
READ ONLYtransactions as defence in depth.โ Two-phase guarded writes โ
write_dbnever executes anything. It stages the statement, estimates the affected rows via the planner, assigns a risk level, and returns aconfirmation_id. Execution happens only throughconfirm_write; high-risk operations (bulk deletes,UPDATEwithoutWHERE) require an explicitacknowledge_risk=true. Unconfirmed writes expire after 10 minutes.๐ Result limiting โ
SELECTwithoutLIMITis automatically capped (default 100 rows) with a warning, soSELECT * FROM eventscan't flood the context window.๐งพ Audit logging โ every operation (success, error, blocked, rate-limited) is appended to a JSONL audit trail with timing, row counts and client identity. Credentials are redacted from every log line and error message. Logs rotate at 10 MB.
๐ฆ Rate limiting โ sliding-window limiter (default 100 requests/minute per client) that rejects before a database connection is consumed.
๐ง Schema intelligence โ row estimates from planner statistics (never
COUNT(*)), foreign-key relationship maps with cardinality, index inventories, column statistics, sample rows โ all behind a 5-minute TTL cache.๐จ Anomaly detection โ
detect_anomaliesscans the audit trail for suspicious usage: bursts of queries against one table, sequential id-enumeration scans, and off-hours activity.
Related MCP server: PostgreSQL MCP Server
Architecture

Feature-based architecture combined with DDD. Each core feature is a bounded context living in its own folder under src/, with its Gherkin specification (.feature), its tests, and DDD layering inside (domain โ application โ infrastructure / presentation). Dependencies point inward within a feature; features depend only on shared/, platform/, and other features' public modules โ never on the composition root.
features/ # Gherkin specifications (Cucumber convention) โ one .feature file per feature
src/
โโโ querying/ # Feature: safe read-only querying
โ โโโ domain/ # SQL lexing, classification, validation, result limiting
โ โโโ application/ # ExecuteQuery, ExplainQuery use cases
โ โโโ presentation/ # query_db / explain_query tools, optimize-query prompt
โ โโโ tests/
โโโ schema-exploration/ # Feature: schema intelligence
โ โโโ domain/ # Table/column/relationship/statistics types
โ โโโ application/ # SchemaService (TTL cache), ListTables, DescribeTable
โ โโโ infrastructure/ # PostgreSQL catalog introspector
โ โโโ presentation/ # list_tables / describe_table tools + schema:// table:// stats:// relations:// resources
โโโ guarded-writes/ # Feature: two-phase confirmed writes
โ โโโ domain/ # PendingWrite aggregate, RiskAssessor
โ โโโ application/ # RequestWrite, ConfirmWrite, RejectWrite
โ โโโ infrastructure/ # In-memory pending-write store
โ โโโ presentation/ # write_db / confirm_write / reject_write tools
โ โโโ tests/
โโโ search/ # Feature: natural-language search
โ โโโ application/ # SearchData use case, SqlGenerator port
โ โโโ infrastructure/ # MCP-sampling SQL generator
โ โโโ presentation/ # search_data tool
โโโ audit/ # Feature: audit trail (JSONL logger, rotation, redaction) + anomaly detection
โ โโโ domain/ # AnomalyDetector: burst / sequential-scan / off-hours heuristics
โ โโโ application/ # AuditService, DetectAnomalies use case
โ โโโ infrastructure/ # JsonlAuditLogger, JsonlAuditReader
โ โโโ presentation/ # detect_anomalies tool
โโโ throttling/ # Feature: rate limiting (sliding window + OperationGate)
โโโ shared/ # Shared kernel: Clock, errors, result envelope, TTL cache, formatting, test fakes
โโโ platform/ # Cross-feature plumbing: zod config, pg pool + gateway, MCP assembly, HTTP transport, composition root
โโโ main.ts # Entrypoint
docker/ # Dockerfile, Dockerfile.dockerignore, docker-compose.yml
docs/ # Architecture, folder structure, setup, development guidesFull documentation lives in docs/: architecture ยท folder structure ยท setup ยท development guidelines.
Tools
Tool | Description |
| Execute read-only SQL. Unbounded queries are capped with a warning. |
| Show the execution plan (optionally |
| Tables/views with estimated row counts and comments. |
| Columns, PK/FKs, indexes, relationships, sample rows, column stats. |
| Natural-language question โ SQL (via MCP sampling) โ validated โ executed. |
| Stage an INSERT/UPDATE/DELETE; returns impact preview + |
| Execute a staged write (high-risk requires |
| Cancel a staged write. |
| Scan the audit trail for suspicious usage patterns (table bursts, id-scan enumeration, off-hours activity). |
Resources & Prompts
schema://{schemaName}โ full schema snapshot (5-minute TTL cache)table://{name}/stats://{table}/relations://{table}โ per-table structure, statistics, relationship mapPrompts:
analyze-table,optimize-query
Prerequisites
Node.js 18 or later
npm (bundled with Node.js)
A reachable PostgreSQL instance (13+) โ or skip this and use the bundled Docker Compose setup, which provisions one with sample data
Quick Start
npm install
npm run buildClaude Desktop / Claude Code
Add to claude_desktop_config.json (or .mcp.json for Claude Code):
{
"mcpServers": {
"mcpbridge": {
"command": "node",
"args": ["/absolute/path/to/mcpbridge/dist/main.js"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb",
"MCPBRIDGE_MODE": "read-only"
}
}
}
}Restart the client โ MCPBridge and its 9 tools appear immediately. Set MCPBRIDGE_MODE=read-write to enable the guarded write flow.
Remote (Streamable HTTP)
MCPBRIDGE_TRANSPORT=http MCPBRIDGE_HTTP_PORT=3920 node dist/main.js
# MCP endpoint: http://localhost:3920/mcpDocker
All Docker assets live in docker/:
docker compose -f docker/docker-compose.yml up # PostgreSQL with sample data + MCPBridge on :3920
docker build -f docker/Dockerfile -t mcpbridge . # image only (repo root as context)Configuration
Everything is environment-driven (see .env.example):
Variable | Default | Purpose |
| โ | PostgreSQL connection string (or use |
|
|
|
|
| Schema used by tools and resources by default |
|
| Cap applied to |
|
| Requests allowed per window per client |
|
| Rate-limit window |
|
|
|
|
| How long a staged write waits for confirmation |
|
| Schema cache TTL |
|
| Estimated affected rows at which a write becomes high-risk |
|
| Connection pool size |
|
| Audit trail path (rotates at 10 MB) |
| โ | Comma-separated extra tables to block (system credential catalogs are always blocked) |
|
|
|
|
| Port for the HTTP transport |
Safety Model
Domain validation (fail closed). Statements are lexed (comments/strings blanked), classified by kind, and checked against forbidden keywords (
DROP,TRUNCATE,ALTER,CREATE,GRANT,COPY, โฆ), credential catalogs (pg_shadow,pg_authid, โฆ), multi-statement payloads, and CTE-smuggled writes (WITH x AS (DELETE โฆ) SELECT โฆ). Anything unclassifiable is rejected.Transactional enforcement. Reads run in
BEGIN TRANSACTION READ ONLYโ PostgreSQL itself rejects any write that slips through. Writes run in their own transaction and roll back on failure.Human confirmation. Writes are staged, previewed (operation, target table, planner row estimate, risk level) and only executed on explicit confirmation โ twice for high-risk operations.
Redaction everywhere. Known secrets, connection-string passwords and
password=pairs are scrubbed from every error message and audit line.
Development
npm run dev # run from source (tsx)
npm test # 81 unit tests (vitest), co-located per feature in <feature>/tests/
npm run typecheck
node scripts/smoke.mjs # end-to-end MCP protocol smoke test over stdioBehavioural specifications live in features/ as Gherkin files โ one per feature (features/safe-querying.feature, features/guarded-writes.feature, โฆ), following the standard Cucumber layout. They document the expected behaviour scenario by scenario and are the reference for the unit tests. See docs/development.md for the full workflow and guidelines.
Roadmap
Core tool set: safe querying, schema intelligence, guarded writes, natural-language search, audit trail, anomaly detection
stdioand Streamable HTTP transportsDocker packaging with sample dataset
Publish package to npm
Persistent pending-write store (currently in-memory, single-instance only)
Additional database engines (MySQL, SQLite)
CI pipeline (lint, typecheck, test) via GitHub Actions
See the open issues for a full list of proposed features and known gaps.
Contributing
Contributions make the open-source community a great place to learn and build. Any contributions are greatly appreciated.
Fork the project
Create your feature branch (
git checkout -b feature/AmazingFeature)Commit your changes (
git commit -m 'Add some AmazingFeature')Push to the branch (
git push origin feature/AmazingFeature)Open a pull request
Please make sure npm test and npm run typecheck pass before opening a PR. See CONTRIBUTING.md and docs/development.md for the full guidelines.
Security
MCPBridge is designed to sit in front of a production database โ if you find a vulnerability, please do not open a public issue. See SECURITY.md for how to report it privately.
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Manul Thanura โ LinkedIn ยท manulthanura.com
Project Link: https://github.com/manulthanura/MCPBridge
Acknowledgements
Best-README-Template โ structure this README is based on
Claude Desktop and Cursor, whose guarded database access flows inspired MCPBridge. MCPBridge is not affiliated with either product.
PostgreSQL is a registered trademark of the PostgreSQL Global Development Group. MCPBridge is not affiliated with the PostgreSQL project.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.90Apache 2.0
- AlicenseNot gradedqualityNot gradedmaintenanceProvides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.1
- FlicenseNot gradedqualityDmaintenanceActs as a secure bridge connecting PostgreSQL databases to AI models, enabling natural language querying, schema analysis, and controlled write operations with multi-layer security.
- AlicenseNot gradedqualityCmaintenanceSecurely connect AI assistants to PostgreSQL databases with read-only access, schema discovery, querying, and performance analysis tools.9MIT
Related MCP Connectors
Query PostgreSQL databases in plain English โ LLM-generated, safety-validated SQL.
The grounded data layer for any LLM: governed SQL, metrics, lineage and catalog over your data.
Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/manulthanura/MCPBridge'
If you have feedback or need assistance with the MCP directory API, please join our Discord server