Bollard MCP
OfficialProvides safe query execution, schema discovery, intent validation, and session memory for MariaDB databases.
Provides safe query execution, schema discovery, intent validation, and session memory for MongoDB databases (planned Phase 2).
Provides safe query execution, schema discovery, intent validation, and session memory for MySQL databases.
Provides safe query execution, schema discovery, intent validation, and session memory for PostgreSQL databases.
Provides safe query execution, schema discovery, intent validation, and session memory for SQLite databases.
Click on "Deploy 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., "@Bollard MCP Show all tables in my PostgreSQL database"
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.
Bollard MCP 🛡️
An AI-powered, safe database access gateway built on the Model Context Protocol (MCP).
Bollard acts as an intelligent execution proxy between your AI code assistant (Cursor, VS Code, Windsurf, Claude Desktop, OpenAI Codex) and your physical databases — providing safe query execution, dynamic schema discovery, cost-based risk parsing, data leak prevention, and session memory.
How It Works
Bollard sits as a transparent intermediary layer between your AI development client and your target database. When the client executes database tools, the requests are statically evaluated, authorized, and structured to optimize context window tokens before the database engine sees them.
Before Bollard vs. With Bollard
Workflow Aspect | Before Bollard (Direct SQL Assistant) | With Bollard (Safe Database Gateway) |
Schema Context | Relies on manually pasted schema blocks, leading to hallucinated queries on outdated schemas. | Inspects schemas dynamically, caching metadata and profiles to feed the LLM accurate context. |
Execution Safety | AI directly runs generated queries. High risk of accidental data modification, deletion, or drops. | Risk levels (LOW to EXTREME) are computed statically. Destructive operations are safely blocked. |
Human-in-the-Loop | None. Large batch updates or structural migrations execute immediately without warnings. | Write queries require double confirmation (confirming query matching phrases and typing local PINs). |
Data Leak Prevention | AI can query any table, including sensitive tables (e.g., password hashes, user secrets, API keys). | Access control lists block sensitive tables via connection-level blocklist wildcards. |
Token & Context Usage | Large queries return massive raw rows, flooding the context window and wasting thousands of tokens. | Large queries are compressed into structured summaries with a 10-row preview and column stats (up to 97% token savings). |
Correction Loop | No memory of past mistakes. AI repeats the same syntax/query errors in new sessions. | Custom fixes and deprecated field overrides are persisted and auto-injected as agent instructions. |
Related MCP server: GraphJin
Getting Started
1. Installation
Bollard is written in Python and is available on PyPI:
Global Installation (Recommended for CLI / standalone runtimes):
pipx install bollard-mcpVirtual Environment Installation:
pip install bollard-mcp
2. Client Configurations
Cursor
Go to Cursor Settings > Features > MCP.
Click + Add New MCP Server.
Set the following fields:
Name:
bollardType:
commandCommand:
bollard-mcp(or the absolute path tobollard-mcporpythoninside your virtualenv, e.g.,python -m bollard_mcp.server)
Or edit your Cursor config file directly (~/.cursor/mcp.json):
{
"mcpServers": {
"bollard": {
"command": "bollard-mcp"
}
}
}VS Code (Cline / Roo Code)
Add the configuration to your Cline settings file (located at %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json on Windows):
{
"mcpServers": {
"bollard": {
"command": "bollard-mcp"
}
}
}Windsurf
Add the configuration under your global Windsurf MCP configuration file (~/.codeium/windsurf/mcp_config.json):
{
"mcpServers": {
"bollard": {
"command": "bollard-mcp"
}
}
}Claude Desktop
Add the configuration to your Claude Desktop config file (%APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"bollard": {
"command": "bollard-mcp"
}
}
}OpenAI Codex
Add the server block under the [mcp_servers] table in your Codex configuration file (~/.codex/config.toml):
[mcp_servers.bollard]
command = "python" # or "bollard-mcp" if installed globally via pipx
args = ["-m", "bollard_mcp.server"]
cwd = "/path/to/your/bollard-mcp"💡 Write Operations in Standalone Clients: In standalone clients (like OpenAI Codex or Claude Desktop) that do not run the editor helper extension, Bollard automatically falls back to an In-Chat PIN Gate. When the AI attempts a write query, the server will block execution, generate a local 4-digit verification PIN, and print it directly in the chat. You simply need to copy-paste this PIN back into the chat prompt to authorize and execute the write query safely.
Database Connection Reference
Once Bollard is registered, prompt your AI agent inside your chat client to connect.
Connection Prompts
General Connect:
"Connect to my local database with alias
local_postgresand connection stringpostgresql://postgres:postgres@localhost:5432/dbcopilot"Connect with a security blocklist:
"Connect to local database with alias
local_postgresatpostgresql://postgres:postgres@localhost:5432/dbcopilotand forbid access touser_secrets"
Local Docker Testing & Seeding
If you are testing database safety gates locally using a Docker PostgreSQL container:
Make sure your local Docker container is running:
docker psSeed the database tables (
users,orders,user_secrets) by running our seeding script:python examples/create_postgres_test_db.pyPrompt the agent in chat to connect and query (e.g. query
user_secretsto verify the blocklist intercepts the request).
License
Bollard is dual-licensed under:
AGPL-3.0-only for open-source non-commercial use. See LICENSE for details.
Commercial License for commercial production use. If you need custom SLAs, Okta/SSO integrations, or compliance audit log exporting, please contact sales at
pavakstudio@gmail.com.
Available Tools
14 toolsconnect_databaseC
Connect to a database.
Inputs: alias (required), connection_string (required), mode, max_rows, +3 more. Returns: result
describe_tableA
Show full column definitions, types, constraints, and indexes for a table.
Includes: column names, data types, nullable, primary key, unique, foreign keys. The editor AI reads this to understand the exact schema before generating queries.
Inputs: connection (required), table_name (required). Returns: result
disconnectB
Disconnect from a database.
Inputs: alias (required). Returns: result
execute_queryC
Execute a SQL query through the risk-tiered safety pipeline.
Inputs: sql (required), connection (required), pin, confirmed, +2 more. Returns: result
get_correctionsA
Return all logged corrections for a connection.
The editor AI reads this via the bollard://corrections/{alias} MCP Resource automatically. Call this tool directly to inspect them.
Inputs: connection (required). Returns: result
get_query_historyA
Return recent query history for a connection.
Useful for the editor AI to understand what has been executed recently, especially when the user says "run that again" or "fix the last query."
Inputs: connection (required), last_n. Returns: result
get_sample_dataA
Preview a few rows from a table to understand its data shape.
Useful for the editor AI to understand the actual values in the database before generating queries (e.g., what status values exist, date formats, etc.)
Inputs: connection (required), table_name (required), limit. Returns: result
list_connectionsA
List all currently active database connections.
Returns alias, dialect, permission mode, and connection time.
Inputs: no named parameters. Returns: result
list_tablesA
List all tables in the connected database with row counts and sizes.
The editor AI uses this to understand the database structure before generating queries. Schema is served from cache when available.
Inputs: connection (required). Returns: result
log_correctionA
Log a query correction for future AI context.
When the editor AI generates a wrong query and the user corrects it, log the correction here. Bollard persists it and exposes it via the bollard://corrections/{alias} MCP Resource, so the AI automatically learns from past mistakes without the user repeating themselves.
Inputs: note (required), connection (required), original_query (required), corrected_query (required). Returns: result
preview_queryA
Dry-run a query through the full safety + intent pipeline.
Returns:
Safety verdict (SAFE / BLOCKED with reason)
Intent analysis (interpreted intent, assumed filters, ambiguity warnings)
EXPLAIN cost estimate (PostgreSQL only)
Final SQL with auto-LIMIT applied
For bare SELECT * queries on large tables, Bollard will automatically redirect to profile_table to give the AI richer context with fewer tokens.
The editor AI should call this before execute_query for any non-trivial query.
Inputs: sql (required), connection (required). Returns: result
profile_tableA
Generate a statistical profile of a database table.
All aggregation is performed directly in the database via SQL queries. No rows are transferred to local memory. Returns a compact Markdown summary suitable for AI context (< 150 tokens overhead per column).
Includes for every column:
Row count and null percentage
Distinct value count
Min / Max / Avg (numeric and date columns)
Top-5 value distribution for categorical columns (<= 100 distinct values)
Inputs: connection (required), table_name (required). Returns: result
reconnect_savedA
Reconnect to a previously saved connection from the OS Keyring.
Inputs: alias (required). Returns: result
refresh_schemaA
Force a schema cache refresh for a connection.
Call this after CREATE TABLE, ALTER TABLE, or any DDL operation to ensure the AI has up-to-date schema context.
Inputs: connection (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Each tool has a clearly distinct purpose: connection lifecycle (connect/disconnect/list/reconnect), schema introspection (list/describe/sample/profile), query execution (preview/execute), and learning (log/get corrections and history). No two tools overlap in function, and descriptions reinforce the boundaries.
Tool names follow a consistent snake_case verb_noun pattern (e.g., list_tables, describe_table, execute_query), with only minor deviation such as 'disconnect' missing an explicit noun. The verbs are predictable and the pattern is maintainable.
With 14 tools, the server is well-scoped for a database assistant, covering connection management, schema exploration, query execution, and learning features without bloat. Each tool appears to serve a distinct need, and the count fits comfortably within the ideal range.
The tool set covers the core workflow: connect to a database, explore schema, preview and execute queries, and log/retrieve corrections. Minor gaps exist around explicit saved-connection management (e.g., save/delete), but the core AI-assisted querying loop is well supported.
Maintenance
Related MCP Connectors
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI to query and manage PostgreSQL and MongoDB databases through natural language. Supports automatic schema discovery, safe data operations, and network-wide database access with zero-configuration deployment.-
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to query databases using natural language, with automatic schema discovery and SQL compilation.833 npm3,235Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to securely interact with multiple databases (MySQL, PostgreSQL) via natural language queries, with cross-database querying and enterprise-grade security.13 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language querying of SQL databases using AI, supporting multiple database types and automatic schema discovery.1MIT