Database Mcp Server — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Database Mcp Server (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.
A Model Context Protocol (MCP) server that provides database operations as tools for LLM-powered applications. Supports PostgreSQL, MySQL, and MongoDB databases with connection pooling and flexible result formatting.
| Tool | Description |
|---|---|
execute_query | Execute arbitrary SQL queries against the database |
list_databases | List all available databases |
list_tables | List all tables in a database (defaults to configured database) |
describe_table | Get schema information for a specific table |
# Clone the repository
git clone <repository-url>
cd database-mcp-server
# Install dependencies using uv (recommended)
uv pip install -e .
# Or using pip
pip install -e .Copy .env.example to .env and configure the environment variables:
cp .env.example .envThen edit .env with your database credentials and settings:
# Database Configuration
DATABASE_PROVIDER=postgres # or mysql, mongodb
DATABASE_HOST=localhost
DATABASE_PORT=5432 # 3306 for MySQL, 27017 for MongoDB
DATABASE_USER=your_username
DATABASE_PASSWORD=your_password
DATABASE_NAME=your_database
DATABASE_MIN_POOL_SIZE=1
DATABASE_MAX_POOL_SIZE=10
# Server Configuration (optional)
HTTP_HOST=0.0.0.0 # Bind address (defaults to all interfaces)
HTTP_PORT=8080| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_PROVIDER | Yes | - | Database provider: postgres, mysql, or mongodb |
DATABASE_HOST | Yes | - | Database server hostname or IP |
DATABASE_PORT | Yes | - | Database server port (5432 for PostgreSQL, 3306 for MySQL, 27017 for MongoDB) |
DATABASE_USER | Yes | - | Database username |
DATABASE_PASSWORD | No | - | Database password |
DATABASE_NAME | Yes | - | Default database to connect to |
DATABASE_MIN_POOL_SIZE | Yes | - | Minimum pool size for connections |
DATABASE_MAX_POOL_SIZE | Yes | - | Maximum pool size for connections |
HTTP_HOST | No | 0.0.0.0 | HTTP server bind address |
HTTP_PORT | No | 8080 | HTTP server port for MCP |
READ_ONLY_MODE | No | true | Enable read-only mode (blocks write operations) |
By default, the server runs in read-only mode to prevent accidental data modifications. When enabled:
SELECT, SHOW, and DESCRIBE queries are allowedfind, find_one, aggregate, count) are allowedWrite operations like INSERT, UPDATE, DELETE, DROP, CREATE, ALTER are blocked.
To disable read-only mode (allow all operations):
READ_ONLY_MODE=false# Using uv (recommended)
uv run python main.py
# Using Python directly
python main.pyAdd the server to your MCP client configuration:
Using uv (recommended for dependency isolation):
{
"mcpServers": {
"sql": {
"command": "uv",
"args": [
"--directory",
"/path/to/database-mcp-server",
"run",
"python",
"main.py"
]
}
}
}Using Python directly:
{
"mcpServers": {
"sql": {
"command": "python",
"args": ["/path/to/database-mcp-server/main.py"]
}
}
}Direct HTTP Connection:
The server exposes a Streamable HTTP endpoint. Configure your MCP client to connect directly:
{
"mcpServers": {
"sql": {
"url": "http://localhost:8080/mcp"
}
}
}Note: For direct HTTP connections, ensure the server is running and accessible at the specified URL.
#### Common Examples (All Providers)
# List all databases
list_databases()
# List tables/collections in the configured database
list_tables()
# List tables/collections in a specific database
list_tables(database="another_db")
# Describe a table/collection schema
describe_table("users")#### PostgreSQL / MySQL Examples (SQL)
For PostgreSQL and MySQL, use standard SQL syntax:
# Execute a SELECT query
execute_query("SELECT * FROM users WHERE active = true LIMIT 10")
# Execute with specific columns
execute_query("SELECT name, email FROM users WHERE age > 18")
# Get results in Markdown format
execute_query("SELECT name, email FROM users", format_type="markdown")
# INSERT, UPDATE, DELETE queries
execute_query("INSERT INTO users (name, email) VALUES ('John', '[email protected]')")
execute_query("UPDATE users SET status = 'active' WHERE status = 'pending'")
execute_query("DELETE FROM users WHERE inactive = true")
# Join queries
execute_query("""
SELECT u.name, o.order_id
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.active = true
""")#### MongoDB Examples (JSON)
For MongoDB, queries use JSON format with operation type:
# Find documents
execute_query('{"collection": "users", "operation": "find", "filter": {"active": true}, "limit": 10}')
# Find with projection (select specific fields)
execute_query('{"collection": "users", "operation": "find", "projection": {"name": 1, "email": 1}}')
# Find with sorting and pagination
execute_query('{"collection": "users", "operation": "find", "filter": {"active": true}, "sort": {"created_at": -1}, "skip": 0, "limit": 20}')
# Find one document
execute_query('{"collection": "users", "operation": "find_one", "filter": {"_id": "64f8a2b1c9d8e7f6a5b4c3d2"}}')
# Insert a document
execute_query('{"collection": "users", "operation": "insert_one", "document": {"name": "John", "email": "[email protected]", "created_at": "2024-01-15T10:30:00"}}')
# Insert multiple documents
execute_query('{"collection": "users", "operation": "insert_many", "documents": [{"name": "John"}, {"name": "Jane"}]}')
# Update documents
execute_query('{"collection": "users", "operation": "update_one", "filter": {"email": "[email protected]"}, "update": {"$set": {"status": "active"}}}')
execute_query('{"collection": "users", "operation": "update_many", "filter": {"status": "pending"}, "update": {"$set": {"status": "active"}}}')
# Delete documents
execute_query('{"collection": "users", "operation": "delete_one", "filter": {"email": "[email protected]"}}')
execute_query('{"collection": "users", "operation": "delete_many", "filter": {"inactive": true}}')
# Aggregation pipeline
execute_query('{"collection": "orders", "operation": "aggregate", "pipeline": [{"$group": {"_id": "$status", "count": {"$sum": 1}}}]}')
# Count documents
execute_query('{"collection": "users", "operation": "count", "filter": {"active": true}}')Supported MongoDB Operations:
| Operation | Description |
|---|---|
find | Query documents with optional filter, projection, sort, skip, limit |
find_one | Query a single document by filter |
insert_one | Insert a single document |
insert_many | Insert multiple documents |
update_one | Update a single document matching filter |
update_many | Update multiple documents matching filter |
delete_one | Delete a single document matching filter |
delete_many | Delete multiple documents matching filter |
aggregate | Run aggregation pipeline |
count | Count documents matching filter |
Query Format Reference:
{
"collection": "collection_name", // Required: Collection to query
"operation": "find", // Required: Operation type (see above)
"filter": {}, // Optional: Query filter (MongoDB query syntax)
"projection": {}, // Optional: Fields to include/exclude
"sort": {"field": 1}, // Optional: Sort order (1=asc, -1=desc)
"skip": 0, // Optional: Number of documents to skip
"limit": 10, // Optional: Maximum documents to return
"document": {}, // For insert_one: Document to insert
"documents": [{}, {}], // For insert_many: Array of documents
"update": {"$set": {}}, // For update operations: Update operators
"pipeline": [{}, {}] // For aggregate: Aggregation pipeline stages
}database-mcp-server/
├── main.py # Entry point
├── pyproject.toml # Project configuration
├── .env # Environment variables (create this)
└── src/
├── server.py # MCP server and tool definitions
├── lib/
│ ├── config.py # Configuration management
│ ├── utils.py # Utility functions
│ ├── middleware.py # Middleware for MCP server
│ └── mcp.py # MCP-specific utilities
└── database/
├── manager.py # Database connection pool manager
├── formatter.py # Result formatting (JSON/Markdown)
├── postgres_client.py # PostgreSQL-specific operations
├── mysql_client.py # MySQL-specific operations
└── mongodb_client.py # MongoDB-specific operations# Run in development mode with auto-reload (requires watching tool)
uv run watch -c "python main.py" .| Package | Purpose |
|---|---|
mcp>=1.26.0 | Model Context Protocol framework |
asyncpg | PostgreSQL async driver |
aiomysql | MySQL async driver |
pymongo>=4.9.0 | MongoDB async driver |
python-dotenv | Environment variable management |
Tests are not yet implemented.
MIT
src/lib/middleware.py)src/lib/mcp.py)mongodb_client.py with full CRUD operations (find, insert, update, delete, aggregate, count)describe_table via document sampling~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.