pg-data-inspector
Provides secure, read-only access to query data structures and retrieve records from PostgreSQL relational data stores via an API interface.
Author

hthuong09
Quick Info
Actions
Tags
MCP Postgres Data Interface Utility
This utility serves as a Model Context Protocol (MCP) endpoint specifically designed for secure interaction with PostgreSQL databases. Its primary function is restricted to read-only operations, enabling users to execute data queries and examine database schema definitions.
Deployment Guide
Installation requires Node Package Manager:
npm install -g @hthuong09/postgres-mcp
Configuration Modalities
The operational parameters for the server are prioritized as follows:
- Environment Variables
POSTGRES_URL: The complete Uniform Resource Locator for the database connection (e.g.,postgres://usr:pwd@server:5432/database_name)- Specific connection components:
POSTGRES_HOST: Target host machine addressPOSTGRES_PORT: Connection port number (defaults to 5432)POSTGRES_DB: The target database identifierPOSTGRES_USER: Authentication usernamePOSTGRES_PASSWORD: Secret credential for authenticationPOSTGRES_SSL: Boolean flag ('true' to activate Transport Layer Security)POSTGRES_SCHEMA: The specific database schema to operate within (defaults to 'public')
-
Auxiliary settings:
DOTENV_PATH: Path specification for an alternative configuration fileDEBUG_MCP: Flag to activate detailed diagnostic output (set to 'true')
-
Invocation Argument Direct execution utilizing a connection string:
bash npx @hthuong09/postgres-mcp "postgres://user:pass@host:5432/dbname"
Accessible Endpoints
- Table Schemas: Every defined table within the database is mapped to an accessible resource.
- Resource URI Structure: The required path format is
postgres://user@host/dbname/table_name/schema - Output Format: Responses consist of a JSON array detailing column attributes (name and associated data type).
Operational Demonstrations
-
Utilizing environmental configuration:
bash export POSTGRES_HOST=localhost export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword npx @hthuong09/postgres-mcp -
Employing a direct connection link:
bash npx @hthuong09/postgres-mcp "postgres://myuser:mypassword@localhost:5432/mydb" -
Enabling secure socket layer (SSL) via variables:
bash export POSTGRES_HOST=db.example.com export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword export POSTGRES_SSL=true npx @hthuong09/postgres-mcp -
Specifying a non-default configuration file location:
bash DOTENV_PATH=/location/to/settings npx @hthuong09/postgres-mcp
Safety Directives
- Protect database authentication secrets diligently.
- For production deployment, favor environment variables or dedicated configuration files over command-line inputs to obscure sensitive data from process listings.
- SSL encryption is strongly advised for live operational contexts.
- All database interactions are strictly enforced as read-only transactions to maintain data integrity.
- Passwords embedded in resource URIs are automatically redacted.
Local Development Setup
To compile the utility locally:
npm install
npm run build
To initiate development iteration with automatic reloading:
npm run watch
Troubleshooting
Activate verbose logging by setting DEBUG_MCP=true. Logs will be redirected to:
- POSIX Systems (Unix/macOS): /tmp/postgres-mcp-debug.json
- Windows Systems: %TEMP%/postgres-mcp-debug.json
Licensing
This software is distributed under the MIT License.
