PostgreSQL Connector

The PostgreSQL connector lets the AI query and inspect PostgreSQL databases. It enables workflows like data analysis, report generation, schema exploration, and natural language to SQL conversion.

Setup

Property Value
Category Database
Command npx @modelcontextprotocol/server-postgres
Required Env Vars POSTGRES_CONNECTION_STRING

Connection String Format

postgresql://username:password@hostname:5432/database_name

For SSL connections (recommended for remote databases):

postgresql://username:password@hostname:5432/database_name?sslmode=require

Security: Use a read-only database user for the PostgreSQL connector. The AI can execute arbitrary SQL queries, so restricting to read-only access prevents accidental data modifications.

Creating a Read-Only User

-- Create a read-only role
CREATE ROLE workjet_reader WITH LOGIN PASSWORD 'secure_password';

-- Grant read access to all tables in a schema
GRANT USAGE ON SCHEMA public TO workjet_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO workjet_reader;

-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT SELECT ON TABLES TO workjet_reader;

Available Tools

Tool Description
query Execute a SQL query and return results
describe_table Show column names, types, and constraints for a table
list_tables List all tables in the database
list_schemas List all schemas in the database

Example Use Cases

  • Data analysis: "What were the top 10 products by revenue last month?"
  • Automated reporting: Build an engine that generates weekly sales summaries from database data
  • Schema exploration: "Describe the users table and its relationships"
  • SQL generation: Use the SQL Query Builder skill with the PostgreSQL connector for natural language queries

Next Steps