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 "Install 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 Servershow 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
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe | |
| schema | No | Schema name (default: public) | public |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It states this is a read operation ('Get'), but doesn't disclose behavioral traits like error handling, permissions needed, rate limits, or what 'detailed schema information' includes. For a tool with no annotations, this leaves significant gaps in understanding how it behaves.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for the tool's complexity. Every word contributes to understanding the tool's function.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no annotations and no output schema, the description is minimal but adequate for a simple read tool. It covers the basic purpose but lacks details on behavior, output format, or sibling differentiation. For a tool with 2 parameters and 100% schema coverage, it meets the minimum viable threshold but has clear gaps in context.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema fully documents both parameters. The description adds no additional meaning beyond what's in the schema, such as examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Get' and resource 'detailed schema information for a specific table', making the purpose unambiguous. It doesn't explicitly differentiate from siblings like 'get_indexes' or 'list_tables', but the specificity of 'detailed schema information' implies a distinction from listing operations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives. The description doesn't mention siblings like 'get_indexes' or 'list_tables', nor does it specify prerequisites or exclusions. Usage is implied by the purpose but not explicitly stated.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_indexesC
Get indexes for a specific table
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table | |
| schema | No | Schema name (default: public) | public |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behavioral aspects: whether this is a read-only operation, what format the indexes are returned in, whether it shows all index types or just specific ones, or if there are permission requirements. The description is minimal and lacks operational context.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is extremely concise - a single sentence with zero wasted words. It's front-loaded with the core purpose and efficiently communicates the basic function. Every word earns its place in this minimal description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no annotations and no output schema, the description is incomplete for a database tool. It doesn't explain what information is returned about indexes (columns, types, uniqueness, etc.), doesn't mention error conditions or permissions needed, and provides no context about how this fits with sibling tools. For a tool that presumably returns structured data about database objects, this is inadequate.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already fully documents both parameters (table_name and schema with default). The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain what constitutes a valid table name, what schemas are available, or how the parameters interact. Baseline 3 is appropriate when schema does all the work.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Get indexes') and target resource ('for a specific table'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'describe_table' or 'get_table_relationships' that might also provide structural information about tables.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'describe_table' (which might include index information) or clarify whether this is for database administration versus general querying. No exclusions or prerequisites are stated.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_table_relationshipsC
Get foreign key relationships for a table
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table | |
| schema | No | Schema name (default: public) | public |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Get') but does not clarify if this is a read-only operation, what permissions might be required, how results are formatted, or any limitations like rate limits. This leaves significant gaps in understanding the tool's behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, direct sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core purpose without unnecessary elaboration, earning a top score for brevity and clarity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the lack of annotations and output schema, the description is incomplete. It does not address behavioral aspects like safety, permissions, or result format, which are crucial for a tool that retrieves database metadata. This leaves the agent with insufficient context to use the tool effectively.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, with clear descriptions for both parameters in the input schema. The description does not add any additional meaning beyond what the schema provides, such as explaining the significance of foreign key relationships or usage examples. Baseline 3 is appropriate as the schema handles the parameter documentation adequately.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb ('Get') and resource ('foreign key relationships for a table'), making the purpose unambiguous. However, it does not explicitly differentiate from sibling tools like 'describe_table' or 'get_indexes', which might also provide metadata about tables, so it falls short of a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'describe_table' and 'get_indexes' available, there is no indication of whether this tool is complementary, overlapping, or exclusive, leaving the agent to infer usage context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_schemasB
List all schemas in the database
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action but doesn't describe key behaviors like whether the list is paginated, sorted, or includes metadata; what permissions are required; or if it's a read-only operation. This leaves significant gaps for an agent to understand how to use it effectively.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it easy to parse. Every part of the sentence earns its place by conveying essential information without redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is minimally adequate. It states what the tool does but lacks details on behavior, usage context, or output format, which could help an agent use it correctly. For a list operation, more context on results would be beneficial.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has 0 parameters, and the schema description coverage is 100%, so there are no parameters to document. The description doesn't need to add parameter semantics, and it appropriately avoids mentioning any. A baseline of 4 is justified as it doesn't mislead or omit parameter information.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('List') and resource ('all schemas in the database'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'list_tables' or 'describe_table', which would require mentioning what distinguishes schemas from tables or descriptions.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'list_tables' or 'describe_table'. It lacks context about scenarios where listing schemas is appropriate, such as for database exploration or schema management, and doesn't mention any prerequisites or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesB
List all tables in the database with basic information
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: public) | public |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It states this is a list operation, implying it's read-only, but doesn't mention potential side effects, permissions required, rate limits, or what 'basic information' includes (e.g., table names, row counts). For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action ('List all tables'), making it easy to parse quickly. Every part of the sentence contributes meaning.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple list tool with one optional parameter and no output schema, the description is minimally adequate but lacks depth. It doesn't explain what 'basic information' includes, how results are formatted, or any limitations (e.g., pagination). With no annotations and incomplete behavioral context, it leaves the agent guessing about practical usage details.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, with the single parameter 'schema' fully documented in the input schema (including default value). The description doesn't add any parameter-specific details beyond what the schema provides, such as explaining why schema filtering is useful or how it interacts with the 'list all tables' claim. Baseline 3 is appropriate when the schema does the heavy lifting.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb ('List') and resource ('tables in the database') with scope ('all'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'list_schemas' or 'describe_table', which would require more specific language about what distinguishes listing tables from listing schemas or describing individual tables.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'list_schemas' or 'describe_table'. It mentions 'basic information' but doesn't specify what that entails or when a more detailed tool might be needed. No exclusions or prerequisites are stated.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
5 tool updates
- First observed
describe_table - First observed
get_indexes - First observed
get_table_relationships - First observed
list_schemas - First observed
list_tables
TDQS
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
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
- dataOAuthco.thinair
Read-only PostgreSQL, MySQL, SQL Server access via MCP — 24 dialect-aware hosted tools.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
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 gradedqualityFmaintenanceEnables interaction with PostgreSQL databases through MCP, supporting queries, DDL, DML, and schema inspection.6MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI assistants to execute SQL queries and inspect PostgreSQL database schemas via MCP tools.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sbfulfil/pg-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server