PostgreSQL Query MCP Server
Runs as a Node.js application, serving as the execution environment for the MCP server
Provides a secure read-only interface to PostgreSQL databases, allowing execution of validated SELECT queries with timeout protection
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 Query MCP Servershow me the 10 most recent orders with customer names"
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.
MCP Postgres Query Server
A Model Context Protocol (MCP) server implementation for querying a PostgreSQL database in read-only mode, designed to work with Claude Desktop and other MCP clients.
Overview
This project implements a Model Context Protocol (MCP) server that provides:
A secure, read-only interface to a PostgreSQL database
Integration with Claude Desktop through the MCP protocol
SQL query validation to ensure only SELECT queries are executed
Query timeout protection (10 seconds)
Related MCP server: PostgreSQL MCP Server
Prerequisites
Node.js (v14 or later)
npm (comes with Node.js)
PostgreSQL database (connection details provided via command line)
Installation
# Clone the repository
git clone https://github.com/RathodDarshil/mcp-postgres-query-server.git
cd mcp-postgres-query-server
# Install dependencies
npm install
# Build the project
npm run buildConnecting to Claude Desktop
You can configure Claude Desktop to automatically launch and connect to the MCP server:
Access the Claude Desktop configuration file:
Open Claude Desktop
Go to Settings > Developer > Edit Config
This will open the configuration file in your default text editor
Add the postgres-query-server to the
mcpServerssection of yourclaude_desktop_config.json:
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:port/database"
]
}
}
}Replace
/path/to/your/with the actual path to your project directory.Replace the PostgreSQL connection string with your actual database credentials.
Save the file and restart Claude Desktop. The MCP server should now appear in the MCP server selection dropdown in Settings.
Example Configuration
Here's a complete example of a configuration file with postgres-query:
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/Users/darshilrathod/mcp-servers/mcp-postgres-query-server/dist/index.js",
"postgresql://user:password@localhost:5432/mydatabase"
]
}
}
}Updating Configuration
To update your Claude Desktop configuration:
Open Claude Desktop
Go to Settings > Developer > Edit Config
Make your changes to the configuration file
Save the file
Restart Claude Desktop for the changes to take effect
If you've updated the MCP server code, make sure to rebuild it with
npm run buildbefore restarting
Features
Read-Only Database Access: Only SELECT queries are permitted for security
Query Validation: Prevents potentially harmful SQL operations
Timeout Protection: Queries running longer than 10 seconds are automatically terminated
MCP Protocol Support: Complete implementation of the Model Context Protocol
JSON Response Formatting: Query results are returned in structured JSON format
API
Tools
query-postgres
Executes a read-only SQL query against the configured PostgreSQL database.
Parameters:
query(string): A SQL SELECT query to execute
Response:
JSON object containing:
rows: The result set rowsrowCount: Number of rows returnedfields: Column metadata
Example:
query-postgres: SELECT * FROM users LIMIT 5Development
The main server implementation is in src/index.ts. Key components:
PostgreSQL connection pool setup
Query validation logic
MCP server configuration
Tool and resource definitions
To modify the server's behavior, you can:
Edit the query validation logic in
isReadOnlyQuery()Add additional tools or resources to the MCP server
Modify the query timeout duration (currently 10 seconds)
Security Considerations
The server validates all queries to ensure they are read-only
Connection to the database uses SSL
Query timeout prevents resource exhaustion
No write operations are permitted
Database credentials are passed directly via command line arguments, not stored in files
License
ISC
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Available Tools
1 toolquery-postgresD
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
- First observed
query-postgres
TDQS
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is singular and clear, eliminating any risk of misselection.
A single tool inherently has perfect naming consistency, as there are no other tools to compare it against. The name 'query-postgres' follows a clear verb-noun pattern without any conflicting conventions.
A single tool is too few for a PostgreSQL server's apparent scope, which typically involves multiple operations like querying, inserting, updating, and deleting data. This minimal set severely limits functionality and agent workflows.
The tool surface is severely incomplete for a PostgreSQL domain, covering only querying. Obvious gaps include create, update, delete, schema management, and transaction handling, which will cause frequent agent failures in database interactions.
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 Connectors
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- -licenseNot gradedqualityAmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.100,74590,042MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.100,745MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.100,745MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries.100,745MIT
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/RathodDarshil/mcp-postgres-query-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server