MCP Postgres Query Server

by rathoddarshil

Not rated
GitHub

About

An MCP server for querying a PostgreSQL database in read-only mode.

Details

Author
rathoddarshil
Categories
Database, Other

Setup

Install MCP Postgres Query Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/rathoddarshil/mcp-postgres-query-server

Follow the installation instructions in the repository README, then restart your MCP client.

An MCP server for querying a PostgreSQL database in read-only mode.

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:
- 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)

- Node.js (v14 or later)
- npm (comes with Node.js)
- PostgreSQL database (connection details provided via command line)

# 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:

- 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 themcpServerssection 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.

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:
- 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 withnpm run buildbefore restarting

- 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

Executes a read-only SQL query against the configured PostgreSQL database.

- query(string): A SQL SELECT query to execute

- JSON object containing:

- rows: The result set rows
- rowCount: Number of rows returned
- fields: Column metadata

query-postgres: SELECT * FROM users LIMIT 5

The main server implementation is insrc/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 inisReadOnlyQuery()
- Add additional tools or resources to the MCP server
- Modify the query timeout duration (currently 10 seconds)

- 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

Contributions are welcome! Please feel free to submit a Pull Request.

A read-only MCP server by CData that enables LLMs to query live data from EnterpriseDB databases.

Expert-level PostgreSQL database analysis MCP server for AI assistants.

Provides read-only access to PostgreSQL databases, enabling schema inspection and query execution.

Provides read-only access to PostgreSQL databases, allowing LLMs to inspect schemas and execute queries.

Provides read-only access to PostgreSQL databases, allowing LLMs to inspect schemas and execute queries.

Transforms PostgreSQL databases from "I have tables and I don't know what they do" into "I understand the entire database structure, relationships, and best practices"

A read-only MCP server for PostgreSQL, enabling LLMs to query live data from PostgreSQL databases.

Read-only MCP server for PostgreSQL, MySQL, and SQL Server with schema introspection, SQL query execution, EXPLAIN/optimization, anomaly detection, PII scanning, and N+1 query detection.

Official MCP server for dbt (data build tool) providing integration with dbt Core/Cloud CLI, project metadata discovery, model information, and semantic layer querying capabilities.

Query and analyze data with MotherDuck and local DuckDB

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.