A Model Context Protocol (MCP) server for querying databases. Supports SQLite, PostgreSQL, MySQL, and Microsoft SQL Server with read-only access.
- Multiple Database Support: SQLite, PostgreSQL, MySQL, and MS SQL Server
- Read-Only Operations: Safe query execution with DML operation blocking
- MCP Integration: Exposes database querying via the Model Context Protocol
- CSV Output: Query results returned in CSV format
- Environment-Based Configuration: Connection via
DATABASE_URLenvironment variable
You can use this MCP server with any MCP client, such as Cursor or Claude Desktop.
Add the following configuration to your MCP settings file (typically in your Cursor settings or .cursorrules):
{
"mcpServers": {
"nala-db-mcp": {
"command": "bunx nala-db-mcp",
"env": {
"DATABASE_URL": "mssql://sa:test@localhost:1433/test"
}
}
}
}Replace the DATABASE_URL value with your database connection string:
- SQLite:
sqlite://path/to/database.db - PostgreSQL:
postgres://user:password@localhost:5432/dbname - MySQL:
mysql://user:password@localhost:3306/dbname - MS SQL Server:
mssql://user:password@localhost:1433/dbname
Once configured, the MCP server will be available in your Cursor environment, and you can use the run-query tool to execute read-only SQL queries.
For local development or custom integrations, you can install and run the server directly.
bun installSet your database connection string in the DATABASE_URL environment variable:
# SQLite
export DATABASE_URL="sqlite://path/to/database.db"
# PostgreSQL
export DATABASE_URL="postgres://user:password@localhost:5432/dbname"
# MySQL
export DATABASE_URL="mysql://user:password@localhost:3306/dbname"
# MS SQL Server
export DATABASE_URL="mssql://user:password@localhost:1433/dbname"bun run startThe MCP server will start and listen on stdio for MCP client connections.
Executes a read-only SQL query against the configured database.
Input:
query(string): SQL query to execute. Must be a SELECT query (no INSERT, UPDATE, DELETE, etc.)
Output:
- CSV-formatted query results
Example:
SELECT * FROM users WHERE active = 1# Run all tests
bun test
# Run specific test file
bun test test/db.test.tsbun run checkThis runs Biome with auto-fix enabled for code formatting and linting.
index.ts- MCP server setup and tool registrationsrc/db.ts- Database connection logic and utilitiestest/db.test.ts- Test suite
- Anything isn't bulletproof, so create a new user with READONLY permissions it's recommended
- All database connections are read-only
- DML operations (INSERT, UPDATE, DELETE, etc.) are blocked via regex validation
- Connection strings support encrypted connections (MS SQL Server uses
Encrypt=true)
MIT
Built with Bun and the Model Context Protocol SDK