PostgreSQL MCP Server
Provides read-only access to PostgreSQL databases, allowing users to execute SELECT queries, inspect table structures, and list schemas or tables while ensuring security through query validation and parameterization.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP Servershow me the structure of the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides read-only access to PostgreSQL databases.
Features
Read-only operations: Query data safely without risk of modifications
Schema inspection: Explore database structure, tables, and columns
Query execution: Run SELECT statements and view results
Connection management: Secure connection handling with proper cleanup
Related MCP server: PostgreSQL MCP Server
Installation
Clone this repository
Install dependencies:
npm installBuild the project:
npm run buildConfigure your database connection (see Configuration section below)
Configuration
Create a .env file in the root directory with your PostgreSQL connection details:
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=your_database
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_SSL=falseUsage
Running the Server
npm startAvailable Tools
The MCP server provides the following tools:
postgres_query - Execute SELECT queries
postgres_describe_table - Get table structure and column information
postgres_list_tables - List all tables in the database
postgres_list_schemas - List all schemas in the database
Example MCP Client Configuration
Add this to your MCP client configuration (e.g., ~/.config/claude-desktop/mcp.json):
{
"servers": {
"postgresql": {
"command": "node",
"args": ["path/to/mcp/server/start-server.cjs"],
"type": "stdio"
}
}
}This configuration automatically loads environment variables from your project's .env file, keeping sensitive credentials out of the MCP configuration.
Security
This server operates in read-only mode only. It:
Only allows SELECT statements
Blocks INSERT, UPDATE, DELETE, DROP, CREATE, ALTER operations
Uses parameterized queries to prevent SQL injection
Validates all queries before execution
Testing
Quick Test
# Run complete test suite (includes security testing)
npm run test:complete
# or
./test.shTest Environment
The project includes a comprehensive test environment with:
PostgreSQL 15.13 in Docker
Realistic e-commerce test data (74 records across 6 tables)
Security validation tests
Automated setup and cleanup
See test/README.md for detailed testing documentation.
Development
# Development mode (rebuild and run)
npm run dev
# Build only (required after code changes)
npm run build
# Test database connection
npm run test-connection
# Test security features
npm run test-mcp-securityNote: You only need to run npm run build when you modify the TypeScript source code. For normal usage with different database credentials, just update your .env file.
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-quality-maintenanceEnables read-only access to PostgreSQL databases with multi-tenant support, allowing users to query data, explore schemas, inspect table structures, and view function definitions across different tenant schemas safely.Last updated551
- Flicense-qualityDmaintenanceProvides read-only access to PostgreSQL databases with schema inspection, query execution in multiple formats (JSON, CSV, Markdown), and query history tracking with built-in security features.Last updated
- Alicense-qualityDmaintenanceEnables secure read-only access to PostgreSQL databases through SELECT queries only, with tools for exploring schemas, listing tables, and executing common queries while preventing any data modification operations.Last updated853MIT
- Alicense-qualityAmaintenanceEnables secure read-only access to PostgreSQL databases, allowing users to list tables, query schemas, execute SELECT statements, and inspect table structures through natural language interactions.Last updated6684MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Read-only access to Auralogs production logs: search logs, inspect errors, review AI analyses.
Appeared in Searches
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/DemeoStep/posgres_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server