MCP PostgreSQL Server
The MCP PostgreSQL Server enables AI models to interact with PostgreSQL databases through a standardized interface. With this server, you can:
Connect to databases: Establish connections using credentials via the
connect_dbtoolQuery data: Execute SELECT queries with support for prepared statements ($1, $2, ?)
Modify data: Run INSERT, UPDATE, or DELETE operations with parameter support
Database introspection: List schemas, tables (with optional schema filter), and describe table structures
This server provides a comprehensive set of tools for database connectivity, querying, data manipulation, and schema exploration.
Supports installation and execution through npm and npx commands, allowing for easy deployment and integration of the MCP server within Node.js environments.
Enables interaction with PostgreSQL databases, providing tools for executing queries, managing database connections, listing tables, and describing table structures with support for prepared statements and comprehensive error handling.
Offers TypeScript support for type-safe interactions with PostgreSQL databases through the MCP server interface.
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., "@MCP PostgreSQL Servershow me the 10 most recent orders from the sales 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.
MCP PostgreSQL Server
A Model Context Protocol server that provides PostgreSQL database operations. This server enables AI models to interact with PostgreSQL databases through a standardized interface.
Installation
Manual Installation
npm install mcp-postgres-serverOr run directly with:
npx mcp-postgres-serverRelated MCP server: PostgreSQL MCP Server
Configuration
The server requires the following environment variables:
{
"mcpServers": {
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-postgres-server"],
"env": {
"PG_HOST": "your_host",
"PG_PORT": "5432",
"PG_USER": "your_user",
"PG_PASSWORD": "your_password",
"PG_DATABASE": "your_database"
}
}
}
}Available Tools
1. connect_db
Establish connection to PostgreSQL database using provided credentials.
use_mcp_tool({
server_name: "postgres",
tool_name: "connect_db",
arguments: {
host: "localhost",
port: 5432,
user: "your_user",
password: "your_password",
database: "your_database"
}
});2. query
Execute SELECT queries with optional prepared statement parameters. Supports both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders.
use_mcp_tool({
server_name: "postgres",
tool_name: "query",
arguments: {
sql: "SELECT * FROM users WHERE id = $1",
params: [1]
}
});3. execute
Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. Supports both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders.
use_mcp_tool({
server_name: "postgres",
tool_name: "execute",
arguments: {
sql: "INSERT INTO users (name, email) VALUES ($1, $2)",
params: ["John Doe", "john@example.com"]
}
});4. list_schemas
List all schemas in the connected database.
use_mcp_tool({
server_name: "postgres",
tool_name: "list_schemas",
arguments: {}
});5. list_tables
List tables in the connected database. Accepts an optional schema parameter (defaults to 'public').
// List tables in the 'public' schema (default)
use_mcp_tool({
server_name: "postgres",
tool_name: "list_tables",
arguments: {}
});
// List tables in a specific schema
use_mcp_tool({
server_name: "postgres",
tool_name: "list_tables",
arguments: {
schema: "my_schema"
}
});6. describe_table
Get the structure of a specific table. Accepts an optional schema parameter (defaults to 'public').
// Describe a table in the 'public' schema (default)
use_mcp_tool({
server_name: "postgres",
tool_name: "describe_table",
arguments: {
table: "users"
}
});
// Describe a table in a specific schema
use_mcp_tool({
server_name: "postgres",
tool_name: "describe_table",
arguments: {
table: "users",
schema: "my_schema"
}
});Features
Secure connection handling with automatic cleanup
Prepared statement support for query parameters
Support for both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders
Comprehensive error handling and validation
TypeScript support
Automatic connection management
Supports PostgreSQL-specific syntax and features
Multi-schema support for database operations
Security
Uses prepared statements to prevent SQL injection
Supports secure password handling through environment variables
Validates queries before execution
Automatically closes connections when done
Error Handling
The server provides detailed error messages for common issues:
Connection failures
Invalid queries
Missing parameters
Database errors
License
MIT
Available Tools
6 toolsconnect_dbA
Connect to PostgreSQL database. NOTE: Default connection exists - only use when requested or if other commands fail
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | Database host | |
| port | No | Database port (default: 5432) | |
| user | Yes | Database user | |
| password | Yes | Database password | |
| database | Yes | Database name |
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 mentions the existence of a default connection and usage constraints, which adds useful context beyond basic functionality. However, it lacks details on error handling, connection persistence, or authentication requirements, leaving gaps in behavioral understanding for a connection tool.
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 and front-loaded, with the core purpose stated first followed by critical usage notes. Every sentence earns its place by providing essential information without redundancy, making it efficient and easy to parse.
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 complexity (connection establishment with multiple parameters) and lack of annotations or output schema, the description is reasonably complete. It covers purpose and usage guidelines well, but could benefit from more behavioral details (e.g., what happens on success/failure) to fully compensate for the missing structured data.
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 documents all five parameters (host, port, user, password, database) with their types and descriptions. The description does not add any additional meaning or context about the parameters beyond what the schema provides, meeting the baseline expectation when schema coverage is high.
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 specific action ('Connect to PostgreSQL database') and resource ('PostgreSQL database'), making the purpose immediately understandable. It distinguishes this tool from sibling tools like 'query' or 'execute' by focusing on establishing a database connection rather than performing operations on an already connected database.
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 explicit guidance on when to use this tool ('only use when requested or if other commands fail') and when not to use it ('Default connection exists'), offering clear context for its application. This helps the agent avoid unnecessary invocations when a default connection is already available.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
describe_tableC
Get table structure
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name | |
| schema | No | Schema name (default: public) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. 'Get table structure' suggests a read-only operation, but it doesn't specify whether it requires authentication, has rate limits, returns detailed metadata (e.g., column types, constraints), or handles errors. This leaves significant gaps for a tool with potential database interactions.
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 with just three words, making it front-loaded and efficient. However, it might be overly terse, potentially sacrificing clarity for brevity, as it could benefit from slightly more detail to fully convey the tool's scope.
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 doesn't explain what 'table structure' entails (e.g., column definitions, indexes), how results are formatted, or any behavioral aspects like error handling. For a database tool with potential complexity, this leaves too much unspecified.
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 input schema has 100% description coverage, clearly documenting both parameters ('table' and 'schema') with their types and defaults. The description adds no additional meaning beyond what the schema provides, such as examples or constraints, but the schema is sufficient, so a baseline score of 3 is appropriate.
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 'Get table structure' clearly states the verb ('Get') and resource ('table structure'), making the purpose understandable. However, it doesn't differentiate from potential sibling tools like 'list_tables' or 'query', and 'structure' could be interpreted as metadata, columns, or schema details without further clarification.
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 explicit guidance is provided on when to use this tool versus alternatives like 'list_tables' or 'query'. The description implies it's for retrieving structural information, but it doesn't specify prerequisites (e.g., needing a database connection) or exclusions (e.g., not for data retrieval).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
executeC
Execute an INSERT, UPDATE, or DELETE query
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query (INSERT, UPDATE, DELETE) (use $1, $2, etc. for parameters) | |
| params | No | Query parameters (optional) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. While it indicates this is a mutation tool (INSERT, UPDATE, DELETE), it doesn't cover critical aspects like required permissions, transaction behavior, error handling, rate limits, or what happens on success/failure. The description is insufficient for a tool that modifies data.
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 wasted words. It's appropriately sized and front-loaded with the core functionality.
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 mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address behavioral expectations, error conditions, or return values. Given the complexity of executing data-modifying SQL queries, this leaves significant gaps for an AI agent.
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 documents both parameters thoroughly. The description doesn't add any meaningful semantic context beyond what's in the schema (e.g., it doesn't explain parameter binding patterns or SQL injection risks). 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 tool executes SQL queries (INSERT, UPDATE, DELETE), which is a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'query' tool, which likely handles SELECT queries, leaving some ambiguity about when to use each.
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 the 'query' sibling tool. It mentions the types of SQL queries supported but doesn't specify prerequisites, exclusions, or contextual usage scenarios.
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 a read operation ('List'), implying it's likely non-destructive, but doesn't cover aspects like permissions required, rate limits, pagination, or the format of the returned list. For a tool with zero annotation coverage, this is a significant gap in transparency.
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 zero waste. It's front-loaded with the core purpose and appropriately sized for a simple tool, making it highly efficient and easy to parse.
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 adequate but has clear gaps. It covers the basic purpose but lacks behavioral details and usage context. For a tool that likely returns a list of schemas, more information on output format or dependencies would improve completeness.
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 input schema has 0 parameters with 100% coverage, meaning no parameters are documented in the schema. The description doesn't add parameter details, but since there are no parameters, this is acceptable. Baseline is 4 for 0 parameters, as the description doesn't need to compensate for missing schema 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 immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'list_tables' or 'describe_table', which might handle similar database metadata operations, so it misses the highest 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 such as 'list_tables' or 'describe_table'. It lacks context about prerequisites (e.g., whether a database connection is needed) or exclusions, leaving the agent to infer usage from the tool name alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesC
List tables in the database
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: 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 ('List') but doesn't describe what 'List' entails—e.g., whether it returns all tables, if there's pagination, what format the output is in, or any permissions required. For a tool with no annotation coverage, this is a significant gap in transparency.
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 is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration. Every word earns its place, making it highly concise.
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 (1 optional parameter, no output schema, no annotations), the description is incomplete. It lacks details on output format, behavioral traits, or usage context, which are necessary for an agent to effectively invoke and interpret results. This is inadequate for even a simple tool.
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 input schema has 100% description coverage, with the single parameter 'schema' documented as 'Schema name (default: public)'. The description adds no parameter semantics beyond what the schema provides, so it meets the baseline of 3 where the schema does the heavy lifting. No additional value is contributed.
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'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'list_schemas' or 'describe_table', but the specificity of 'tables' provides some implicit distinction. This is clear but lacks explicit sibling differentiation.
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 prerequisites (e.g., needing to connect to the database first), when to prefer 'list_schemas' or 'describe_table', or any usage constraints. This leaves the agent with minimal context for tool selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
queryC
Execute a SELECT query
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL SELECT query (use $1, $2, etc. for parameters) | |
| params | No | Query parameters (optional) |
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. 'Execute a SELECT query' implies a read-only operation, but it doesn't confirm safety (e.g., that it won't modify data), describe error handling, rate limits, or authentication needs. For a database query tool with zero annotation coverage, this leaves critical behavioral traits unspecified.
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 action ('Execute a SELECT query'), making it immediately clear. Every word earns its place, and there's no unnecessary elaboration or repetition.
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 complexity of database operations and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., result sets, error messages), performance implications, or connection requirements. For a tool that executes SQL queries, more context is needed to guide the agent 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?
Schema description coverage is 100%, with both parameters ('sql' and 'params') well-documented in the schema. The description adds no parameter semantics beyond what the schema provides (e.g., it doesn't explain SQL syntax, parameter binding rules, or result formatting). With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't enhance parameter understanding.
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 'Execute a SELECT query' clearly states the verb ('Execute') and resource ('SELECT query'), making the purpose understandable. However, it doesn't distinguish this tool from its sibling 'execute' (which likely handles non-SELECT queries), leaving ambiguity about when to use each. The purpose is clear but lacks sibling differentiation.
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 when to use 'query' vs 'execute' (a sibling tool), nor does it specify prerequisites like needing an established database connection. Without any usage context or exclusions, the agent must infer when this tool is appropriate.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
Most tools have distinct purposes: list_schemas and list_tables are clearly different, describe_table is unique, and query vs execute handle different SQL types. However, 'execute' and 'query' could potentially be confused since both run SQL commands, though their descriptions clarify one is for SELECT and the other for INSERT/UPDATE/DELETE.
Tools follow a consistent verb_noun pattern (e.g., list_schemas, describe_table, execute_query would have been more consistent but 'query' and 'execute' are verbs alone). Minor deviation: 'connect_db' uses a verb_noun format while 'query' and 'execute' are standalone verbs, but overall naming is readable and predictable.
With 6 tools, this is well-scoped for a PostgreSQL server. It covers essential database operations without being overwhelming. Each tool has a clear role, and the count aligns with typical MCP server ranges for this domain.
The toolset covers core CRUD operations via query and execute, and metadata exploration with list/describe tools. However, there are notable gaps: no tools for creating/dropping tables, managing indexes, or handling transactions, which are common in database workflows. The surface is functional but incomplete for full database management.
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
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Your Supabase account in natural language: run SQL, apply migrations, manage tables, storage, edge f
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to interact deeply with PostgreSQL databases—query data, manage schema, analyze performance, and administer the database.1214MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.101
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with PostgreSQL databases through the Model Context Protocol, supporting SQL queries, schema management, and data operations.19MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.2
Appeared in Searches
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/antonorlov/mcp-postgres-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server