postgres
MCP server for interacting with a PostgreSQL products database.
claude mcp add --transport stdio michael7736-postgres-mcp-server node /path/to/your/postgres-mcp-server/build/index.js \ --env PGHOST="your_db_host" \ --env PGPORT="5432" \ --env PGUSER="your_db_user" \ --env PGDATABASE="your_db_name" \ --env PGPASSWORD="your_db_password"
How to use
This MCP server provides a PostgreSQL-backed toolset for querying a products database. The server exposes a single primary tool, run_sql_query, which executes read-only SQL SELECT statements against the configured PostgreSQL database. After you configure and run the server within your MCP client, you can invoke run_sql_query to fetch product information such as names, prices, stock levels, categories, and other product-related fields. Ensure your PostgreSQL credentials are securely provided via environment variables in the MCP settings, as shown in the example configuration. The tool expects a JSON payload containing the SQL query you want to run, and it returns the resulting rows from the database, enabling AI assistants to reason over live product data while preserving read-only access to the underlying data.
To use, prepare a configuration block for the server in your MCP client settings (or the claude/mcp settings file you use) with the run_sql_query tool enabled. Then call the tool with a query string. For example, you can query for electronics in stock by sending a query like: SELECT product_name, stock_quantity FROM products WHERE category = 'Electronics'; The server will return the matching rows. You can craft more complex SELECT statements as needed, but this server is intended for read-only access, so INSERT/UPDATE/DELETE operations should not be performed through this tool.
How to install
Prerequisites:
- Node.js v18 or later
- npm or yarn
- Access to a PostgreSQL database with the products schema
Install from repository and install dependencies:
git clone https://github.com/michael7736/postgres-mcp-server.git
cd postgres-mcp-server
Install dependencies (choose one):
npm install
or
yarn install
Build the TypeScript source to JavaScript:
npm run build
or
yarn build
The build will produce build/index.js (or the configured output) which is the entry point for the MCP server when run with Node.
Additional notes
Tips and common considerations:
- The server requires PostgreSQL connection details to be provided via environment variables in your MCP client settings (PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE).
- The run_sql_query tool is read-only by design. Use carefully to avoid exposing sensitive data in responses.
- Ensure the PostgreSQL user has only the necessary permissions to read the products schema to minimize security risks.
- If you change the database connection, update the env variables in your MCP settings accordingly.
- When deploying, ensure the build/index.js path in the MCP configuration points to the actual location of the built server file.
- You can adjust autoApprove or disabled flags in the MCP settings to control access and automation for this server.
Related MCP Servers
zen
Selfhosted notes app. Single golang binary, notes stored as markdown within SQLite, full-text search, very low resource usage
MCP -Deepseek_R1
A Model Context Protocol (MCP) server implementation connecting Claude Desktop with DeepSeek's language models (R1/V3)
mcp-fhir
A Model Context Protocol implementation for FHIR
mcp
Inkdrop Model Context Protocol Server
mcp-appium-gestures
This is a Model Context Protocol (MCP) server providing resources and tools for Appium mobile gestures using Actions API..
dubco -npm
The (Unofficial) dubco-mcp-server enables AI assistants to manage Dub.co short links via the Model Context Protocol. It provides three MCP tools: create_link for generating new short URLs, update_link for modifying existing links, and delete_link for removing short links.