unrestricted-postgres-mcp

startino/unrestricted-postgres-mcp

3.3

If you are the rightful owner of unrestricted-postgres-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A powerful Model Context Protocol server providing full read-write access to PostgreSQL databases, enabling LLMs to query and modify database content with transaction management and safety controls.

Tools
7
Resources
0
Prompts
0

Unrestricted PostgreSQL MCP Server

Model Context Protocol Node.js TypeScript Vite

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

ToolPurposeParameters
execute_queryExecute read-only SELECT queriessql (string)
list_tablesList all tables in a schemaschema_name (string, optional)
describe_tableGet detailed table schema informationtable_name (string), schema_name (string, optional)

Data Modification Tools

ToolPurposeParameters
execute_dml_ddl_dcl_tclExecute data modification operationssql (string)
execute_maintenanceRun maintenance commands (VACUUM, ANALYZE)sql (string)
execute_commitCommit a pending transactiontransaction_id (string)
execute_rollbackRollback a pending transactiontransaction_id (string)

Transaction Management & Recovery

ToolPurposeParameters
list_transactionsList all active transactionsNone
force_rollbackForce rollback aborted transactionsNone
reset_sessionReset database session completelyNone
get_connection_statusCheck connection and transaction stateNone

šŸ”„ Workflow Examples

Safe Data Modification Workflow

  1. Analyze: Use execute_query to understand current data
  2. Modify: Use execute_dml_ddl_dcl_tcl to make changes
  3. Review: Transaction is created but not committed
  4. Decide: Use execute_commit or execute_rollback based on review

Recovery from Stuck Transactions

  1. Diagnose: Use get_connection_status to check state
  2. List: Use list_transactions to see active transactions
  3. Recover: Use force_rollback to clear aborted state
  4. Reset: If needed, use reset_session for complete reset

Schema Exploration

  1. Discover: Use list_tables to see available tables
  2. Examine: Use describe_table for detailed schema information
  3. Query: Use execute_query to explore data patterns

āš™ļø Configuration

Environment Variables

VariableDefaultDescription
TRANSACTION_TIMEOUT_MS15000Transaction timeout in milliseconds
MAX_CONCURRENT_TRANSACTIONS10Maximum concurrent transactions
PG_STATEMENT_TIMEOUT_MS30000SQL statement execution timeout
PG_MAX_CONNECTIONS20Maximum PostgreSQL connections
ENABLE_TRANSACTION_MONITORtrueEnable transaction monitoring
MONITOR_INTERVAL_MS5000Transaction monitor check interval

Security Best Practices

  1. Create Dedicated Database User:

    CREATE USER mcp_user WITH PASSWORD 'secure_password';
    GRANT SELECT, INSERT, UPDATE, DELETE ON specific_tables TO mcp_user;
    
  2. Use "Allow Once" for All Operations:

    • Never select "Always allow" for database modifications
    • Review all SQL operations before approval
  3. 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

ScriptPurpose
pnpm run devStart development server with hot reload
pnpm run buildBuild for production
pnpm run startRun production build
pnpm run type-checkRun 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:

  1. Use get_connection_status to diagnose
  2. Use force_rollback to clear aborted state
  3. If still stuck, use reset_session

Connection Timeouts:

  1. Check PG_STATEMENT_TIMEOUT_MS setting
  2. Increase TRANSACTION_TIMEOUT_MS if needed
  3. Verify database connection limits

Permission Errors:

  1. Verify database user permissions
  2. Check table-specific access rights
  3. Ensure user has necessary schema access

šŸ“Š Comparison with Official MCP Servers

FeatureThis ServerOfficial 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 for details.

Quick Contribution Guide

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: pnpm run type-check && pnpm run build
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open a Pull Request

šŸ“„ License

This project is licensed under the Apache License Version 2.0 - see the file for details.

šŸ‘„ Credits

šŸ™ Acknowledgments


āš ļø Important: This server provides full database access. Always review operations before committing changes and use appropriate database user permissions for security.