Unrestricted PostgreSQL MCP Server
Provides full read-write access to PostgreSQL databases with advanced transaction management, recovery tools, and schema exploration capabilities, enabling LLMs to safely query, modify, and manage database content.
README
Unrestricted PostgreSQL MCP Server
Fork of mcp-postgres-full-access by Syahiid Nur Kamil - Enhanced with modern tooling, transaction recovery tools, and improved developer experience.
A powerful Model Context Protocol (MCP) server that provides full read-write access to PostgreSQL databases. Unlike read-only MCP servers, this implementation enables Large Language Models to safely query, modify, and manage database content with comprehensive transaction management and recovery capabilities.
✨ Key Features
🔐 Safe Full Database Access
- Read Operations: Execute SELECT queries with automatic read-only transaction protection
- Write Operations: Safely perform INSERT, UPDATE, DELETE with explicit transaction management
- Schema Management: Create, alter, and drop database objects with DDL operations
- Maintenance Commands: Execute VACUUM, ANALYZE, and CREATE DATABASE operations
🛡️ Advanced Transaction Management
- Explicit Commit/Rollback: Two-step process requiring user confirmation for all changes
- Transaction Recovery: Tools to recover from aborted transaction states
- Timeout Protection: Automatic rollback of abandoned transactions
- Session Reset: Complete session reset capabilities for stuck connections
- Connection Status: Real-time monitoring of database connection state
📊 Rich Schema Information
- Comprehensive Metadata: Detailed column information, data types, constraints
- Relationship Mapping: Primary keys, foreign keys, and index information
- Performance Insights: Row count estimates and table statistics
- Documentation Support: Table and column descriptions when available
🔧 Developer Experience
- Modern Build System: Powered by Vite for fast development and building
- TypeScript Support: Full type safety and IntelliSense support
- Hot Reload: Instant development server with
vite-node - Comprehensive Tooling: 10+ specialized tools for database operations
🚀 Quick Start
Prerequisites
- Node.js 18.0.0 or higher
- PostgreSQL 12.0 or higher
- Claude Desktop (for MCP integration)
Installation
# Install globally
npm install -g unrestricted-postgres-mcp
# Or use with npx (recommended)
npx unrestricted-postgres-mcp postgresql://user:password@localhost:5432/database
Claude Desktop Configuration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"postgres-unrestricted": {
"command": "npx",
"args": [
"-y",
"unrestricted-postgres-mcp",
"postgresql://username:password@localhost:5432/database"
],
"env": {
"TRANSACTION_TIMEOUT_MS": "60000",
"MAX_CONCURRENT_TRANSACTIONS": "5",
"PG_STATEMENT_TIMEOUT_MS": "30000"
}
}
}
}
🛠️ Available Tools
Query & Analysis Tools
| Tool | Purpose | Parameters |
|---|---|---|
execute_query |
Execute read-only SELECT queries | sql (string) |
get_database_schema |
Get comprehensive database schema overview | None |
search_text |
Search text across tables using full-text search | search_term (string), tables (array, optional), columns (array, optional), limit (number, optional) |
list_tables |
List all tables in a schema | schema_name (string, optional) |
describe_table |
Get detailed table schema information | table_name (string), schema_name (string, optional) |
Data Modification Tools
| Tool | Purpose | Parameters |
|---|---|---|
execute_dml_ddl_dcl_tcl |
Execute data modification operations (auto-committed) | sql (string) |
execute_maintenance |
Run maintenance commands (VACUUM, ANALYZE) | sql (string) |
execute_rollback |
Rollback a pending transaction | transaction_id (string) |
Transaction Management & Recovery
| Tool | Purpose | Parameters |
|---|---|---|
list_transactions |
List all active transactions | None |
force_rollback |
Force rollback aborted transactions | None |
reset_session |
Reset database session completely | None |
🔄 Workflow Examples
Typical Usage Pattern
- Query data to understand current state
- Execute modifications (automatically committed)
- Query again to verify changes
Recovery from Stuck Transactions
- Diagnose: Use
list_transactionsto check state - List: Use
list_transactionsto see active transactions - Recover: Use
force_rollbackto clear aborted state - Reset: If needed, use
reset_sessionfor complete reset
Schema Exploration
- Discover: Use
list_tablesto see available tables - Examine: Use
describe_tablefor detailed schema information - Query: Use
execute_queryto explore data patterns
⚙️ Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
TRANSACTION_TIMEOUT_MS |
15000 |
Transaction timeout in milliseconds |
MAX_CONCURRENT_TRANSACTIONS |
10 |
Maximum concurrent transactions |
PG_STATEMENT_TIMEOUT_MS |
30000 |
SQL statement execution timeout |
PG_MAX_CONNECTIONS |
20 |
Maximum PostgreSQL connections |
ENABLE_TRANSACTION_MONITOR |
true |
Enable transaction monitoring |
MONITOR_INTERVAL_MS |
5000 |
Transaction monitor check interval |
Security Best Practices
-
Create Dedicated Database User:
CREATE USER mcp_user WITH PASSWORD 'secure_password'; GRANT SELECT, INSERT, UPDATE, DELETE ON specific_tables TO mcp_user; -
Use "Allow Once" for All Operations:
- Never select "Always allow" for database modifications
- Review all SQL operations before approval
-
Test with Non-Production Data:
- Use a development database for initial testing
- Implement regular backups before extensive use
🏗️ Development
Prerequisites
- Node.js 18+
- pnpm (recommended) or npm
- PostgreSQL database
Setup
# Clone the repository
git clone https://github.com/your-username/unrestricted-postgres-mcp.git
cd unrestricted-postgres-mcp
# Install dependencies
pnpm install
# Create environment file
cp .env.example .env
# Edit .env with your database connection details
# Start development server
pnpm run dev
# Build for production
pnpm run build
Available Scripts
| Script | Purpose |
|---|---|
pnpm run dev |
Start development server with hot reload |
pnpm run build |
Build for production |
pnpm run start |
Run production build |
pnpm run type-check |
Run TypeScript type checking |
Project Structure
src/
├── index.ts # Main server entry point
├── lib/
│ ├── config.ts # Configuration management
│ ├── tool-handlers.ts # Tool implementation functions
│ ├── transaction-manager.ts # Transaction lifecycle management
│ ├── types.ts # TypeScript type definitions
│ └── utils.ts # Utility functions
└── types.ts # Additional type definitions
🔍 Troubleshooting
Common Issues
"Current transaction is aborted" Error:
- Use
list_transactionsto diagnose - Use
force_rollbackto clear aborted state - If still stuck, use
reset_session
Connection Timeouts:
- Check
PG_STATEMENT_TIMEOUT_MSsetting - Increase
TRANSACTION_TIMEOUT_MSif needed - Verify database connection limits
Permission Errors:
- Verify database user permissions
- Check table-specific access rights
- Ensure user has necessary schema access
📊 Comparison with Official MCP Servers
| Feature | This Server | Official PostgreSQL MCP |
|---|---|---|
| Read Access | ✅ Enhanced | ✅ Basic |
| Write Access | ✅ Full Support | ❌ Not Available |
| Transaction Management | ✅ Advanced | ❌ Not Available |
| Schema Details | ✅ Comprehensive | ✅ Basic |
| Recovery Tools | ✅ Multiple Options | ❌ Not Available |
| Type Safety | ✅ Full TypeScript | ❌ Not Available |
| Modern Tooling | ✅ Vite + Hot Reload | ❌ Not Available |
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Quick Contribution Guide
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Run tests:
pnpm run type-check && pnpm run build - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
📄 License
This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details.
👥 Credits
- Original Creator: Syahiid Nur Kamil - mcp-postgres-full-access
- Current Maintainer: Jonas Lindberg - Enhanced version with modern tooling and recovery capabilities
🙏 Acknowledgments
- Model Context Protocol for the MCP specification
- Anthropic for Claude and MCP integration
- PostgreSQL for the excellent database system
- Vite for the modern build tooling
⚠️ Important: This server provides full database access. Always review operations before committing changes and use appropriate database user permissions for security.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。