mcp-postgres-query
Connects to any PostgreSQL database, allowing schema exploration, SQL query execution, and performance analysis through natural conversation.
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-postgres-queryWhat tables are in this database?"
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-postgres-query
MCP server that connects Claude to any PostgreSQL database. Explore schemas, run queries, analyze performance — all through natural conversation.
Built by THRYXAGI.
Install
npm install -g mcp-postgres-queryOr run directly:
npx mcp-postgres-queryRelated MCP server: PostgreSQL MCP Server
Configuration
Set the DATABASE_URL environment variable with your PostgreSQL connection string:
DATABASE_URL=postgresql://user:password@localhost:5432/mydbClaude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "mcp-postgres-query"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"
}
}
}
}Claude Code
Add to your .mcp.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "mcp-postgres-query"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"
}
}
}
}Tools (7)
Tool | Description | Params |
| Execute a SQL query |
|
| List all tables in the public schema | none |
| Get column details (type, nullable, default) |
|
| List indexes on a table |
|
| Get EXPLAIN ANALYZE plan (safe, rolls back) |
|
| Row counts and table size |
|
| Database overview (version, size, table count) | none |
Example Usage
Once connected, ask Claude things like:
"What tables are in this database?"
"Describe the users table"
"SELECT * FROM orders WHERE created_at > '2024-01-01' LIMIT 10"
"Explain this slow query: SELECT ..."
"How big is the events table?"
Security Notes
The
querytool executes arbitrary SQL. Connect with a read-only database user for safety.The
explain_querytool wraps EXPLAIN ANALYZE in a transaction that always rolls back, so it never modifies data.Parameterized queries are supported via the
paramsargument to prevent SQL injection.Never expose
DATABASE_URLin public repositories or logs.
License
MIT
Available Tools
7 toolsdescribe_tableA
Get detailed column information for a table: column name, data type, nullable, default value, character max length, and ordinal position.
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description must disclose behavior. It lists the returned fields, which is helpful, but it does not mention whether the operation is read-only, whether it requires table existence, or any error behavior. It doesn't contradict any annotations (none exist), but it leaves some behavioral aspects 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 sentence that front-loads the action and enumerates exactly what information is returned. Every word is useful, with no filler 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 lack of an output schema, the description attempts to list the output fields, which aids the agent. However, it does not specify the exact result format (e.g., list of rows, order) or handle error cases, and it relies on the agent inferring the read-only nature. It is adequate for a simple metadata tool but leaves minor gaps.
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 already describes table_name as 'Name of the table to describe' (100% coverage), and the tool description does not add extra parameter meaning like format or qualification requirements. The description's mention of 'a table' is redundant with the schema.
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 retrieves detailed column information for a table, enumerating specific attributes. This distinguishes it from siblings like list_tables (table names) and list_indexes (index details), making the purpose 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 the tool is appropriate when column-level metadata is needed, but it does not explicitly contrast with alternatives or state when not to use it. For example, it doesn't mention that list_tables is for table names, so usage guidance is implicit rather than explicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
explain_queryA
Get the EXPLAIN ANALYZE execution plan for a SQL query. The query runs inside a transaction that is always rolled back, so it never modifies data.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to explain |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden. It discloses a key behavioral trait: the query runs inside a transaction that always rolls back, ensuring no data modification. This adds safety context beyond simply 'explain'. However, it does not mention that EXPLAIN ANALYZE actually executes the query, which could have performance implications, nor any permission requirements.
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 with no filler. It front-loads the purpose and then adds a behavioral safety note. Every sentence earns its place.
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 a simple one-parameter tool with no annotations or output schema, the description covers the essential purpose and the critical safety guarantee. However, it does not describe the format of the returned execution plan or note that the query is actually executed (which might matter for planning). Still, it is adequate for an agent to select and invoke the tool correctly.
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 describes the sole parameter (sql) as 'SQL query to explain' with 100% coverage. The description reinforces the purpose but adds no new parameter-specific details such as syntax constraints or how the query string is processed. Therefore, it hovers at the baseline.
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 retrieves the EXPLAIN ANALYZE execution plan for a SQL query, which distinguishes it from sibling tools like query (executing queries) and list_tables/describe_table (schema introspection). The verb 'Get' and specific resource 'EXPLAIN ANALYZE execution plan' make the purpose explicit.
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 analyzing execution plans but does not explicitly state when to prefer this over sibling tools like query, nor does it mention alternatives or exclusions. The rollback note provides context that it is safe for read-only analysis, but there is no direct guidance on when to use it versus other tools.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_db_infoA
Get an overview of the connected database: PostgreSQL version, database name, total size on disk, number of tables, and current connection info (user, host, port).
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden of behavior disclosure. It lists the output fields but does not explicitly state that the operation is read-only, mention prerequisites like an active connection, or describe potential errors. For a simple getter, this is moderate 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 sentence that front-loads the action and resource, then concisely lists the returned information. There is no redundancy or filler, making it highly efficient.
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?
This is a low-complexity tool with no parameters, no output schema, and no annotations. The description fully specifies the output and the database system (PostgreSQL), which is sufficient for an agent to select and invoke the tool correctly.
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 zero parameters, so the description does not need to explain any parameter details. According to the baseline for zero-parameter tools, a score of 4 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 clearly states the tool's purpose with a specific verb ('Get') and resource ('overview of the connected database'). It enumerates the exact data returned (version, name, size, table count, connection info), distinguishing it from siblings like list_tables or describe_table.
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: when a database-level overview is needed. It does not explicitly name alternatives, but the specificity of the returned fields makes the appropriate usage evident. No exclusions are mentioned, so it falls short of a 5.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_table_statsA
Get statistics for a table: estimated row count (from pg_stat), live/dead tuples, last vacuum/analyze times, and total disk size.
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table |
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 discloses that the row count is 'estimated (from pg_stat)', which is a key behavioral caveat. It also enumerates all returned statistics, giving the agent a clear expectation of the output. It does not mention permissions or error handling, but for a stats tool this is reasonably transparent.
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, information-dense sentence. It front-loads the action and lists all key output items, earning every word with no repetition 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?
The tool is simple with one parameter and no output schema. The description adequately covers the return values and the estimated nature of the row count. It could mention behavior for missing tables, but overall it is complete for typical use.
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% (table_name is documented as 'Name of the table'), and the description does not add additional semantic meaning beyond that. The baseline of 3 applies since the schema is sufficient.
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's purpose: getting statistics for a table, listing specific stats (row count, tuples, vacuum/analyze times, disk size). It uses a specific verb ('Get') and resource ('statistics for a table'), which distinguishes it from sibling tools like list_tables or describe_table.
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 context is clear: use when you need table statistics such as row counts, vacuum times, or disk size. It does not explicitly name alternatives or exclusions, but the scope is obvious given the sibling tools, so it meets the 'clear context, no exclusions' criterion.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_indexesA
List all indexes on a given table, including index name, whether it is unique, and the index definition.
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description must carry the transparency burden. It clearly conveys a read-only listing operation and discloses the key output fields (index name, uniqueness, definition). There are no hidden side effects or mutations indicated.
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 action and includes essential output details. Every word contributes 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 single-parameter listing tool with no output schema, the description adequately specifies the returned information (index name, unique flag, definition). It does not cover edge cases like nonexistent tables, but this is not critical for such a straightforward operation.
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% (table_name is described as 'Name of the table'). The description only restates that it operates on a table, adding no additional semantic detail beyond the schema.
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 ('List') and resource ('indexes on a given table'), and states exactly what is included (index name, uniqueness, definition). This clearly distinguishes it from sibling tools like list_tables or describe_table.
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 when to use the tool (when you need index information for a specific table) but does not explicitly mention alternatives or when not to use it. No exclusions or comparisons to siblings are provided.
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 in the public schema of the connected database. Returns table names, types (BASE TABLE or VIEW), and the schema they belong to.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden of disclosure. It specifies the return content (table names, types, schema) and the scope limitation to the public schema. This is adequate for a simple read-only listing tool, though it does not explicitly mention that it is non-destructive (which is implied).
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 sentence that is front-loaded with the action and scope, and it includes the key return fields. No redundant 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?
Given the tool's low complexity (no parameters, no nested objects) and lack of an output schema, the description adequately explains what will be returned and the scope. It is complete for its intended use.
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, so the description is not required to explain parameter behavior. The schema description coverage is 100% (no properties), and the description adds context about the output rather than input, which is acceptable. Baseline 4 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's function: 'List all tables in the public schema of the connected database.' This is a specific verb+resource+scope, and it distinguishes from sibling tools like describe_table (which targets a specific table) and list_indexes (which lists indexes).
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 you need an overview of tables in the public schema) but provides no explicit guidance on when to use this over alternatives or any exclusions. The context is clear but not elaborated.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
queryB
Execute a SQL query against the PostgreSQL database. Supports parameterized queries for safety. Returns rows and row count.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to execute | |
| params | No | Optional array of parameters for parameterized queries (e.g. $1, $2) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries full burden but fails to disclose that arbitrary SQL may modify data, and does not mention side effects, transaction behavior, or error handling. It only notes parameterized safety and returns, which does not cover the potentially destructive nature of executing arbitrary SQL.
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 three short sentences, front-loaded with the action verb, and each sentence adds a distinct point: purpose, safety feature, and return value. It contains no fluff or redundancy, making it highly concise and well-structured.
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?
No output schema or annotations exist, so the description's mention of 'rows and row count' is helpful but incomplete—it omits return format, error behavior, and mutation warnings. However, the tool is simple (2 params, 1 required) and the core purpose is adequately stated, making it minimally viable.
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%, as both 'sql' and 'params' have descriptions. The description's mention of 'parameterized queries for safety' adds no new semantic detail beyond the schema's existing explanation of the params array, so it does not elevate the score above the baseline.
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 ('SQL query against the PostgreSQL database'), clearly distinguishing it from sibling metadata tools like list_tables and describe_table. It also notes parameterized queries and return of rows/row count, reinforcing its role as the primary query executor.
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 explain_query or list_tables. No exclusions, prerequisites, or situational recommendations are mentioned, leaving the agent to infer usage from the tool name and sibling list.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
Each tool has a distinctly different purpose: query executes SQL, list_tables lists tables, describe_table shows columns, list_indexes shows indexes, explain_query shows execution plans, get_table_stats shows table statistics, and get_db_info shows database overview. There is no functional overlap.
Most tools follow a clear verb_object pattern (list_tables, describe_table, get_table_stats) with consistent lowercase snake_case. The sole deviation is 'query', which is a single verb without an explicit object, but it is still understandable and fits the server's purpose.
With 7 tools, the server is well-scoped for its purpose. It covers querying, schema inspection, and database metadata without being bloated or sparse. This is an ideal size for a PostgreSQL query-focused MCP server.
The tool set covers core database operations: executing queries, exploring tables and columns, inspecting indexes, and retrieving performance statistics. Minor gaps exist, such as missing explicit list_schemas or list_functions tools, but these are easily worked around using the query tool, and the overall surface is sufficient for most tasks.
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.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Connect Claude to your Platform7n workspaces — chat, links, and tasks. One-click OAuth.
Connect Claude to Fathom meeting recordings, transcripts, and summaries
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides authenticated access to PostgreSQL databases for Claude AI, enabling users to browse database tables, discover schemas, and execute custom SQL queries through natural language interaction.
- AlicenseNot gradedqualityDmaintenanceEnables Claude to interact with PostgreSQL databases by executing SQL queries, exploring schemas, and monitoring database health. It provides tools for data manipulation and schema management via a secure SSE connection.290MIT
- FlicenseNot gradedqualityDmaintenanceEnables Claude Desktop to interact with PostgreSQL databases through natural language for schema exploration, data analysis, and query execution. Users can search schemas, describe tables, and perform read or write operations without needing to write manual SQL.
- AlicenseAqualityAmaintenanceQuery and manage PostgreSQL databases from Claude Code, Cursor, and any MCP client, with read-only by default and built-in schema introspection, EXPLAIN, and performance diagnostics.236,9773MIT
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/lordbasilaiassistant-sudo/mcp-postgres-query'
If you have feedback or need assistance with the MCP directory API, please join our Discord server