sierra-db-query
v1.0.2
Published
Sierra DB Query - A Model Context Protocol (MCP) server for PostgreSQL database management
Maintainers
Readme
Sierra DB Query
A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL database management capabilities for AI assistants.
Features
10 powerful tools for complete PostgreSQL database management:
Core Tools
- Schema Management - Tables, columns, ENUMs, views
- Query Execution - SELECT operations with count/exists support
- Data Mutations - INSERT/UPDATE/DELETE/UPSERT operations
- SQL Execution - Arbitrary SQL with transaction support
Analysis & Monitoring
- Database Analysis - Configuration, performance, and security analysis
- Real-time Monitoring - Active queries, locks, connection stats, replication
Database Object Management
- Index Management - Create, drop, reindex, analyze usage
- Constraint Management - Foreign keys, unique, check, primary key constraints
- Function Management - Create, drop, and list PostgreSQL functions
- User Management - Create users, manage permissions, grant/revoke access
Quick Start
Prerequisites
- Node.js >= 18.0.0
- Access to a PostgreSQL server
- (Optional) An MCP client like Cursor or Claude for AI integration
Option 1: Install via Smithery (Recommended)
npx -y @smithery/cli install @Yaswanth-ampolu/sierra-db-query --client claudeOption 2: npm
# Install globally
npm install -g @sierra/db-query
# Or run directly with npx
npx @sierra/db-query --connection-string "postgresql://user:pass@localhost:5432/db"Add to your MCP client configuration:
{
"mcpServers": {
"sierra-db-query": {
"command": "npx",
"args": [
"@sierra/db-query",
"--connection-string", "postgresql://user:password@host:port/database"
]
}
}
}Option 3: Docker
# Build the Docker image
docker build -t sierra-db-query .
# Run with environment variable
docker run -i --rm \
-e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \
sierra-db-queryAdd to your MCP client configuration:
{
"mcpServers": {
"sierra-db-query": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"sierra-db-query"
],
"env": {
"POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:port/database"
}
}
}
}Option 4: Manual Installation (Development)
git clone https://github.com/Yaswanth-ampolu/sierra-db-query.git
cd sierra-db-query
npm install
npm run buildAdd to your MCP client configuration:
{
"mcpServers": {
"sierra-db-query": {
"command": "node",
"args": [
"/path/to/sierra-db-query/build/index.js",
"--connection-string", "postgresql://user:password@host:port/database"
]
}
}
}Available Tools
| Tool | Description |
|------|-------------|
| sierra_manage_schema | Schema management - tables, columns, ENUMs, views |
| sierra_execute_query | SELECT queries with count/exists operations |
| sierra_execute_mutation | INSERT/UPDATE/DELETE/UPSERT operations |
| sierra_execute_sql | Arbitrary SQL execution with transaction support |
| sierra_analyze_database | Configuration, performance, security analysis |
| sierra_monitor_database | Real-time monitoring - queries, locks, connections |
| sierra_manage_indexes | Index management - create, drop, reindex, analyze |
| sierra_manage_constraints | Constraint management - FK, unique, check, PK |
| sierra_manage_functions | Function management - create, drop, list |
| sierra_manage_users | User and permission management |
Example Usage
// Analyze database performance
{ "analysisType": "performance" }
// Create a table with constraints
{
"operation": "create_table",
"tableName": "users",
"columns": [
{ "name": "id", "type": "SERIAL PRIMARY KEY" },
{ "name": "email", "type": "VARCHAR(255) UNIQUE NOT NULL" }
]
}
// Query data with parameters
{
"operation": "select",
"query": "SELECT * FROM users WHERE created_at > $1",
"parameters": ["2024-01-01"],
"limit": 100
}
// Insert new data
{
"operation": "insert",
"table": "users",
"data": {"name": "John Doe", "email": "[email protected]"},
"returning": "*"
}
// Monitor active queries
{
"operation": "active_queries",
"includeIdle": false
}CLI Options
# With connection string
sierra-db-query --connection-string "postgresql://user:password@host:5432/database"
# With tools configuration
sierra-db-query --tools-config ./tools-config.json
# HTTP mode (for Smithery deployment)
sierra-db-query --http --port 7409Tools Configuration
Create a tools-config.json to enable specific tools:
{
"enabledTools": [
"sierra_manage_schema",
"sierra_execute_query",
"sierra_execute_mutation",
"sierra_analyze_database"
]
}Features Highlights
Security Focused
- SQL injection prevention with parameterized queries
- Connection string validation
- Non-root Docker user for security
Production Ready
- Flexible connection options (CLI args, env vars, per-tool config)
- Connection pooling for performance
- Comprehensive error handling
- Docker support for containerized deployment
Developer Friendly
- TypeScript with full type safety
- Zod schema validation
- Clear error messages
Development
# Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run dev
# Clean build
npm run cleanContributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a Pull Request
License
MIT License - see LICENSE file for details.
Author
Yaswanth Ampolu - [email protected]
