postgresql-mcp
Provides tools to directly interact with PostgreSQL databases, including creating tables, listing tables, describing tables, and executing arbitrary 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 List all tables in the 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.
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-mcpSetup & 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-webOr, if running without global installation:
uvx --from . postgresql-mcp-webOpen 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 toolscreate_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" }
Inputs: columns (required), table_name (required). Returns: result
describe_tableA
Describe table structure (columns, types, nullability, default).
Inputs: table_name (required). Returns: result
execute_sqlB
Execute any SQL query. WARNING: Full database access.
Inputs: query (required).
list_tablesA
List all tables in the public schema.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
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.
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.
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.
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.
Related MCP Connectors
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Xata MCP server lets AI agents interact with your Xata projects, and Postgres database branches.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Related MCP Servers
- AlicenseBqualityDmaintenanceA 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.4129 npmMIT
- AlicenseBqualityNot gradedmaintenanceA universal MCP server that enables AI agents to securely manage PostgreSQL databases, make API requests, and execute SSH commands with features for database analysis, schema editing, and data operations.31-
- AlicenseNot gradedqualityDmaintenanceA production-ready MCP server that connects AI assistants to any PostgreSQL database with 25 tools and role-based access control.12 npmMIT
- AlicenseNot gradedqualityDmaintenanceA PostgreSQL MCP server with AST-based security for safe database operations. Enables AI assistants to query and manage PostgreSQL databases securely.MIT