@gongrzhe/server-db-query-builder
v1.0.0
Published
Database Query Builder MCP App Server with interactive SQL editor and results viewer
Downloads
97
Readme
Database Query Builder MCP Server
Interactive SQL editor with query execution, results table, and database schema exploration.
Features
- Execute SQL Queries - Run arbitrary SQL queries against a PostgreSQL database with real-time results in a structured table view
- Schema Exploration - List all tables in the database with column counts and estimated row statistics
- Table Introspection - View detailed column definitions including data types, nullability, defaults, and primary key constraints
- Auto-Limiting - SELECT queries are automatically limited to 1,000 rows to prevent memory issues
- Execution Metrics - Track query execution time and row counts for performance monitoring
- Safety Features - Statement timeout (30 seconds) prevents long-running queries from hanging
Installation
npm install @gongrzhe/server-db-query-builderUsage
As a CLI
npx @gongrzhe/server-db-query-builderClaude Desktop Configuration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"db-query-builder": {
"command": "npx",
"args": ["-y", "@gongrzhe/server-db-query-builder"]
}
}
}Claude Code Configuration
claude mcp add db-query-builder -- npx -y @gongrzhe/server-db-query-builderTools
execute-query
Executes a SQL query against the connected PostgreSQL database and returns the results.
Input:
sql(string): The SQL query to execute
Output:
columns: Array of column definitions with name and data typerows: Array of result rowsrowCount: Number of rows returnedexecutionTimeMs: Query execution time in millisecondswasTruncated: Boolean indicating if results were truncated to 1,000 rowserror(optional): Error message if query failed
list-tables
Lists all tables in the connected PostgreSQL database with column counts and estimated row counts.
Input: None
Output:
tables: Array of table objects with:schemaName: Schema name (e.g., "public")tableName: Table namecolumnCount: Number of columnsestimatedRows: Approximate number of rows
describe-table
Returns the column definitions for a specific table, including data types, nullability, defaults, and primary key status.
Input:
tableName(string): Name of the table to describeschemaName(string, optional): Schema name (defaults to "public")
Output:
schemaName: Schema nametableName: Table namecolumns: Array of column definitions with:columnName: Column namedataType: PostgreSQL data typenullable: Boolean indicating if column allows NULLdefaultValue: Default value if set, otherwise nullisPrimaryKey: Boolean indicating if column is a primary key
Configuration
Set the DATABASE_URL environment variable to connect to a PostgreSQL database:
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
npx @gongrzhe/server-db-query-builderThe server will warn if DATABASE_URL is not set, but will start and fail gracefully when queries are attempted.
Example Prompt
Show me all tables in the database and run SELECT * FROM users LIMIT 10License
MIT
