@dhank77/mcp-universal-db
v1.0.5
Published
MCP universal database library
Readme
MCP Universal Database Server
A Model Context Protocol (MCP) server that provides universal database connectivity and operations. This server supports multiple database types and offers a comprehensive set of tools for database management.
Features
This MCP server provides the following tools for database operations:
🔌 Connection Management
- connection: Manage database connections with support for connect, disconnect, and status operations
- Supports lazy connection initialization
- Multi-database type support (MySQL, PostgreSQL, SQLite, etc.)
📊 Data Operations
Query Operations
- query: Execute SELECT queries on the database
- Support for parameterized queries
- Safe SQL execution with prepared statements
- Flexible parameter binding
CRUD Operations
- create: Insert new records into tables
- Key-value pair data insertion
- Confirmation required for safety
- update: Update existing records in tables
- Conditional updates with WHERE clauses
- Key-value pair data updates
- Confirmation required for safety
- delete: Delete records from tables
- Conditional deletion with WHERE clauses
- Confirmation required for safety
Schema Operations
- readSchema: Read database schema information
- Get schema for specific tables or all tables
- Comprehensive table structure information
Configuration
The server supports multiple configuration formats through environment variables. Create a .env file based on the provided .env.example:
Format 1: DSN Direct
DATABASE_URL=mysql://user:pass@localhost:3306/mydb
SUPABASE_DB_URL=postgres://user:[email protected]:5432/postgresFormat 2: Laravel Style
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=secretFormat 3: WordPress Style
DB_NAME=wordpress
DB_USER=wp_user
DB_PASS=wp_password
DB_HOST=localhost
DB_PORT=3306Format 4: Multi Database with Prefix
DB1_CONNECTION=mysql
DB1_HOST=localhost
DB1_PORT=3306
DB1_DATABASE=app1_db
DB1_USERNAME=app1_user
DB1_PASSWORD=app1_pass
DB2_CONNECTION=postgres
DB2_HOST=localhost
DB2_PORT=5432
DB2_DATABASE=app2_db
DB2_USERNAME=app2_user
DB2_PASSWORD=app2_passFormat 5: Docker Style
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DATABASE=docker_mysql
MYSQL_USER=mysql_user
MYSQL_PASSWORD=mysql_pass
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=docker_postgres
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=postgres_passFormat 6: Django Style
DJANGO_DB_ENGINE=django.db.backends.postgresql
DJANGO_DB_HOST=localhost
DJANGO_DB_PORT=5432
DJANGO_DB_NAME=django_db
DJANGO_DB_USER=django_user
DJANGO_DB_PASSWORD=django_passMCP Client Configuration
To connect to this MCP server from an MCP-compatible client, add the following configuration:
{
"mcpServers": {
"dbmcp": {
"command": "npx",
"args": [
"-y",
"@dhank77/mcp-universal-db",
"--transport",
"stdio"
],
"env": {
"DOTENV_CONFIG_PATH": "./.env"
}
}
}
}Make sure your .env file is in the same directory as your MCP client configuration.
Installation
- Clone the repository
- Install dependencies:
npm install - Build the project:
npm run build - Configure your database connection in
.envfile - Start the server:
npm start
Usage
This server is designed to work with MCP-compatible clients. The server communicates via stdio transport and provides all database operations through the MCP protocol.
Example Tool Calls
Check Connection Status
{
"tool": "connection",
"params": {
"action": "status"
}
}Execute a Query
{
"tool": "query",
"params": {
"sql": "SELECT * FROM users WHERE age > ?",
"params": [18]
}
}Insert a Record
{
"tool": "create",
"params": {
"table": "users",
"data": {
"name": "John Doe",
"email": "[email protected]",
"age": 25
},
"confirm": true
}
}Update Records
{
"tool": "update",
"params": {
"table": "users",
"data": {
"age": 26
},
"where": {
"id": 1
},
"confirm": true
}
}Delete Records
{
"tool": "delete",
"params": {
"table": "users",
"where": {
"id": 1
},
"confirm": true
}
}Read Schema
{
"tool": "readSchema",
"params": {
"table": "users"
}
}Safety Features
- Confirmation Required: All destructive operations (create, update, delete) require explicit confirmation
- Parameterized Queries: Support for prepared statements to prevent SQL injection
- Connection Management: Proper connection lifecycle management
- Error Handling: Comprehensive error handling and reporting
Supported Databases
- MySQL
- PostgreSQL
- SQLite
- And other databases supported by the underlying connection libraries
Development
Build
npm run buildTest
npm testDevelopment Mode
npm run devLicense
MIT License
