Skip to main content
Glama
udaykumar-dhokia

postgresql-mcp

PostgreSQL MCP

A Model Context Protocol (MCP) server that provides AI assistants (like Claude) with tools to directly interact with PostgreSQL databases securely.

Features

  • create_table: Create a new table with custom columns.

  • list_tables: List all tables in the public schema.

  • describe_table: Get the schema and column details of a specific table.

  • execute_sql: Execute arbitrary SQL queries.

  • Web Configurator: A built-in local web UI to securely manage connection strings and generate API keys.

Related MCP server: PostgreSQL API SSH MCP Server

Installation

You can install and run this package easily using uv:

# Run without installing globally
uvx postgresql-mcp

# Or install globally for easy access
uv tool install postgresql-mcp

Setup & Configuration

This project requires an API Key mapped to your PostgreSQL database URL. To easily set this up, we provide a built-in Web Configurator.

1. Generate an API Key

Run the web configurator:

postgresql-mcp-web

Or, if running without global installation:

uvx --from . postgresql-mcp-web

Open your browser to http://localhost:8000. Enter your database URL (postgresql://user:pass@host/db) and click "Generate API Key".

The application securely stores your credentials in ~/.sql-mcp/keys.json and outputs a configuration snippet.

2. Connect Claude Desktop

Copy the generated snippet and add it to your Claude Desktop configuration file (typically located at %APPDATA%\Claude\claude_desktop_config.json on Windows or ~/Library/Application Support/Claude/claude_desktop_config.json on macOS).

{
  "mcpServers": {
    "postgresql-mcp": {
      "command": "uvx",
      "args": [
        "postgresql-mcp"
      ],
      "env": {
        "API_KEY": "postgresql-mcp-your-generated-key"
      }
    }
  }
}

Restart Claude Desktop, and your AI assistant will now be able to interact with your database!

Usage Tracking

The server automatically tracks how many times each API key is utilized. You can view this data locally in ~/.sql-mcp/usage.json.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on how to get started.

Available Tools

4 tools
create_tableA

Create a table with custom columns.

Example: table_name = "users" columns = { "id": "SERIAL PRIMARY KEY", "name": "TEXT NOT NULL", "age": "INT", "created_at": "TIMESTAMP DEFAULT CURRENT_TIMESTAMP" }

ParametersJSON Schema
NameRequiredDescriptionDefault
columnsYes
table_nameYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the burden of disclosing side effects. It states the create action but does not say what happens if the table already exists, whether the operation is destructive, whether permissions are needed, or whether it returns any confirmation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and front-loaded, with the example earning its place because the schema provides no parameter documentation. No filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The example makes the core call pattern clear, but the description omits behavior on conflicts (table already exists), error conditions, and post-creation confirmation. Moderate complexity tool with no annotations; enough to attempt a call but not to use it reliably in edge cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the example gives concrete meaning to both parameters: table_name is a quoted string, columns maps names to SQL type definitions like 'TEXT NOT NULL'. This is valuable, though it doesn't cover edge cases or allowed syntax.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific action—'Create a table with custom columns'—that is clearly separate from the sibling tools (list, describe, execute SQL). The example reinforces the resource and scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides no guidance on when to use create_table over execute_sql, which could also create tables. There is no mention of prerequisites or conditions where an alternative is preferred.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

describe_tableA

Describe table structure (columns, types, nullability, default).

ParametersJSON Schema
NameRequiredDescriptionDefault
table_nameYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

There are no annotations, so the description carries the full burden of behavioral disclosure. 'Describe table structure' strongly implies a read-only metadata operation with no side effects, which covers the most important behavioral trait. However, it does not explicitly state read-only semantics, error behavior for missing tables, or any permission requirements. This is adequate but not thorough.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that front-loads the core action ('Describe table structure') and immediately specifies the returned components. There is no filler or redundant restatement of the tool name.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read-only metadata tool with one obvious parameter, the description covers the essentials: what the tool returns and the target resource. The presence of an output schema reduces the need to document return values, though the description still lists them. It is missing explicit guidance on error behavior and permissions, but for this tool's simplicity the description is nearly complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has zero description coverage, and the description does not explicitly explain the table_name parameter. However, the parameter is self-evident given the tool name and the phrase 'Describe table structure', which implies the named table is the target. The description adds minimal meaning beyond the schema and does not fully compensate for the lack of schema documentation, but the single parameter poses little ambiguity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Describe') and a concrete resource ('table structure'), and enumerates the relevant aspects ('columns, types, nullability, default'). This clearly distinguishes it from siblings like create_table and list_tables, which handle creation and enumeration rather than schema introspection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is given about when to use this tool versus its siblings. The description only states what the tool does; it does not mention that list_tables is for enumerating tables or that execute_sql is for arbitrary queries. Usage context is entirely implied rather than stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

execute_sqlB

Execute any SQL query. WARNING: Full database access.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes

TDQS

B3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the behavioral disclosure burden. 'WARNING: Full database access' meaningfully signals broad read/write/destructive capability. However, it does not describe return behavior, transaction commit semantics, or whether queries execute immediately with no confirmation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two short sentences deliver the core purpose and the key warning with no wasted words. The front-loaded action and warning make the definition efficient and easy to scan.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a potentially destructive tool with no annotations and no output schema, this is under-specified. It lacks usage routing, side-effect expectations, and return format details. The warning is helpful but insufficient for an agent to fully anticipate the consequences of invoking the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description adds little beyond restating that the query is arbitrary SQL. It provides no syntax guidance, examples, or constraints such as whether multiple statements are allowed. The single 'query' parameter is self-explanatory, but the description does not compensate for the missing schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the action and resource: execute any SQL query. The phrase 'any SQL query' signals that this is a general-purpose tool rather than a table-specific one, though it does not explicitly name or contrast the siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is given about when to use this tool versus the sibling tools like list_tables or describe_table. The warning implies the tool is powerful and should be used carefully, but it does not state when to prefer it or when to avoid it.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. The description clearly indicates a read-only listing operation with no side effects, but it does not explicitly state that it makes no modifications or whether it requires any special permissions. It is adequate for a simple zero-parameter tool but is minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no unnecessary words. It states the action and scope directly, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter, read-only listing tool with an output schema, the description is sufficient. It fully covers what the tool does and does not require explaining return values since the output schema exists. The simplicity of the tool means no additional context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters and 100% schema coverage, so the schema already provides all necessary information. The description adds no parameter details, but none are needed. The baseline for 0 parameters is 4, which is appropriate here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('List') and a well-scoped resource ('all tables in the public schema'). This clearly distinguishes it from sibling tools like create_table, describe_table, and execute_sql, since it uniquely targets table listing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The intended use is implied by the name and description, but the description gives no explicit guidance about when to prefer this tool over alternatives, nor any exclusions. It is obvious enough for a simple list operation, but could have mentioned that this only lists tables, not views or other schema objects.

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.

  1. 4 tool updatesv0.1.0
    • First observedcreate_table
    • First observeddescribe_table
    • First observedexecute_sql
    • First observedlist_tables

TDQS

A3.7/5.0

Scored across 4 tools

Disambiguation4/5

The structured tools (create_table, list_tables, describe_table) have clear, distinct purposes, and execute_sql is explicitly a general SQL escape hatch. However, execute_sql overlaps with all of them, especially create_table, since table creation can be done through either tool.

Naming Consistency5/5

All tool names follow the same verb_noun snake_case pattern: create_table, list_tables, describe_table, execute_sql. There are no mixed conventions or inconsistent verb styles.

Tool Count5/5

Four tools is a reasonable, well-scoped set for a PostgreSQL server: three schema-oriented helpers plus one arbitrary SQL tool. Each tool has a clear role and none feel redundant or missing.

Completeness4/5

The set covers schema creation, listing, and inspection, and execute_sql provides full database access as a fallback. Row-level CRUD and operations like ALTER/DROP are not exposed as first-class tools, but they can be handled through execute_sql, leaving only minor gaps.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    A blazing fast MCP server that enables AI agents to interact with multiple PostgreSQL databases, providing functionality to list tables, inspect schemas, execute queries, and run transactions.
    4
    152 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A PostgreSQL MCP server with AST-based security for safe database operations. Enables AI assistants to query and manage PostgreSQL databases securely.
    MIT