db-mcp
Verified Safeby Abdulmumin1
Overview
Provides a secure, read-only interface for AI assistants to execute SQL queries against PostgreSQL or MySQL databases using the Model Context Protocol.
Installation
node build/index.jsEnvironment Variables
- DB_TYPE
- DB_HOST
- DB_PORT
- DB_USER
- DB_PASSWORD
- DB_DATABASE
Security Notes
The server implements keyword filtering and requires queries to start with 'SELECT' or 'WITH' to enforce read-only operations. It correctly loads database credentials from environment variables and uses connection isolation by connecting and disconnecting for each query. However, the `validateReadOnly` function's deny-list is incomplete; it does not block keywords like `UNION` (which can be used for data exfiltration in a read-only context) or functions that could enable time-based or error-based SQL injection attacks (e.g., `pg_sleep`). Furthermore, the server passes the SQL query as a raw string to the database driver's `query` or `execute` method. While its intent is secure, it does not utilize parameterized queries for values, which is the most robust way to prevent SQL injection. This means if an AI assistant generates a 'SELECT' query with user-controlled input that isn't properly escaped by the AI itself, the server's validation might not catch all read-only injection vectors.
Similar Servers
mcp-mysql-server
Provides an MCP-compliant interface for AI models to securely interact with a MySQL database for CRUD operations, schema inspection, and performance analysis.
DatabaseMcpServer
Provides a robust and secure database access layer for AI assistants, supporting 19 types of databases with single-instance multi-database dynamic switching and over 50 tools for data and schema management.
mysql_mcp_server
This server provides a Model Context Protocol (MCP) interface to a MySQL database, enabling AI models to execute SQL queries and retrieve database schema information.
mcp-postgres
Provides a read-only Model Context Protocol (MCP) server for AI tools (like Claude Code, Cursor) to query a PostgreSQL database directly.