postgres-mcp-server
Provides tools for interacting with a PostgreSQL database, allowing users to list tables, describe schemas, run read queries, explain query plans, get database stats, and optionally execute write queries.
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., "@postgres-mcp-serverShow me the first 10 rows from the orders 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
An enterprise-ready Model Context Protocol (MCP) server built with Node.js & TypeScript for PostgreSQL databases. Compatible with Antigravity, Claude Desktop, Cursor, Continue, and any standard MCP client.
๐ Features & Tools Exposed
Tool Name | Mode | Description |
| Read-only | Lists all schemas, tables, views, estimated row counts, and table disk sizes. |
| Read-only | Details table schema: column types, nullability, defaults, primary keys, foreign keys, and indexes. |
| Read-only | Executes SELECT queries safely inside DB-level |
| Read-only | Generates PostgreSQL query execution plans ( |
| Read-only | Returns DB health stats: database size, top 10 largest tables, active connections, and cache hit ratios. |
| Write (Optional) | Executes |
Related MCP server: PostgreSQL MCP Server
๐ ๏ธ Quick Start
1. Install Dependencies & Build
npm install
npm run build2. Configure Environment Variables
Copy .env.example to .env and fill in your PostgreSQL credentials:
# Database Connection String
DATABASE_URL=postgresql://postgres:password@localhost:5432/mydb
# OR individual settings:
PGHOST=localhost
PGPORT=5432
PGUSER=postgres
PGPASSWORD=your_password
PGDATABASE=mydb
# Enable write capabilities if needed (Default: false)
ALLOW_WRITE_QUERIES=false๐ Registering with MCP Clients
This server uses standard stdio communication and can be added to any MCP-compliant application.
1. Antigravity Configuration
Add to your Antigravity MCP settings:
Global Config:
%USERPROFILE%\.gemini\antigravity-cli\mcp_config.json(Windows) or~/.gemini/antigravity-cli/mcp_config.json(Linux/macOS)Workspace Config:
.agents/mcp.json
{
"mcpServers": {
"postgres-db": {
"command": "node",
"args": [
"D:/Projects/AI/MCP/postgres-connector/dist/index.js"
],
"env": {
"DATABASE_URL": "postgresql://your_user:your_password@localhost:5432/your_project_db",
"ALLOW_WRITE_QUERIES": "false"
}
}
}
}2. Claude Desktop Configuration
Add to your Claude Desktop configuration file:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"postgres-db": {
"command": "node",
"args": [
"D:/Projects/AI/MCP/postgres-connector/dist/index.js"
],
"env": {
"DATABASE_URL": "postgresql://your_user:your_password@localhost:5432/your_project_db",
"ALLOW_WRITE_QUERIES": "false"
}
}
}
}3. Cursor / Continue / Standard MCP Clients
For Cursor, Continue, or any other MCP host supporting stdio servers:
{
"mcpServers": {
"postgres-db": {
"command": "node",
"args": [
"D:/Projects/AI/MCP/postgres-connector/dist/index.js"
],
"env": {
"DATABASE_URL": "postgresql://your_user:your_password@localhost:5432/your_project_db",
"ALLOW_WRITE_QUERIES": "false"
}
}
}
}Tip (Development Mode): You can also run the server directly with
npx tsxwithout a build step:"command": "npx", "args": [ "-y", "tsx", "D:/Projects/AI/MCP/postgres-connector/src/index.ts" ]
๐งช Testing & Local Debugging
Option 1: Interactive GUI Testing with MCP Inspector (Recommended)
The official MCP Inspector allows you to visually trigger tool calls (list_tables, read_query, describe_table, etc.) and view response payloads in your browser:
Quick development testing (no compilation step required):
npx @modelcontextprotocol/inspector npx tsx src/index.tsProduction build testing:
npm run build npx @modelcontextprotocol/inspector node dist/index.js
The command will automatically open the inspector in your default browser (e.g. http://localhost:<port>/?MCP_INSPECTOR_API_TOKEN=...), where you can inspect available tools, fill in parameters, and view responses in real time.
Option 2: Live Integration via MCP Hosts
Register the server in your AI host config (such as Antigravity or Claude Desktop) as detailed in Registering with MCP Clients, then restart your host application to test tool invocation through natural language prompts.
Option 3: Code Compilation & Type Check
Verify TypeScript types and esbuild bundle output:
npm run build๐ Security Best Practices
By default, all queries executed via
read_queryrun insideBEGIN READ ONLY; ... COMMIT;transactions to prevent unexpected data mutations.Write queries via
execute_queryare disabled by default unlessALLOW_WRITE_QUERIES=true.
๐ License & Attribution
This project is licensed under the BSD 3-Clause License.
Mandatory Terms:
Attribution Required: You are free to use, modify, and distribute this software, provided that all copies retain the original copyright notice (
Copyright (c) 2026, Rajath Kumar D) and license terms.No Unauthorized Endorsement: You may not use the author's name (Rajath Kumar D) or contributors to endorse or promote derived products without prior written permission.
Available Tools
6 toolsdescribe_tableA
Get detailed schema breakdown for a specific table or view, including column names, data types, constraints, primary keys, foreign keys, and indexes.
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Name of the table or view | |
| schema | No | Database 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 full burden for behavioral disclosure. It does describe the contents of the return (columns, data types, constraints, etc.), which is helpful. However, it does not explicitly state that the operation is read-only, nor does it mention any limitations or error behavior. The 'Get' verb implies a safe read, but more transparency would be expected.
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, well-structured sentence that front-loads the main purpose ('Get detailed schema breakdown') and lists the specific items covered. Every word earns its place, with no redundancy or filler.
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 (2 parameters, no output schema), the description sufficiently explains the return value by enumerating the schema components. It could benefit from an example or note on error handling for non-existent tables, but for its complexity, it is largely complete.
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 already provides 100% coverage with descriptions for both parameters ('table' and 'schema'). The description does not add additional meaning to the parameters themselves, only restates that it works for a 'specific table or view', which echoes the schema. Thus baseline 3 applies.
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 provides a 'detailed schema breakdown' for 'a specific table or view', listing the exact contents (columns, types, constraints, keys, indexes). This specific verb+resource combination distinguishes it from sibling tools like list_tables (which lists tables) or execute_query (which runs queries).
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 implies usage when one needs schema details for a specific table/view, but it does not explicitly state when to use this tool over alternatives or provide any exclusions. Sibling tools are present, but the description offers no direct comparison, so the usage context is only implied.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
execute_queryA
Execute data modification statements (INSERT, UPDATE, DELETE, DDL). Requires ALLOW_WRITE_QUERIES=true in environment.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL query to execute |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden of disclosing side effects. It mentions the environment requirement and the mutation nature, but does not detail consequences like irreversibility, potential destructive effects, or return values. This is adequate but lacks depth.
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?
Two short sentences: the first states the core functionality, the second notes a key prerequisite. No wasted words, and important information is front-loaded.
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 one-parameter tool, the description covers purpose, statement types, and an environment requirement. It lacks explicit return-value information, but given the simple interface and sibling context, it's sufficiently complete.
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% coverage for the sole parameter 'sql', and the description does not add extra meaning beyond the schema. Baseline 3 applies since the schema already documents the parameter.
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 uses a specific verb ('Execute') and resource ('data modification statements') and explicitly lists statement types (INSERT, UPDATE, DELETE, DDL), which clearly distinguishes it from sibling tools like read_query. The purpose is unambiguous.
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 implies usage for write operations and names a prerequisite (ALLOW_WRITE_QUERIES=true). However, it does not explicitly mention alternatives or state when not to use it, though the write-focused wording makes the context clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
explain_queryA
Execute EXPLAIN on a SQL query to inspect query planner cost estimates, join strategies, and index usage.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL query to explain | |
| analyze | No | If true, runs EXPLAIN ANALYZE (actually executes the query to get actual timings). Default: false. |
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 disclosing behavior. It fails to mention that setting 'analyze' to true actually executes the query, which is a significant behavioral trait with potential side effects. It also omits any statement about read-only nature or return format.
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, focused sentence that is front-loaded with the action and delivers all essential purpose information with no redundancy or wasted words.
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?
While the tool is simple and the schema covers both parameters, the absence of annotations and output schema leaves gaps: the description does not explain the side effect of EXPLAIN ANALYZE or describe what the returned plan looks like. It is adequate but not fully complete for safe invocation.
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 parameters 'sql' and 'analyze' are already well-documented in the schema. The description adds no additional parameter-level meaning, which aligns with the baseline of 3 for full schema coverage.
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 uses a specific verb ('Execute EXPLAIN') and resource ('a SQL query'), and clearly distinguishes the tool from siblings by naming the diagnostic outputs (cost estimates, join strategies, index usage). It unambiguously identifies what this tool does.
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 clear context for when to use the tool: to inspect query planner cost estimates, join strategies, and index usage. It does not explicitly mention exclusions or alternatives, but the sibling tools (e.g., read_query, execute_query) are implicitly distinct.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_db_statsA
Retrieve database health & performance metrics: database size, top tables by disk usage, active connections, and cache hit ratio.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description bears full responsibility. It implies a read-only operation via 'Retrieve' and specifies the measured metrics, giving useful transparency. However, it omits details like potential performance impact, permission requirements, or output structure, leaving some gaps.
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, tightly packed sentence that front-loads the action and resource, followed by a concise list of metrics. Every word adds value with no 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?
For a simple, parameterless diagnostic tool with no output schema, the description adequately conveys the core purpose and key metrics. However, it does not specify details like the ordering or limit of 'top tables' or the exact format of the returned data, leaving minor ambiguity.
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 zero parameters, and the schema confirms this (100% coverage). The baseline for 0 params is 4, and the description correctly focuses on the output without needing to explain parameters.
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 uses the specific verb 'Retrieve' and clearly identifies the resource as 'database health & performance metrics,' enumerating concrete outputs: database size, top tables by disk usage, active connections, and cache hit ratio. This clearly differentiates it from sibling tools like list_tables or read_query, which serve different purposes.
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 gives clear context: use this tool when you need database health or performance metrics. It does not explicitly name alternatives or state when not to use it, but the unique purpose within the sibling group is evident.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesA
List all tables, views, and schemas in the PostgreSQL database along with estimated row counts and table sizes.
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Database schema name (default: "public") | |
| include_views | No | Whether to include database views (default: true) |
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. It clearly describes a read-only listing operation and discloses that row counts are 'estimated', which signals approximate values. However, it does not explicitly state that the tool is non-destructive or requires no special permissions. Still, the term 'list' implies a safe read operation, and the 'estimated' caveat adds useful behavioral nuance, meriting a score above baseline.
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 concise sentence that front-loads the core purpose ('List all tables, views, and schemas') and immediately follows with the key output details ('estimated row counts and table sizes'). Every word earns its place, with no redundancy or filler.
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 low complexity, lack of output schema, and no annotations, the description is fairly complete: it states what the tool lists and what accompanying data is returned. The only minor gap is a slight ambiguity over the phrase 'and schemas' (whether schemas are listed as separate objects or just included as context), but this is a small omission in an otherwise adequate description.
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 already provides 100% description coverage for both parameters: 'schema' (Database schema name, default public) and 'include_views' (Whether to include database views, default true). The tool description does not add any additional meaning beyond the schema, so the baseline score of 3 applies. No enrichment of parameter semantics is present.
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 uses the specific verb 'List' and clearly identifies the resource: 'all tables, views, and schemas in the PostgreSQL database'. It also specifies additional output details ('estimated row counts and table sizes'), which distinguishes it from sibling tools like describe_table (which describes a single table) and get_db_stats (which focuses on database stats). This leaves no ambiguity about the tool's function.
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 does not mention that describe_table is more appropriate for inspecting a specific table, or that get_db_stats is useful for broader database statistics. There is no explicit when-to-use or when-not-to-use context, so the agent is left to infer usage solely from the tool name.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
read_queryA
Execute a read-only SQL query (SELECT, WITH, etc.). Strictly executed inside a DB-level READ ONLY transaction for safety.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL SELECT query to execute | |
| limit | No | Maximum rows to return (default: 100, max: 1000) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden. It transparently discloses that the query runs inside a DB-level READ ONLY transaction for safety, which is critical behavioral context beyond just saying 'read-only'. It does not detail return format or error handling, but the transaction safety note adds meaningful value.
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 two sentences long, front-loads the primary action, and contains no superfluous words. Every phrase earns its place, including the safety qualifier.
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 two-parameter, no-output-schema tool, the description adequately covers the core purpose and the key safety behavior (READ ONLY transaction). It falls short of explaining return structure or error behavior, but given the simplicity and the read-only guarantee, it is reasonably complete.
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 coverage is 100%, so per guidelines the baseline is 3. The description does not add extra meaning beyond the schema: the 'sql' parameter is already described as 'The SQL SELECT query to execute', and 'limit' has its default and max documented. The description's emphasis on read-only does not alter parameter semantics.
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 a specific verb ('Execute') and resource ('read-only SQL query'), and explicitly limits to SELECT, WITH, etc. This distinguishes it from sibling execute_query, which likely handles writes.
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 tool is explicitly described as read-only, making it clear it should be used for queries that do not modify data. It does not explicitly name alternatives or exclusions, but the read-only qualifier provides sufficient guidance compared to the execution-querysibling.
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.
6 tool updates
v1.0.0- First observed
describe_table - First observed
execute_query - First observed
explain_query - First observed
get_db_stats - First observed
list_tables - First observed
read_query
TDQS
Each tool targets a distinct function: listing tables, describing schema, executing read-only queries, explaining query plans, retrieving database stats, and executing write operations. There is no overlap or ambiguity between tool purposes.
All tool names follow a consistent verb_noun pattern in snake_case (list_, describe_, read_, explain_, get_, execute_). The naming is uniform and predictable.
With 6 tools, the set is concise and well-scoped for a PostgreSQL server, covering the essential operations without unnecessary bloat or sparse coverage.
The tool surface covers the full lifecycle of database interaction: discovery, schema inspection, read queries, write queries, query planning, and server statistics. No critical gaps are apparent for the intended purpose.
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
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
- dataOAuthco.thinair
Read-only PostgreSQL, MySQL, SQL Server access via MCP โ 24 dialect-aware hosted tools.
MCP server for querying and analyzing data from ad platforms, analytics tools, and spreadsheets
Related MCP Servers
- AlicenseAqualityAmaintenanceMCP server with 14 tools for PostgreSQL database operations. Query databases, explore schemas, analyze tables, with SQL injection prevention and read-only mode by default.1410MIT
- AlicenseNot gradedqualityDmaintenanceAn open-source MCP server for PostgreSQL schema introspection and guarded read-only queries. It enables MCP clients to discover schemas, tables, columns, indexes, relationships, and safe queryable data from a configured PostgreSQL database.13MIT
- AlicenseNot gradedqualityCmaintenanceRead-only PostgreSQL MCP server that enables running SELECT queries, listing tables and schemas, and describing columns, with built-in protection against writes and malicious SQL attacks.751MIT
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.1427MIT
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/rajath002/postgres-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server