rmcp-postgres
A PostgreSQL MCP (Model Context Protocol) server built with rmcp, the Rust MCP SDK.
Provides comprehensive PostgreSQL database access through MCP tools for querying, inserting, updating, deleting, and inspecting database schemas.
Features
- Full CRUD Operations: Query, insert, update, and delete data
- Schema Inspection: List tables, describe schemas, check existence
- Relationship Discovery: Explore foreign key relationships
- Safety Limits: Built-in protections for bulk operations
- Configurable: Flexible database connection configuration
- Library + Binary: Use as a standalone server or integrate into your own Rust projects
Installation
From crates.io (coming soon)
From source
The binary will be at target/release/rmcp-postgres.
Usage
As a Standalone Server
Set your PostgreSQL connection string and run:
# Using environment variable
# Using command line argument
As a Library
Add to your Cargo.toml:
[]
= "0.1"
= { = "0.12", = ["server"] }
= { = "1", = ["full"] }
Use in your code:
use ServiceExt;
use PostgresServer;
async
Claude Desktop Configuration
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
Or if installed from source:
Available Tools
Data Operations
- query_data - Execute SELECT queries and return JSON results
- insert_data - Insert rows into tables
- update_data - Update rows with WHERE conditions (safety limit: 1000 rows)
- delete_data - Delete rows with WHERE conditions (safety limit: 1000 rows)
- execute_raw_query - Execute any SQL query (use with caution)
Schema Inspection
- list_tables - List all tables in the database
- get_schema - Get column information for tables
- describe_table - Get detailed table info including indexes and constraints
- table_exists - Check if a table exists
- column_exists - Check if a column exists in a table
Utilities
- count_rows - Count rows in a table with optional WHERE conditions
- get_table_sample - Get sample rows from a table (default: 10, max: 100)
- get_relationships - Get foreign key relationships between tables
- get_connection_status - Test connection and get database version info
Connection String Format
PostgreSQL connection strings support multiple formats:
# Basic
"host=localhost user=postgres dbname=mydb"
# With password
"host=localhost user=postgres dbname=mydb password=secret"
# With port
"host=localhost port=5433 user=postgres dbname=mydb"
# Full URL format
See the tokio-postgres documentation for all connection options.
Examples
Query data
Insert data
Update data
Get schema for a table
Safety Features
- Update and delete operations have default limits (1000 rows)
- WHERE conditions required for updates and deletes
- Raw query execution requires explicit tool call
- Connection string passwords are sanitized in logs
Development
# Build
# Run tests
# Run with debug logging
RUST_LOG=rmcp_postgres=debug,rmcp=debug
Contributing
Contributions welcome! Please feel free to submit issues or pull requests.
License
MIT
Related Projects
- rmcp - Rust MCP SDK
- Model Context Protocol - The MCP specification