Secure read-only PostgreSQL MCP server with query validation and timeout for Claude Desktop integration
The PostgreSQL Query Server is a comprehensive Model Context Protocol (MCP) server implementation designed to facilitate secure, read-only access to PostgreSQL databases within various AI applications and development environments. This server ensures that only SELECT queries are executed, protecting the integrity of your data while enabling seamless integration with AI tools such as Claude Desktop.
The PostgreSQL Query Server comes packed with features designed for security, flexibility, and performance. Key among these is MCP protocol implementation, ensuring a standardized approach to connecting AI applications like Claude Desktop, Continue, Cursor, and more to PostgreSQL databases. Additionally, this server provides query validation mechanisms to prevent harmful SQL operations and includes timeout protection, guaranteeing efficient data retrieval.
The implementation is based on the Model Context Protocol (MCP), a widely adopted standard in integrating various AI applications with backend data sources. This protocol enables secure and efficient communication between clients (like AI desktop apps) and servers, maintaining data integrity and minimizing latency.
The PostgreSQL Query Server uses Node.js as its runtime environment, leveraging npm for dependency management. The server architecture consists of a PostgreSQL connection pool setup, query validation logic, and an MCP server configuration. Key components include:
To modify behavior, developers can adjust query validation logic or add more tools/resources to the MCP server. This flexibility allows for enhanced functionality without significantly altering the core architecture.
Installing and deploying the PostgreSQL Query Server is straightforward. Follow these steps:
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 build
Configure and Launch Claude Desktop: Update your claude_desktop_config.json
to include this server.
AI teams need quick, secure access to PostgreSQL databases for data analysis. The PostgreSQL Query Server ensures that all queries are read-only and validated before execution. This setup prevents accidental modifications or deletions while providing the necessary metadata and data.
Example Workflow:
During model training, AI applications need periodic and secure updates from live databases without disrupting ongoing operations. The PostgreSQL Query Server ensures that only authorized SELECT queries are executed, making it ideal for maintaining consistent data access during critical development phases.
The PostgreSQL Query Server is designed to work seamlessly with a variety of Model Context Protocol (MCP) clients such as Claude Desktop and others listed in the compatibility matrix. Ensure your configuration aligns with these clients for optimal interaction.
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph TD
subgraph Database
B[Databases] -->|Queries| C[PostgreSQL]
end
subgraph Client
E[Claude Desktop] --> F[MCP Protocol]
end
subgraph Server
F --> G[Query Validation]
G --> H[MCP Server]
end
C --> D[Metadata Response]
The PostgreSQL Query Server is designed to deliver high performance while maintaining compatibility with various MCP clients and environments. Here’s a breakdown of the current status:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ❌ | Partial Support |
Cursor | ❌ | ✅ | ❌ | Limited Tools |
To customize the PostgreSQL Query Server, follow these steps:
isReadOnlyQuery()
in src/index.ts
to add custom validation criteria.Here is a sample configuration for your claude_desktop_config.json
:
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://user:password@localhost:5432/mydatabase"
]
}
}
}
claude_desktop_config.json
file and restart Claude Desktop for changes to take effect.claude_desktop_config.json
, you can manage multiple database connections simultaneously.Contributions are welcome! If you wish to contribute to the project, please adhere to these guidelines:
npm run test
.For more information on the Model Context Protocol and its ecosystem, visit the official documentation or explore related resources available online. Engaging with the broader community can also provide valuable insights into best practices and new developments in MCP integration.
By using the PostgreSQL Query Server, you enhance your AI workflows by ensuring secure, efficient, and scalable data access through a standardized protocol.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration