endaoment-postgres-mcp
Documentation
Model Context Protocol PostgreSQL Server
This project implements a Model Context Protocol (MCP) server that connects to a PostgreSQL database. It allows AI models to interact with your database through a standardized protocol.
Features
- Connects to a PostgreSQL database using connection pooling
- Implements the Model Context Protocol for AI model interaction
- Provides database schema information as resources
- Allows executing SQL queries with retry logic
- Handles connection errors gracefully
Prerequisites
- Node.js 20 or higher
- PostgreSQL database
- Access credentials for the database
Installation
1. Clone this repository
2. Install dependencies:
npm installConfiguration
The server reads database credentials from a `.env` file in the project root directory. You need to add your database credentials as a JSON string in the `DB_CREDENTIALS` environment variable:
1. Create a `.env` file in the project root:
touch .env2. Add the following line with your actual database credentials:
export DB_CREDENTIALS='{"DB_USER":"your-username","DB_PASSWORD":"your-password","DB_HOST":"your-host","DB_PORT":"5433","DB_NAME":"your-database"}'Fallback to Shell Config Files
If the `.env` file is not present or the credentials variable is not found, the server will automatically look for the credentials in your shell configuration files in the following order:
1. `~/.zshrc`
2. `~/.bashrc`
3. `~/.bash_profile`
4. `~/.profile`
This is especially useful in environments where shell config files are not automatically sourced, such as the Cursor MCP environment.
To set up credentials in any of your shell config files:
1. Open your preferred shell config file, for example:
nano ~/.zshrc
# or
nano ~/.bashrc2. Add the following line with your actual database credentials:
export DB_CREDENTIALS='{"DB_USER":"your-username","DB_PASSWORD":"your-password","DB_HOST":"your-host","DB_PORT":"5433","DB_NAME":"your-database"}'The server will automatically detect and use these credentials when the `.env` file is not available.
Custom Credentials Variable
You can also use a custom environment variable name instead of `DB_CREDENTIALS` by using the `--credentials-var` flag when starting the server:
node server.js --credentials-var MY_CUSTOM_DB_CREDSIn this case, you would define `MY_CUSTOM_DB_CREDS` in your `.env` file instead.
Combining Options
You can combine different command-line options as needed:
# Use custom credentials and enable verbose mode
node server.js --credentials-var MY_CUSTOM_DB_CREDS --verbose
# Short form also works
node server.js -c MY_CUSTOM_DB_CREDS -vUsage
Start the MCP server:
# Directly with Node.js
node server.js
# Or with npm
npm startLogging Options
By default, the server runs in silent mode, displaying only error messages. If you want to see all log messages, you can use the verbose flag:
# With verbose logging
node server.js --verbose
# Or with npm
npm start -- --verboseYou can also use the short flag `-v`:
node server.js -vThe server will:
1. Test the database connection
2. Start the MCP server using stdio transport
3. Handle requests from AI models
Integration with Cursor
This server supports the Model Context Protocol (MCP) and integrates with Cursor AI.
Automatic Configuration
This project includes a pre-configured `.cursor/mcp.json` file for automatic setup within Cursor.
Manual Configuration
To manually add this server to Cursor:
1. Go to Cursor Settings → Features → MCP
2. Click "+ Add New MCP Server"
3. Enter the following details:
For more information on MCP integration with Cursor, see the official documentation.
Available Tools
The server provides the following tools to AI models:
- `query`: Execute SQL queries with retry logic
Resources
The server exposes database tables as resources, allowing AI models to:
- List all tables in the database
- View schema information for each table
Error Handling
The server includes:
- Connection retry logic
- Detailed error logging
- Graceful shutdown handling
Troubleshooting
Connection Issues
1. Database Connection Failed
2. Environment Variable Problems
3. Node.js Version Issues
Cursor Integration
1. Server Not Showing in Cursor
2. "Failed to create client" Error
3. No Tools Available in Cursor
PostgreSQL Specific Issues
1. Permission Denied Errors
2. "Relation does not exist" Errors
3. Performance Issues
For additional help, you can run the server with verbose logging (`-v` flag) to see detailed error messages and operation logs.
License
MIT
Frequently asked questions
What is endaoment-postgres-mcp?
endaoment-postgres-mcp is a Model Context Protocol (MCP) server listed in the TrackMCP directory.
How do I install endaoment-postgres-mcp?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is endaoment-postgres-mcp open source?
Yes — it is hosted on GitHub at https://github.com/endaoment/endaoment-postgres-mcp and has 1 stars.
Related MCP tools
An MCP server that installs other MCP servers for you JavaScript-based implementation. Trusted by 1400+ developers. Trusted by 1400+ developers.
MCP server for interacting with the iOS simulator JavaScript-based implementation. Trusted by 1200+ developers. Trusted by 1200+ developers.
A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only...
This is an MCP server that allows you to directly download transcripts of YouTube videos. JavaScript-based implementation.
The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.
An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others. Built for the Model Context Protocol to enhance AI capabiliti
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP