Skip to main content
Glama
KannaKim

PostgreSQL MCP Server

by KannaKim

PostgreSQL MCP Server

A generic Model Context Protocol (MCP) server for PostgreSQL, allowing AI agents to inspect and query PostgreSQL databases safely.

Features

  • list_tables: List all tables in the public schema.

  • get_schema: Get the schema (columns, types, nullability) of a specific table.

  • run_query: Run a read-only SQL query (only SELECT/WITH allowed) with a maximum limit of 100 rows to avoid large responses.

Related MCP server: PostgreSQL MCP Server

Prerequisites

  • Python 3.13+

  • uv

  • PostgreSQL database

Installation

You can run this directly using uvx or uv run if you clone the repository.

Usage

This server requires the DATABASE_URL environment variable to be set.

Example connection string: postgres://user:password@localhost:5432/mydatabase

Running directly

DATABASE_URL="postgresql://postgres:poggerpogger@localhost:5432/boxboxWeb" uv run main.py

Usage with Claude Desktop / MCP Clients

Add the following to your MCP client configuration (e.g., Claude Desktop's claude_desktop_config.json):

{
  "mcpServers": {
    "postgres": {
      "command": "uv",
      "args": [
        "run",
        "/path/to/2025postgresqlmcp/main.py"
      ],
      "env": {
        "DATABASE_URL": "postgres://user:password@localhost:5432/mydatabase"
      }
    }
  }
}

Available Tools

3 tools
get_schemaA

Get the schema (columns, types) of a specific table

ParametersJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table

TDQS

A3.7/5.0
Behavior3/5

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

With no annotations, the description must convey behavioral traits. It describes a read operation ('Get') but lacks details such as whether any side effects occur, authentication requirements, or rate limits. The description is adequate for a simple metadata retrieval but could be more explicit.

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

Conciseness4/5

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

The description is a single, front-loaded sentence that directly states the purpose. It is concise and efficient, though it could briefly mention the output to improve completeness without adding much length.

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?

Given the low complexity (one parameter, no output schema), the description covers the core functionality. It does not explain the return format, but the tool name and description imply a schema structure. For simple tools, this level of detail is sufficient.

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 provides 100% coverage with a clear description for table_name ('Name of the table'). The tool description does not add additional meaning beyond what the schema already conveys, so baseline score applies.

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 clearly states the action ('Get') and the resource ('schema of a specific table'), making the purpose instantly understandable. It distinguishes itself from sibling tools: list_tables lists tables, run_query executes queries.

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 description implies usage when needing column names and types for a known table, but it does not provide explicit guidance on when to use this tool versus alternatives (e.g., run_query for more complex queries).

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

list_tablesB

List all tables in the current database schema

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

B3.3/5.0
Behavior2/5

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

With no annotations, the description carries full burden. It states the basic action but fails to disclose important behaviors such as whether system tables are included, required permissions, or response format. The minimal description limits transparency.

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, clear sentence that conveys the core action efficiently. It is front-loaded with the verb and resource, containing no unnecessary words.

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?

Given the tool's simplicity (no parameters, no output schema), the description is adequate to understand what it does. However, it lacks information about the output format or any constraints, making it partially complete for effective agent use.

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?

There are no parameters, and schema description coverage is 100%. The description adds minimal context ('current database schema'), which provides scope but does not significantly enhance parameter meaning. Baseline score of 3 is appropriate.

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 clearly states the action (List) and the resource (tables) with a specific scope ('current database schema'). It differentiates well from siblings: get_schema likely retrieves schema structure, run_query executes queries, while list_tables is focused solely on listing table names.

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 provided on when to use this tool versus alternatives like get_schema or run_query. The description does not mention context, prerequisites, or exclusions, leaving the agent to infer usage.

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

run_queryA

Run a read-only SQL query against the database. ONLY SELECT queries are allowed for safety.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesThe read-only SQL query to execute

TDQS

A3.9/5.0
Behavior3/5

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

With no annotations, the description discloses the key read-only behavior. However, it lacks details on error handling, result format, or performance impacts, making it adequate but not rich.

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 two concise sentences, front-loaded with the core action, with no redundant information.

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?

Given the simplicity of the tool (single parameter, no output schema), the description is minimally complete. It could mention that it returns query results, but the lack is not critical.

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?

Schema coverage is 100% and the description reinforces the parameter's safety (read-only, SELECT-only). No additional meaning beyond the schema is provided, so baseline score applies.

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 clearly states the tool runs a read-only SQL query, specifying 'SELECT queries only' which distinguishes it from sibling tools like get_schema and list_tables.

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

Usage Guidelines4/5

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

It explicitly restricts usage to SELECT queries for safety, providing a clear when-to-use guideline. It could mention alternatives for non-SELECT queries, but the constraint is sufficient.

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

TDQS

A3.8/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: listing tables, retrieving table schema, and running arbitrary SQL queries. No overlap or ambiguity exists.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (list_tables, get_schema, run_query), making them predictable and easy to understand.

Tool Count4/5

Three tools is on the lower end of the ideal range, but they cover the essential operations for a read-only database server. Slightly more tools (e.g., listing views) would improve scope without bloat.

Completeness4/5

The tool set provides core capabilities for exploring and querying a database, but lacks support for listing views, functions, or other database objects. This is acceptable for a focused MCP server.

Maintenance

ActivityInactive
ResponsivenessSyncing

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

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.
    2
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to query and explore PostgreSQL databases with tools for executing SQL queries, listing tables, and describing table structures.
    MIT

Latest Blog Posts

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/KannaKim/PostgresqlMCPServer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server