Database Mcp — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Database Mcp (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Connect AI agents to any SQL database using the Model Context Protocol (MCP).
DB-MCP is a Python-based MCP server that lets AI agents query, analyze, and interact with your databases through natural language. Supports PostgreSQL, MySQL, SQL Server, and SQLite.
# Install from PyPI
pip install db-mcp
# Generate example configuration
db-mcp --init
# Edit config.json with your database details
# Then run the server
db-mcp --config config.jsonfrom db_mcp.config import Config
from db_mcp.database import DatabaseManager
config = Config("config.json")
db = DatabaseManager(config.get_database("my_database"))
result = db.execute_query("SELECT * FROM users")
if result["success"]:
print(result["data"])
db.close()That's it! Now configure your AI agent to connect to the server (see below).
graph LR
A[AI Agent] -->|MCP Protocol| B[DB-MCP Server]
B -->|SQLAlchemy| C[PostgreSQL]
B -->|SQLAlchemy| D[MySQL]
B -->|SQLAlchemy| E[SQLite]
B -->|SQLAlchemy| F[SQL Server]
G[config.json] -.->|Configuration| B
H[.env] -.->|Credentials| B
style A fill:#4CAF50
style B fill:#2196F3
style C fill:#336791
style D fill:#4479A1
style E fill:#003B57
style F fill:#CC2927Components:
sequenceDiagram
participant Agent as AI Agent
participant MCP as DB-MCP Server
participant Pool as Connection Pool
participant DB as Database
Agent->>MCP: Natural Language Query
Note over MCP: Parse request & validate
MCP->>MCP: Security Check<br/>(read-only mode?)
MCP->>Pool: Request connection
Pool->>DB: Execute SQL
DB->>Pool: Return results
Pool->>MCP: Results (max 100 rows)
MCP->>MCP: Format results as JSON
MCP->>Agent: Structured response
Note over Agent: Agent processes and<br/>presents to userFlow Steps:
pip install db-mcpInstall the drivers you need for your database(s):
# For PostgreSQL
pip install psycopg2-binary
# For MySQL
pip install mysql-connector-python
# For SQL Server (Windows only)
pip install pyodbcNote: SQLite support is built-in, no additional driver needed.
Generate an example config file:
db-mcp --initThis creates a config.json file with examples for all database types. Edit it with your actual database details:
{
"databases": {
"my_database": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"database": "mydb",
"username": "user",
"password": "password",
"read_only": true
}
}
}Supported database types: postgresql, mysql, sqlite, mssql
Important: Remove database entries you don't need from config.json
Run the server to make sure it connects:
db-mcp --config config.jsonYou should see:
==================================================
DB-MCP Server Starting...
==================================================
Loaded 1 database(s): my_database
Connected to database 'my_database' (postgresql)
Server ready and listening for connections
==================================================Press Ctrl+C to stop the test.
#### For Claude Desktop
Edit your Claude Desktop config file:
Windows: %APPDATA%\Claude\claude_desktop_config.json Mac: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json
Add this configuration:
Windows:
{
"mcpServers": {
"database": {
"command": "db-mcp",
"args": [
"--config",
"C:\\path\\to\\your\\config.json"
]
}
}
}Mac/Linux:
{
"mcpServers": {
"database": {
"command": "db-mcp",
"args": [
"--config",
"/path/to/your/config.json"
]
}
}
}Important: Use absolute paths for config.json location.
#### For Other MCP-Compatible Agents
Configure according to your agent's MCP server setup instructions. The server communicates via standard MCP protocol over stdio.
Completely restart your AI agent to load the MCP server.
Once connected, you can ask your agent questions like:
Your agent will automatically use the appropriate tools to query your database.
{
"databases": {
"database_name": {
"type": "postgresql", // Required: postgresql, mysql, sqlite, mssql
"host": "localhost", // Required for all except SQLite
"port": 5432, // Optional: default port for each DB type
"database": "dbname", // Required: database name
"username": "user", // Required for most databases
"password": "pass", // Required for most databases
"read_only": true, // Optional: default true (recommended)
"pool_size": 5, // Optional: connection pool size (default 5)
"max_overflow": 2, // Optional: max extra connections (default 2)
"pool_timeout": 30 // Optional: connection timeout (default 30s)
}
}
}{
"databases": {
"my_sqlite": {
"type": "sqlite",
"path": "./database.db", // Path to SQLite file
"read_only": false // SQLite can be read-write
}
}
}You can reference environment variables in your config (recommended for passwords):
{
"databases": {
"prod": {
"type": "postgresql",
"host": "localhost",
"username": "$DB_USER", // Will read from environment
"password": "$DB_PASSWORD" // Will read from environment
}
}
}Create a .env file:
DB_USER=myuser
DB_PASSWORD=mysecurepasswordYour AI agent has access to these 5 tools:
list_databasesLists all configured databases.
get_schemaGet database schema information.
execute_queryExecute SQL queries (SELECT only in read-only mode).
explain_queryGet query execution plan without running the query.
get_table_sampleQuick preview of table data.
PostgreSQL:
CREATE USER readonly_user WITH PASSWORD 'password';
GRANT CONNECT ON DATABASE mydb TO readonly_user;
GRANT USAGE ON SCHEMA public TO readonly_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_user;MySQL:
CREATE USER 'readonly_user'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT ON mydb.* TO 'readonly_user'@'localhost';⚠️ WARNING: Write access allows your AI agent to modify data!
To allow INSERT, UPDATE, DELETE operations:
"read_only": false in config.jsonTo allow INSERT, UPDATE, DELETE operations:
"read_only": false in config.jsonSee WRITE_ACCESS_GUIDE.md for detailed instructions and safety tips.
db-mcp/
├── src/
│ └── db_mcp/
│ ├── __init__.py # Package initialization
│ ├── server.py # Main MCP server
│ ├── database.py # Database connection manager
│ ├── tools.py # MCP tool definitions
│ └── config.py # Configuration handling
├── config.example.json # Example configuration
├── requirements.txt # Python dependencies
├── setup.py # PyPI packaging
└── README.md # This file# Test with SQLite (no setup required)
echo '{"databases": {"test": {"type": "sqlite", "path": ":memory:", "read_only": false}}}' > test_config.json
python src/db_mcp/server.py --config test_config.jsonDB-MCP can connect to multiple databases simultaneously:
{
"databases": {
"prod_postgres": {
"type": "postgresql",
"host": "prod.server.com",
"database": "production",
"read_only": true
},
"staging_mysql": {
"type": "mysql",
"host": "staging.server.com",
"database": "staging",
"read_only": false
},
"local_sqlite": {
"type": "sqlite",
"path": "./local.db",
"read_only": false
}
}
}Your agent can then specify which database to query:
Adjust pool settings based on your workload:
{
"pool_size": 10, // Max persistent connections
"max_overflow": 5, // Additional connections during spikes
"pool_timeout": 30, // Wait time for available connection
"pool_recycle": 3600 // Recycle connections after 1 hour
}explain_query tool to analyze query performancepool_size in configread_only: false if you need write accessdb-mcp --init to generate example configpip install db-mcppython -m db_mcp.server --config config.json| Database | Driver | Connection String Format |
|---|---|---|
| PostgreSQL | psycopg2 | postgresql://user:pass@host:port/db |
| MySQL | mysql-connector-python | mysql+mysqlconnector://user:pass@host:port/db |
| SQLite | built-in | sqlite:///path/to/file.db |
| SQL Server | pyodbc | mssql+pyodbc://user:pass@host:port/db?driver=... |
If you want to contribute or modify the code:
# Clone the repository
git clone https://github.com/fenil210/Database-MCP
cd Database-MCP
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
# Install all database drivers
pip install -e ".[all]"db-mcp/
├── src/
│ └── db_mcp/
│ ├── __init__.py # Package initialization
│ ├── server.py # Main MCP server
│ ├── database.py # Database connection manager
│ ├── tools.py # MCP tool definitions
│ └── config.py # Configuration handling
├── requirements.txt # Python dependencies
├── setup.py # PyPI packaging
└── README.md # This file# Test with SQLite (no setup required)
db-mcp --init
# Edit config.json to only include the my_sqlite_db entry
db-mcp --config config.jsonContributions welcome! Feel free to:
MIT License - See LICENSE file for details
For issues and questions:
--init command for easy configurationBuilt with the Model Context Protocol (MCP) by Anthropic. Uses SQLAlchemy for universal database connectivity.
Connect any AI agent to any database with DB-MCP!
Install now: pip install db-mcp
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.