Unified, read-only interface for executing SQL queries via CLI tools.
DB CLI MCP Server
A Model Context Protocol (MCP) Server that provides a unified, safe, AI-friendly interface for executing read-only database queries across multiple databases via CLI tools.
Features
- Multi-database support — SQL Server, MySQL, MariaDB, PostgreSQL, Oracle
- Read-only enforcement — Strict SELECT-only query execution with fail-closed validation
- Zero-config startup — Server starts even without config files or CLI tools installed
- Auto-detection — Scans project files (.env, appsettings.json, docker-compose.yml, etc.) for DB configs
- Temporary connections — Ephemeral, in-memory-only connections that never touch disk
- CLI tool guidance — Detects missing CLI tools and provides installation instructions
- AI-native — Built for seamless integration with AI IDEs and CLI tools via MCP protocol
Supported Databases
| Database | CLI Tool | Default Port |
|---|---|---|
| SQL Server | sqlcmd |
1433 |
| MySQL | mysql |
3306 |
| MariaDB | mariadb |
3306 |
| PostgreSQL | psql |
5432 |
| Oracle | sqlplus |
1521 |
Installation
Prerequisites
- Node.js 18 or later
- At least one database CLI tool installed (optional — server works without them)
Install via npm
npm install -g @mcp/dbcli-server
Install from source
git clone https://github.com/your-org/dbcli-mcp-server.git
cd dbcli-mcp-server
npm install
npm run build
Quick Start
1. Run the server
# Via npx (no install needed)
npx @mcp/dbcli-server --stdio
# Or if installed globally
dbcli-mcp-server --stdio
2. Check system status
Use the doctor tool to verify CLI tools and configuration:
{
"serverVersion": "2.0",
"cliStatus": [
{ "dbType": "mssql", "cli": "sqlcmd", "installed": true, "version": "17.10" },
{ "dbType": "mysql", "cli": "mysql", "installed": false }
],
"issues": ["mysql not installed"]
}
3. Run a query
// Input
{ "sql": "SELECT * FROM users LIMIT 10" }
// Output
{
"success": true,
"columns": ["id", "name", "email"],
"rows": [
{ "id": "1", "name": "Alice", "email": "alice@example.com" }
],
"rowCount": 1,
"truncated": false
}
AI IDE & CLI Integration
Claude Code
Claude Code supports MCP servers natively.
Setup
Add the server to your Claude Code MCP configuration:
claude mcp add dbcli -- npx @mcp/dbcli-server --stdio
Or manually edit ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"dbcli": {
"command": "npx",
"args": ["@mcp/dbcli-server", "--stdio"]
}
}
}
Usage
Once configured, you can ask Claude Code directly:
> Query the users table to show the first 10 records
> Check which database CLI tools are installed on my system
> Create a temporary connection to my local MySQL database
> Scan this project for database configurations
Codex CLI
Codex CLI supports MCP protocol integration.
Setup
Add to your Codex CLI configuration file ~/.codex/config.json:
{
"mcpServers": {
"dbcli": {
"command": "npx",
"args": ["@mcp/dbcli-server", "--stdio"]
}
}
}
Usage
codex "Query the users table in my local SQL Server database"
codex "What database configurations exist in this project?"
Cursor
Cursor supports MCP servers for AI-assisted development.
Setup
- Open Cursor Settings:
Ctrl+Shift+J(Windows/Linux) orCmd+Shift+J(macOS) - Navigate to MCP section
- Click "Add new MCP server"
- Fill in the configuration:
{
"mcpServers": {
"dbcli": {
"command": "npx",
"args": ["@mcp/dbcli-server", "--stdio"]
}
}
}
Or manually edit .cursor/mcp.json in your
Tools (2)
doctorVerifies CLI tools and configuration statusqueryExecutes a read-only SQL query against a databaseConfiguration
{"mcpServers": {"dbcli": {"command": "npx", "args": ["@mcp/dbcli-server", "--stdio"]}}}