dblink
dblink is an MCP server that gives an agent a uniform toolset to connect to PostgreSQL, MySQL, Redis, SQLite, and MongoDB and inspect, query, and write data with read-only guardrails.
Open/reuse labeled database connections, close them, and list active connection status; connections are read-only by default.
Run read-only SQL queries (SELECT/SHOW/EXPLAIN/read-only WITH) with parameters and row limits, and run write statements via
db_executeonly on writable connections.List tables/views and describe table columns and indexes.
Run read-only allow-listed Redis commands; Redis writes return
UNSUPPORTED.Query MongoDB documents with
mongo_find, run aggregation pipelines (read-only connections reject$out/$merge), write with insert/update/delete, list collections, and describe collections.Use supported DSNs such as PostgreSQL, MySQL, Redis, MongoDB, and SQLite; run over stdio or authenticated HTTP; results have row/result-size limits, timeouts, and uniform error shapes.
Provides tools for querying documents, running aggregation pipelines, performing writes, listing collections, and describing collections with sampled documents and indexes.
Enables agents to connect to MySQL databases, run read-only queries or write operations, list and describe tables, and manage connections with pooling and result limits.
Enables agents to connect to PostgreSQL databases, run read-only queries or write operations, list and describe tables, and manage connections with pooling and result limits.
Allows agents to connect to Redis and execute read-only commands through an allow-list, using the same uniform connection and tool interface.
Allows agents to connect to SQLite file or in-memory databases, run queries and write operations, and inspect tables and schemas.
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., "@dblink connect to postgres and list the tables in the public schema"
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.
dblink
A Model Context Protocol (MCP) server that lets an agent talk to multiple databases through a small, uniform tool surface: PostgreSQL, MySQL, Redis, SQLite and MongoDB.
open_connection(dsn) ──▶ connection_id ──▶ db_query / db_execute / db_list_tables / db_describe_table / redis_command / mongo_find / mongo_aggregate / mongo_write / mongo_list_collections / mongo_describe_collection ──▶ close_connectionInstall & run
# stdio (default, no auth — for local use)
npx @fb0sh/dblink
# HTTP (requires a bearer token; refuses to start without one)
DBLINK_HTTP_TOKEN=change-me npx @fb0sh/dblink --http 7331Prefer a container? See Docker (container MCP) for the published ghcr.io/fb0sh/dblink image and MCP client config.
Related MCP server: mcp-database-universal
CLI
dblink # stdio server (default)
dblink serve --host 0.0.0.0 --port 7331 --token xxx # HTTP server
dblink client --url http://127.0.0.1:7331/mcp --token xxx # interactive REPL
dblink client --list # list tools
dblink client --tool db_query --args '{"connection_id":"conn_x","sql":"select 1"}'dblink serve requires a token (--token or DBLINK_HTTP_TOKEN) and refuses to start without one. dblink client is a thin MCP client for manual testing and scripts.
MCP client config (stdio) example:
{
"mcpServers": {
"dblink": { "command": "npx", "args": ["-y", "@fb0sh/dblink"] }
}
}Docker (container MCP)
The image runs the same MCP server. Default is stdio (the MCP client spawns the container); serve switches it to MCP Streamable HTTP.
Published image (public, linux/amd64): ghcr.io/fb0sh/dblink:2.1.0 (also :2 and :latest).
docker pull ghcr.io/fb0sh/dblink:2.1.0Build locally instead (equivalent, tagged dblink:local):
docker build -t dblink:local .MCP client config — stdio (container)
{
"mcpServers": {
"dblink": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/fb0sh/dblink:2.1.0"]
}
}
}Use dblink:local in place of the image if you built it locally. The client must attach stdin (-i) and must not allocate a TTY (-t).
MCP client config — Streamable HTTP
docker run -d --name dblink \
-p 7331:7331 \
-e DBLINK_HTTP_TOKEN=change-me \
ghcr.io/fb0sh/dblink:2.1.0 serve{
"mcpServers": {
"dblink": {
"url": "http://127.0.0.1:7331/mcp",
"headers": { "Authorization": "Bearer change-me" }
}
}
}serve requires DBLINK_HTTP_TOKEN and refuses to start without it. Releases publish on vX.Y.Z tags via the release-image workflow (X.Y.Z, X, latest). GHCR starts new packages private — after the first publish, set the package visibility to Public once in the package settings.
GET/HEAD /healthz is an unauthenticated liveness probe (returns {"ok":true}); every other path, including /mcp, still requires the Bearer token.
SQLite persistence — mount a volume at /data and use a file DSN:
docker run -i --rm -v dblink-data:/data ghcr.io/fb0sh/dblink:2.1.0
# inside the session: open_connection with dsn "sqlite:/data/app.db"The image sets DBLINK_BIND=0.0.0.0 (unlike the bare-metal default 127.0.0.1). If you override the port with --port, set DBLINK_PORT to match so the container HEALTHCHECK probes the right port. The HEALTHCHECK probes the bind address (DBLINK_BIND, or 127.0.0.1 when bound to 0.0.0.0) and cannot detect a serve whose process is alive but listener has died.
Library usage (integration)
Hold one MCP session instead of reconnecting per call:
import { createDblinkClient } from "@fb0sh/dblink/client";
const dblink = await createDblinkClient({
url: "http://127.0.0.1:7331/mcp",
token: process.env.DBLINK_HTTP_TOKEN,
});
const tools = await dblink.listTools();
const opened = await dblink.call("open_connection", { dsn: "sqlite::memory:" });
const rows = await dblink.call("db_query", {
connection_id: opened.json.connection_id,
sql: "select 1 as v",
});
await dblink.close();createDblinkClient keeps the session alive (one initialize handshake). Use callOnce(...) for fire-and-forget scripts.
Tools
Tool | Purpose |
| Open/reuse a connection, return |
| Close and release |
| Alive/dead status of active connections |
| Read-only SQL |
| Write SQL (needs |
| List tables/views |
| Columns + indexes |
| Read-only Redis commands (allow-list) |
| Query documents (relaxed EJSON) |
| Aggregation pipeline (no |
| insert/update/delete (writable connections only) |
| List collections |
| Sample document, indexes, inferred fields |
Supported DSN schemes: postgres://, postgresql://, mysql://, redis://, rediss://, mongodb://, mongodb+srv://, sqlite: (file or :memory:).
Configuration (environment)
Variable | Default | Meaning |
| — | Required when |
|
| Bind address; |
|
| HTTP port (or pass |
|
| Max clients per pool |
|
| Idle pool eviction (15 min) |
|
| Max distinct connection pools per process |
Limits: 100 rows by default (max 1000), 256 KB per result, 30 s statement timeout. Truncated results return truncated: true.
Errors are uniform: { ok: false, error: { code, message, hint? } } with code ∈ CONN_NOT_FOUND | CONN_CLOSED | READ_ONLY_VIOLATION | SQL_ERROR | TIMEOUT | LIMIT_EXCEEDED | UNSUPPORTED.
Security — read this
read_onlyis not a security boundary. The real boundary is the database account. Use a read-only database user for read-only connections. The built-in SQL guard (single statement, no DDL/DML, noSELECT ... INTO) is best-effort and can be bypassed (CTEs, functions, comments, etc.). Seedocs/adr/0003-read-only-boundary.md.DSNs are passed by the agent and transit the model context; the server itself never writes plaintext credentials to its logs.
HTTP is fail-closed: without
DBLINK_HTTP_TOKENthe server refuses to start. Default bind is127.0.0.1; exposing it on0.0.0.0is your call and requires the token to be protected.stdio transport is unauthenticated by design (local, single user).
Development
npm install
npm run build # tsc -> dist/
npm test # unit tests (SQLite + fakes); docker tests skipped
docker compose up -d # postgres/mysql/redis for integration
DBLINK_TEST_PG_DSN=postgres://dblink:dblink@127.0.0.1:55432/dblink \
DBLINK_TEST_MYSQL_DSN=mysql://dblink:dblink@127.0.0.1:53306/dblink \
DBLINK_TEST_REDIS_DSN=redis://127.0.0.1:56379 \
DBLINK_TEST_MONGO_DSN=mongodb://127.0.0.1:57017/dblink \
npm run test:integrationSee docs/adr/ for design decisions, GLOSSARY.md for vocabulary, and .scratch/dblink/ for the spec and tickets.
Available Tools
13 toolsclose_connectionC
Close a connection and release its pool.
Inputs: connection_id (required).
db_describe_tableB
Describe a table: columns (name/type/nullable/default) and indexes.
Inputs: table (required), connection_id (required), schema.
db_executeB
Run a write statement on a writable connection (read_only=false). Returns affected_rows.
Inputs: sql (required), connection_id (required), params.
db_list_tablesC
List tables/views in the connected database.
Inputs: connection_id (required), schema.
db_queryB
Run a read-only SQL statement (SELECT/SHOW/EXPLAIN/read-only WITH) and return rows.
Inputs: sql (required), connection_id (required), limit, params.
list_connectionsA
List active connections with alive/dead status.
Inputs: no named parameters.
mongo_aggregateC
Run a MongoDB aggregation pipeline. Read-only connections reject $out/$merge.
Inputs: pipeline (required), collection (required), connection_id (required), limit, +1 more.
mongo_describe_collectionB
Describe a MongoDB collection: sample document (EJSON), indexes and inferred fields.
Inputs: collection (required), connection_id (required), database.
mongo_findC
Query documents from a MongoDB collection. filter/projection/sort accept relaxed EJSON. Returns relaxed EJSON documents.
Inputs: collection (required), connection_id (required), sort, limit, +3 more.
mongo_list_collectionsC
List collections in a MongoDB database.
Inputs: connection_id (required), database.
mongo_writeB
Write to MongoDB (action: insert|update|delete). Only allowed on writable connections (read_only=false).
Inputs: action (required), payload (required), collection (required), connection_id (required), +1 more.
open_connectionA
Open (or reuse) a database connection. Returns a connection_id used by the other tools. DSN schemes: postgres://, mysql://, redis://, mongodb://, mongodb+srv://, sqlite:
Inputs: dsn (required), name, read_only.
redis_commandB
Run a read-only Redis command (allow-list). Writes return UNSUPPORTED.
Inputs: command (required), connection_id (required), args.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
MongoDB, SQL, and Redis operations are clearly separated by tool prefixes and descriptions, so an agent can usually select the right backend. Minor overlap remains between read/query tools like mongo_find, db_query, and redis_command, and between the Mongo/SQL list/describe pairs, but the database family disambiguates them.
Most tools follow a predictable family-prefix plus action pattern: mongo_*, db_*, and connection lifecycle verbs like open_connection/close_connection/list_connections. There are small deviations such as mongo_find vs db_query vs redis_command, but the overall scheme is readable and consistent.
The 13 tools are well-scoped for a multi-database connector, with connection management plus a focused set of read, write, list, and describe operations per backend. No tool appears redundant enough to remove, and the count stays within a manageable range.
The surface covers connection lifecycle, SQL read/write and introspection, MongoDB query/aggregate/write/introspection, and Redis read-only commands. Gaps remain around Redis writes, SQL DDL/transaction operations, and broader MongoDB administration, but core database workflows are covered.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.13MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query databases across SQLite, PostgreSQL, MySQL, and MSSQL, with schema introspection, natural language queries, and data profiling.MIT
- FlicenseNot gradedqualityAmaintenanceEnables LLM agents to connect to and query many database types—including PostgreSQL, MySQL, SQLite, BigQuery, Oracle, MS SQL, and Redshift—through a single unified API. It provides schema retrieval and optimized query execution with normalized schemas for easier natural-language-driven data access.-
- FlicenseNot gradedqualityAmaintenanceEnables LLM agents to connect to and retrieve data from multiple database types through a unified API, with schema normalization, query transformation, and secure connections. Supports PostgreSQL, MySQL, SQLite, BigQuery, Oracle, MS SQL, and Redshift.-