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.
This project implements a Model Context Protocol (MCP) server that provides:
# 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
You can configure Claude Desktop to automatically launch and connect to the MCP server:
Access the Claude Desktop configuration file:
Add the postgres-query-server to the mcpServers
section of your claude_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"
]
}
}
}
/path/to/your/
with the actual path to your project directory.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"
]
}
}
}
To update your Claude Desktop configuration:
npm run build
before restartingExecutes a read-only SQL query against the configured PostgreSQL database.
Parameters:
query
(string): A SQL SELECT query to executeResponse:
rows
: The result set rowsrowCount
: Number of rows returnedfields
: Column metadataExample:
query-postgres: SELECT * FROM users LIMIT 5
The main server implementation is in src/index.ts
. Key components:
To modify the server's behavior, you can:
isReadOnlyQuery()
ISC
Contributions are welcome! Please feel free to submit a Pull Request.
{
"mcpServers": {
"postgres-query": {
"env": {},
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:port/database"
],
"command": "node"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.