Postgres Mcp
@freakynit
关于 Postgres Mcp
A lightweight MCP (Model Context Protocol) server built to query Postgres database. It provides comprehensive tools for database operations, table introspection, and query execution with smart permission handling.
基本信息
配置
使用下面的配置,将此服务器添加到你的 MCP 客户端。
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@freakynit/postgres-mcp@latest"
],
"env": {
"POSTGRES_HOST": "<POSTGRES HOST>",
"POSTGRES_USER": "<POSTGRES USER>",
"POSTGRES_PASSWORD": "<POSTGRES PASSWORD>",
"POSTGRES_DATABASE": "<POSTGRES DATABASE>"
}
}
}
}工具
4List all user tables in the database
Get comprehensive table information for one or more tables including columns, indexes, triggers, foreign keys, and constraints
Execute a SQL query. The system will automatically detect the required permission level and request user approval for write operations and dangerous DDL commands.
Switches the active database to the specified one. If an error occurs during the switch, the system automatically reverts back to the previous active database
概览
What is Postgres Mcp?
Postgres Mcp is a lightweight MCP (Model Context Protocol) server for querying a Postgres database using SQL or plain English commands. It provides tools for database operations, table introspection, and query execution with smart permission handling, intended for use with MCP-enabled AI assistants.
How to use Postgres Mcp?
Configure the server in an mcpServers JSON block with environment variables POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DATABASE (and optionally POSTGRES_PORT, POSTGRES_SSL, etc.). On macOS/Linux use npx -y @freakynit/postgres-mcp@latest as the command; on Windows use cmd /k npx -y @freakynit/postgres-mcp@latest.
Key features of Postgres Mcp
- Smart query permission handling (read-only, read-write, admin/DDL)
- Dry-run mode to validate queries without execution
- Comprehensive table introspection (columns, keys, indexes, triggers, constraints)
- Multiple database switching capability
- Robust error handling and rollback
Use cases of Postgres Mcp
- Ask an AI assistant to list all tables and describe their schemas
- Execute read-only queries (SELECT, EXPLAIN) with automatic approval
- Run INSERT/UPDATE/DELETE queries after user confirmation
- Switch between multiple Postgres databases in one session
- Safely test SQL statements using dry-run mode
FAQ from Postgres Mcp
How does permission handling work?
Read-only queries (SELECT, EXPLAIN, SHOW, VALUES) are automatically approved. Read-write queries (INSERT, UPDATE, DELETE, MERGE) require user confirmation. Admin/DDL queries (CREATE, ALTER, DROP, etc.) require elevated permission.
Can I run a query without actually executing it?
Yes, dry-run mode lets you validate queries without execution.
What environment variables are needed?
Minimum four variables: POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DATABASE. Optionally set POSTGRES_PORT, POSTGRES_SSL, POSTGRES_VERIFY, POSTGRES_SEND_RECEIVE_TIMEOUT, and POSTGRES_CONNECT_TIMEOUT.
What tools does Postgres Mcp provide?
Four tools: execute_raw_query, list_tables, describe_tables, and switch_database.
Can I switch databases during a session?
Yes, the switch_database tool allows changing the active database connection.
数据库 分类下的更多 MCP 服务器
Elasticsearch MCP Server
elasticDatabase Gateway
centralmindUniversal MCP-Server for your Databases optimized for LLMs and AI-Agents.

PostgreSQL
modelcontextprotocolModel Context Protocol Servers
MotherDuck's DuckDB MCP Server
motherduckdbLocal MCP server for DuckDB and MotherDuck
MongoDB MCP Server
mongodb-jsA Model Context Protocol server to connect to MongoDB databases and MongoDB Atlas Clusters.
评论