Postgres MCP Server
Postgres MCP Server
A Model Context Protocol (MCP) server that provides secure database access to PostgreSQL through Kysely ORM. This server enables Claude Desktop to interact with PostgreSQL databases using natural language.
Features
MCP Tools: Query execution, table listing, schema inspection, and constraint information
Type Safety: Full TypeScript support with typed inputs/outputs
Connection Pooling: Configurable connection limits with idle timeout
Error Handling: Graceful error messages for connection and query issues
Security: Parameterized queries to prevent SQL injection
Installation
npx postgres-mcp-serverConfiguration
Create a .env file with your database credentials:
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password_here
DB_NAME=postgres
DB_SSL=trueAvailable Tools
Tool | Description | Required Parameters | Optional Parameters |
| Execute SQL queries with pagination support |
|
|
| Get table structure and column details |
| - |
| List all tables in a schema |
| - |
| List all schemas in the database | - |
|
| Get table constraints (PK, FK, etc.) |
| - |
| List indexes for a table or schema |
|
|
| List views in a schema |
| - |
| List functions and procedures |
| - |
| Get query execution plan |
|
|
| Get table size and statistics |
|
|
Key Features
Pagination: Query tool supports up to 500 rows per page with automatic LIMIT/OFFSET handling
Security: Parameterized queries prevent SQL injection, READ_ONLY mode by default
Type Safety: Full TypeScript support with Zod schema validation
Claude Desktop Configuration
Add this server to your Claude Desktop configuration file:
Edit claude_desktop_config.json:
{
"mcpServers": {
"postgres-mcp-server": {
"command": "npx",
"args": ["postgres-mcp-server"],
"env": {
"DB_HOST": "127.0.0.1",
"DB_PORT": "5432",
"DB_USER": "postgres",
"DB_PASSWORD": "your_password_here",
"DB_NAME": "your_database_name",
"DB_SSL": "true"
}
}
}
}Configuration File Locations
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Development
# Clone and install dependencies
git clone https://github.com/abiswas97/postgres-mcp-server.git
cd postgres-mcp-server
npm install
# Run in development mode with hot reload
npm run dev
# Build for production
npm run build
# Run tests
npm run test
# Run specific test suites
npm run test:unit
npm run test:integrationEnvironment Variables
Variable | Default | Description |
|
| PostgreSQL host |
|
| PostgreSQL port |
|
| Database user |
| required | Database password |
|
| Database name |
|
| Enable SSL connection |
|
| Restrict to SELECT/WITH/EXPLAIN queries |
|
| Query timeout in milliseconds |
|
| Maximum rows per page |
|
| Default page size when not specified |
License
ISC
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/abiswas97/postgres-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server