PostgreSQL MCP Server
Provides tools for inspecting and querying a PostgreSQL database, including listing tables, retrieving schema, and executing read-only SQL queries.
Click on "Deploy 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., "@PostgreSQL MCP Server show me the users table schema"
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
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 thepublicschema.get_schema: Get the schema (columns, types, nullability) of a specific table.run_query: Run a read-only SQL query (onlySELECT/WITHallowed) with a maximum limit of 100 rows to avoid large responses.
Related MCP server: PostgreSQL MCP Server
Prerequisites
Python 3.13+
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.pyUsage 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 toolsget_schemaA
Get the schema (columns, types) of a specific table
Inputs: table_name (required).
list_tablesB
List all tables in the current database schema
Inputs: no named parameters.
run_queryA
Run a read-only SQL query against the database. ONLY SELECT queries are allowed for safety.
Inputs: query (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: listing tables, retrieving table schema, and running arbitrary SQL queries. No overlap or ambiguity exists.
All tool names follow a consistent verb_noun pattern (list_tables, get_schema, run_query), making them predictable and easy to understand.
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.
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
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables 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
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.1ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.2ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query a PostgreSQL database through a small set of controlled, read-only tools for schema inspection, row lookup, and aggregate statistics.1MIT