PostgreSQL MCP Server
Supports configuration through .env files, allowing users to set database connection parameters like host, port, database name, username, and password.
Runs as a Node.js application, requiring Node.js 18+ for execution of the MCP server.
Supports installation and management of dependencies through npm package manager.
Provides access to PostgreSQL database schemas and metadata, enabling users to list tables, describe table schemas, explore foreign key relationships, view available schemas, and get index information for tables.
Supports installation and management of dependencies through yarn package manager as an alternative to npm.
Click on "Deploy 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 MCP Server show me the schema for the users table"
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.
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides access to PostgreSQL database schemas and metadata. This server allows Cursor and other MCP-compatible tools to explore your database structure, inspect table schemas, and understand relationships.
Features
List Tables: Get all tables in a schema with basic information
Describe Table: Get detailed column information for any table
Table Relationships: Explore foreign key relationships
List Schemas: See all available schemas in your database
Index Information: View indexes for specific tables
Related MCP server: PostgreSQL MCP Server
Prerequisites
Node.js 18+
PostgreSQL database (local or remote)
npm or yarn package manager
Installation
Clone or download this repository
Install dependencies:
npm installConfigure database connection:
cp config.env.example .envEdit the
.envfile with your PostgreSQL connection details:DB_HOST=localhost DB_PORT=5432 DB_NAME=your_database_name DB_USER=your_username DB_PASSWORD=your_passwordTest the server (optional):
npm start
Cursor Integration
To use this MCP server with Cursor, you need to add it to your Cursor configuration.
Step 1: Add to Cursor MCP Configuration
Open Cursor and go to Settings → Features → Model Context Protocol, or edit your MCP configuration file directly.
Add the following configuration:
{
"mcpServers": {
"postgres-schema": {
"command": "node",
"args": ["/absolute/path/to/pg_mcp/src/index.js"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "your_database_name",
"DB_USER": "your_username",
"DB_PASSWORD": "your_password"
}
}
}
}Important: Replace /absolute/path/to/pg_mcp/src/index.js with the actual absolute path to your src/index.js file.
Step 2: Alternative Configuration (Using .env file)
If you prefer to use the .env file for configuration:
{
"mcpServers": {
"postgres-schema": {
"command": "node",
"args": ["/absolute/path/to/pg_mcp/src/index.js"],
"cwd": "/absolute/path/to/pg_mcp"
}
}
}Step 3: Restart Cursor
After adding the configuration, restart Cursor to load the MCP server.
Available Tools
Once configured, you'll have access to these tools in Cursor:
list_tables
Lists all tables in a specified schema (defaults to 'public')
Parameters:
- schema (optional): Schema name (default: "public")describe_table
Gets detailed schema information for a specific table
Parameters:
- table_name (required): Name of the table to describe
- schema (optional): Schema name (default: "public")get_table_relationships
Shows foreign key relationships for a table
Parameters:
- table_name (required): Name of the table
- schema (optional): Schema name (default: "public")list_schemas
Lists all available schemas in the database
No parameters requiredget_indexes
Shows indexes for a specific table
Parameters:
- table_name (required): Name of the table
- schema (optional): Schema name (default: "public")Usage Examples
Once configured in Cursor, you can ask questions like:
"What tables are in my database?"
"Show me the schema for the users table"
"What are the foreign key relationships for the orders table?"
"List all indexes on the products table"
"What schemas are available in my database?"
Troubleshooting
Connection Issues
Database connection fails:
Verify your database credentials in
.envEnsure PostgreSQL is running
Check if the database allows connections from your host
MCP server not loading in Cursor:
Verify the absolute path to
index.jsis correctCheck that Node.js is installed and accessible
Review Cursor's MCP logs for error messages
Permission denied errors:
Ensure the database user has read permissions on
information_schemaGrant necessary SELECT permissions on system tables
Common Error Messages
Database connection failed: Check your connection parametersTable not found: Verify the table name and schemaPermission denied: Ensure your database user has appropriate read permissions
Security Considerations
This server only reads database metadata (schema information)
No actual table data is accessed or exposed
Uses parameterized queries to prevent SQL injection
Database credentials are stored locally in your environment
Development
To run in development mode with auto-reload:
npm run devLicense
MIT License - see LICENSE file for details.
Available Tools
5 toolsdescribe_tableB
Get detailed schema information for a specific table
Inputs: table_name (required), schema.
get_indexesC
Get indexes for a specific table
Inputs: table_name (required), schema.
get_table_relationshipsC
Get foreign key relationships for a table
Inputs: table_name (required), schema.
list_schemasB
List all schemas in the database
Inputs: no named parameters.
list_tablesB
List all tables in the database with basic information
Inputs: schema.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Every tool has a clearly distinct purpose targeting different aspects of PostgreSQL metadata. describe_table focuses on schema details, get_indexes on indexing, get_table_relationships on foreign keys, and list_schemas/list_tables on database structure overviews. There is no overlap or ambiguity between these functions.
All tools follow a consistent verb_noun naming pattern (describe_table, get_indexes, get_table_relationships, list_schemas, list_tables). The verbs are appropriate and descriptive, and the snake_case convention is maintained throughout without deviation.
Five tools is a reasonable number for a PostgreSQL metadata server, providing essential introspection capabilities. It is slightly lean but covers core needs like schema listing, table exploration, and relationship mapping, though it could potentially benefit from additional tools for views or constraints.
The toolset covers read-only metadata operations well, but there are notable gaps for a full PostgreSQL MCP server. It lacks tools for query execution, data manipulation (INSERT/UPDATE/DELETE), or administrative tasks like user management, which limits its utility for broader database interactions.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
The AI that understands raw data: Schema over your tables and databases, as MCP tools.
Managed Postgres MCP: projects, SQL, docs search, and storage buckets via OAuth.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables interaction with PostgreSQL databases through MCP, allowing users to explore database structures, inspect table schemas, and execute read-only SQL queries.-
- AlicenseCqualityDmaintenanceEnables querying PostgreSQL database metadata including table lists and schema information through the MCP protocol. Supports stdio transport for Cursor/IDE integration as well as HTTP transport with health check endpoints.2MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with PostgreSQL databases through MCP, supporting queries, DDL, DML, and schema inspection.6MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to execute SQL queries and inspect PostgreSQL database schemas via MCP tools.-