MCP server for accessing Nuuly PostgreSQL database resources
Project description
Nuuly Postgres MCP Server
This MCP server provides AI code editors with access to PostgreSQL databases through the Model Context Protocol (MCP). It allows AI assistants to understand database schemas, tables, and to run queries against non-prod PostgreSQL databases. This implementation acts as a client that forwards requests to a remote PostgreSQL MCP server running on Google Cloud Run.
Features
- List available PostgreSQL databases and their aliases
- Get detailed schema information for all tables in a database
- Run SQL queries against PostgreSQL databases
Prerequisites
- Python 3.8+
Installation
Step 1: Install Python (Mac Users)
Option A: Using Homebrew (Recommended)
- Open Terminal
- Check if Homebrew is installed by typing:
brew --version - If Homebrew is not installed, install it by copying and pasting this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Once Homebrew is installed, install Python:
brew install python
Option B: Download Python directly
- Go to python.org
- Download Python 3.8 or newer
- Run the installer and follow the prompts
Step 2: Install the Postgres MCP Server
- Open Terminal
- Install the server by running:
pip install nuuly-postgres-mcp-server
- Wait for the installation to complete
Step 3: Find the Installation Path
You'll need to find where the server was installed to configure Claude:
- In Terminal, run:
which nuuly-postgres-mcp - This will show something like:
/Users/yourname/Library/Python/3.12/bin/nuuly-postgres-mcp - Copy this path - you'll need it for the next step
Step 4: Configure Claude Desktop
- Open Claude Desktop application
- Find the "MCP Servers" section
- Click "Edit Config" or open the configuration file
- Add the following configuration, replacing the path with your actual path from Step 3:
{
"nuuly-postgres-mcp": {
"command": "/Users/yourname/Library/Python/3.12/bin/nuuly-postgres-mcp",
"env": {
"PYTHONUNBUFFERED": "1",
"POSTGRES_MCP_SERVER_URL": "https://postgres-mcp-toolbox-186512416539.us-east4.run.app",
"DB_PROXY_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
Environment URLs:
- Dev (rental-dev):
https://postgres-mcp-toolbox-186512416539.us-east4.run.app - Staging (rental-staging):
https://postgres-mcp-toolbox-526194183507.us-east4.run.app
Use POSTGRES_MCP_SERVER_URL to switch between dev and staging.
Step 5: Restart Claude
- Restart Claude Desktop
- The PostgreSQL tools should now be available
Available Tools
The server provides the following tools, which are forwarded to the remote PostgreSQL MCP server:
1. list_databases
Lists all databases and their aliases accessible via the Cloud Run DB Proxy.
list_databases()
Example response:
{
"databases": [
{
"name": "orders",
"aliases": ["orders_db", "order_system"],
"instance": "rental-dev:us-east4:orders-db"
},
{
"name": "products",
"aliases": ["product_db"],
"instance": "rental-dev:us-east4:product-db"
}
]
}
2. get_schema
Gets the schema of all tables in the specified database.
get_schema(database="orders")
Example response:
{
"tables": [
{
"name": "orders",
"columns": [
{
"name": "id",
"type": "integer",
"nullable": false,
"primary_key": true
},
{
"name": "customer_id",
"type": "integer",
"nullable": false,
"foreign_key": {
"table": "customers",
"column": "id"
}
},
{
"name": "created_at",
"type": "timestamp",
"nullable": false
}
]
}
],
"success": true
}
3. run_query
Runs a SQL query against the database and returns results.
run_query(database="orders", sql="SELECT * FROM orders LIMIT 10")
Example response:
{
"columns": ["id", "customer_id", "created_at"],
"rows": [
[1001, 5001, "2023-01-15T10:30:00Z"],
[1002, 5002, "2023-01-15T11:45:00Z"]
],
"count": 2,
"success": true
}
Backend Deployment
The Postgres MCP client forwards requests to a Cloud Run DB Proxy. The backend is deployed via Terraform in infra_tools/postgres_mcp_server/terraform/:
- Dev:
rental-dev,config/dev.yaml, Cloud SQL private IPs - Staging:
rental-staging,config/staging.yaml, Cloud SQL + AlloyDB private IPs - Region:
us-east4 - VPC Connector:
rental-vpc-connector
See infra_tools/postgres_mcp_server/README.md for build and deploy instructions.
Troubleshooting
Connection Issues with Claude Desktop
If you experience connection issues with Claude Desktop, ensure that:
- The server is running with the correct URL for the Cloud Run DB Proxy
- The API key is correctly set in your configuration
- The server is properly handling heartbeat and shutdown messages
- The JSON-RPC initialization response includes
keepAlive: trueandsupportsHeartbeats: true
Example curl commands to test the API:
# Dev
curl -X GET "https://postgres-mcp-toolbox-186512416539.us-east4.run.app/databases" -H 'x-api-key: YOUR_API_KEY_HERE'
# Staging
curl -X GET "https://postgres-mcp-toolbox-526194183507.us-east4.run.app/databases" -H 'x-api-key: YOUR_API_KEY_HERE'
Common Issues
- Missing API Key: Ensure the
DB_PROXY_API_KEYenvironment variable is set - Permission Errors: Verify that your API key has the necessary permissions
- Timeout Errors: Check network latency or increase the timeout settings in the code
- Heartbeat Issues: Ensure the MCP server properly implements heartbeat handlers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nuuly_postgres_mcp_server-1.0.2.tar.gz.
File metadata
- Download URL: nuuly_postgres_mcp_server-1.0.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ebd0a96fa986dd8c0781d42308a778f2b1f5437aa148b70213c1371ed0f8dd
|
|
| MD5 |
f93a38f46de7c9966d9cd226d76ffd67
|
|
| BLAKE2b-256 |
6f6a974128321f77859b9e9c3043ab253584413148147736fb5ba2d5a0d45658
|
File details
Details for the file nuuly_postgres_mcp_server-1.0.2-py3-none-any.whl.
File metadata
- Download URL: nuuly_postgres_mcp_server-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbcd87495947b5764cd0f96fda82c085b6c52d25c9ffc40ab42fcd53c7da9431
|
|
| MD5 |
ebf67753bc2dd532972d28d3ba684906
|
|
| BLAKE2b-256 |
6838c4b1912b36c8738e7416927860778da187ad8ad4e9c93d36985d3f5f108e
|