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.
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
Prerequisites
- Node.js 18+
- PostgreSQL database (local or remote)
- npm or yarn package manager
Installation
- Clone or download this repository
- Install dependencies:
- Configure database connection:Edit the
.env
file with your PostgreSQL connection details: - Test the server (optional):
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:
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:
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')
describe_table
Gets detailed schema information for a specific table
get_table_relationships
Shows foreign key relationships for a table
list_schemas
Lists all available schemas in the database
get_indexes
Shows indexes for a specific table
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
.env
- Ensure PostgreSQL is running
- Check if the database allows connections from your host
- Verify your database credentials in
- MCP server not loading in Cursor:
- Verify the absolute path to
index.js
is correct - Check that Node.js is installed and accessible
- Review Cursor's MCP logs for error messages
- Verify the absolute path to
- Permission denied errors:
- Ensure the database user has read permissions on
information_schema
- Grant necessary SELECT permissions on system tables
- Ensure the database user has read permissions on
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:
License
MIT License - see LICENSE file for details.
This server cannot be installed
Provides access to PostgreSQL database schemas and metadata, allowing MCP-compatible tools like Cursor to explore database structure, inspect table schemas, and understand relationships.
Related MCP Servers
- -securityFlicense-qualityProvides read-only access to PostgreSQL databases, enabling users to inspect database schemas and execute read-only queries through a Model Context Protocol server.Last updated -3JavaScript
- -securityAlicense-qualityAn MCP server that connects to Supabase PostgreSQL databases, exposing table schemas as resources and providing tools for data analysis through SQL queries.Last updated -1JavaScriptMIT License
- -securityFlicense-qualityA server implementing the Model Context Protocol (MCP) for Cursor that allows using a PostgreSQL database as storage for model contexts, enabling secure database exploration and querying.Last updated -64JavaScript
- -securityAlicense-qualityA template project for building custom MCP servers that enables direct access to PostgreSQL databases, allowing SQL query execution and schema information retrieval through the Model Context Protocol.Last updated -30PythonMIT License