One of the principal and most powerful components of the pgEdge Agentic AI Toolkit is the pgEdge Postgres MCP Server. In just over a year MCP (Model Context Protocol), initially developed by Anthropic, has become the standard way to connect LLMs to external data sources and tools. Some people describe it as being like a USB for LLMs. 

The pgEdge Postgres MCP server makes it extremely easy to connect Claude Code, Claude Desktop, Cursor and other AI development tools directly to any Postgres database – not just pgEdge distributions, but standard community Postgres, Amazon RDS, and pretty much any other relatively standard version of Postgres (so long as it is v14 or newer).

Let’s walk through how to set up the pgEdge Postgres MCP Server, what makes it different, and how to use it with Claude Desktop and AI code generators like Claude Code and Cursor. Our discussion is somewhat Claude-centric, but the pgEdge MCP Server also works with OpenAI GPT-5 and local models such as Ollama.

What Makes Our MCP Server for Postgres Different

Perhaps your first reaction to seeing our announcement was “wait, what? Another Postgres MCP Server”.  But it turns out until today there was no dedicated Postgres vendor offering a fully featured and fully supported MCP Server that works with all your existing Postgres databases.  Most of the available Postgres MCP Servers are tied to the vendor's own products, and in particular their cloud database offering.

The pgEdge MCP Server provides flexible deployment options: on-premises, in self managed cloud accounts or soon in our pgEdge Cloud managed cloud service. Additionally, when used with pgEdge Distributed Postgres, applications making use of the pgEdge MCP Server can meet enterprise requirements for high availability, multi-region failover and data sovereignty.  

Most Postgres MCP servers out there give you basic read-only access—enough to query schemas and run SELECT statements. We built ours to be production-grade from day one:

Full schema introspection - The MCP server doesn't just list your tables. It pulls detailed information about your database structure: primary keys, foreign keys, indexes, column types, constraints, the works. This lets Claude actually reason about your data model instead of just blindly querying it.

Performance metrics - Want to know which queries are slow? Which indexes aren't being used? The server exposes pg_stat_statements and other data so the LLM can help you optimize performance, not just write queries.

Multi-database support - Connect to multiple Postgres instances from the same MCP server. Useful when you're working across dev, staging, and production, or when you need to query both your application database and your analytics warehouse. For Claude Code and Desktop you do this by configuring multiple MCP server instances with different names e.g. devdb, stagingdb, proddb. For your own MCP clients you can refer to the Natural Language Agent client code found in our MCP server repo.)

Security Built-in - Many MCP Servers are stdio only, and do not support HTTP.   In addition to full HTTP support we’ve added TLS support, user and token auth, and read-only enforcement (at initial beta the MCP server is readonly, but this will be switchable in a forthcoming release).

Installation and Setup

The MCP server is part of the pgEdge Agentic AI Toolkit, which you can download directly from our site. It works with Postgres 16, 17, and 18. 

For a quick start first go to https://github.com/pgEdge/pgedge-postgres-mcp/releases and download the correct MCP server download for your OS and architecture. 

Then follow the instructions below.

# Check that the MCP server binary is ready to use

./bin/pgedge-postgres-mcp --version

Connecting to Claude Desktop

Claude Desktop is probably the easiest way to get started with MCP servers. Here's the full setup:

Step 1: Locate Your Config File

The configuration file location depends on your OS:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%/Claude/claude_desktop_config.json

  • Linux: ~/.config/Claude/claude_desktop_config.json

If this file doesn't exist, create it.

Step 2: Add the pgEdge MCP Server

Edit claude_desktop_config.json and add this configuration:

{
  "mcpServers": {
    "production-db": {
      "command": "/path/to/pgedge-mcp-server",
      "env": {
        "PGHOST": "prod.db.company.com",
        "PGDATABASE": "prod_db",
        "PGUSER": "readonly_user",
        "PGPASSWORD": "secure_password",
        "PGSSLMODE": "require"
      }
    },
    "analytics-db": {
      "command": "/path/to/pgedge-mcp-server",
      "env": {
        "PGHOST": "analytics.db.company.com",
        "PGDATABASE": "warehouse",
        "PGUSER": "analyst_user",
        "PGPASSWORD": "another_password"
      }
    }
  }
}

Step 3: Restart Claude Desktop

After saving your config, fully quit and restart Claude Desktop. When you open a new conversation, you should see a small hammer icon () in the interface—that's your MCP server connection.

Step 4: Test It Out

Open a new conversation and try:

What tables are in my database?

Claude will use the MCP server to introspect your schema and list all tables with descriptions.

Try something more advanced:

Show me the schema for the users table, including all indexes and foreign keys.

Or get performance insights:

Which queries have been running the slowest in the last hour?

Connecting to Claude Code

Claude Code is where things get really interesting — you can have Claude write code that directly queries your database, with full context about your schema.

Step 1: Create Project Config

In your project root, create a .mcp.jsonfile:

{
  "mcpServers": {
    "pgedge-postgres": {
      "command": "/path/to/pgedge-ai-toolkit/bin/pgedge-mcp-server",
      "env": {
        "PGHOST": "localhost",
        "PGPORT": "5432",
        "PGDATABASE": "myapp_db",
        "PGUSER": "app_user",
        "PGPASSWORD": "app_password"
      }
    }
  }
}

Step 2: Launch Claude Code

cd /path/to/your/project claude-code

Claude Code will automatically detect the .mcp.json file and establish the MCP server connection.

Step 3: Start Building

Now you can give Claude commands like:

Write a Python script that queries the top 10 users by sign-up date and exports them to CSV.

Claude will:

  • Inspect your database schema via the MCP server

  • Understand the structure of your users table

  • Write properly parameterized SQL

  • Generate the complete Python script with error handling

Or try:

I need a function that efficiently checks if a user has a certain permission. 

Look at my permissions model and write the most performant query.

Claude will examine your foreign key relationships, check which indexes exist, and write optimized SQL based on your actual schema.

Using with Cursor

Cursor has excellent MCP support. Here's how to connect:

Step 1: Open Cursor Settings

  • Open Cursor

  • Go to Settings → Cursor Settings → Tools & MCP

  • Under Installed MCP Servers select Add Custom MCP

Step 2: Add Server Configuration

Using the Cursor edit window, edit .cursor/mcp.json:

{
  "mcpServers": {
    "pgedge-postgres": {
      "command": "/path/to/pgedge-ai-toolkit/bin/pgedge-mcp-server",
      "env": {
        "PGHOST": "localhost",
        "PGPORT": "5432",
        "PGDATABASE": "your_database",
        "PGUSER": "your_username",
        "PGPASSWORD": "your_password"
      }
    }
  }
}

Step 3: Verify Connection

After saving, you should see a green "active" status indicator next to the pgedge-postgres server in the MCP section of Cursor settings.

Step 4: Use in Cursor Chat

Open the Cursor chat panel and reference your database:

@pgedge-postgres Show me all tables with more than 1 million rows

Or while writing code:

I'm writing a migration script. Show me the current schema for the orders table so I know what columns already exist.

Advanced Configuration Options

Multiple Database Connections

You can configure multiple MCP servers in the same config file to work with different databases:

{
  "mcpServers": {
    "production-db": {
      "command": "/path/to/pgedge-mcp-server",
      "env": {
        "PGHOST": "prod.db.company.com",
        "PGDATABASE": "prod_db",
        "PGUSER": "readonly_user",
        "PGPASSWORD": "secure_password",
        "PGSSLMODE": "require"
      }
    },
    "analytics-db": {
      "command": "/path/to/pgedge-mcp-server",
      "env": {
        "PGHOST": "analytics.db.company.com",
        "PGDATABASE": "warehouse",
        "PGUSER": "analyst_user",
        "PGPASSWORD": "another_password"
      }
    }
  }
}

Now Claude can query both databases and even help you write queries that join data across them.

Now Claude can query both databases and even help you write queries that join data across them.

Read-Only Mode

[The initial beta01 version only supports readonly mode.  This is applicable for later versions.]

For production databases, you probably want read-only access. Grant your database user only SELECT privileges:

CREATE USER claude_readonly WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE production_db TO claude_readonly;
GRANT USAGE ON SCHEMA public TO claude_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO claude_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public 
  GRANT SELECT ON TABLES TO claude_readonly;

Environment Variables and Security 

Rather than putting the database password directly in JSON files, we can use a .pgpass file for password management

% cat > ~/.pgpass

localhost:5432:mydb:myuser:mypass ^D

Then configure without PGPASSWORD in the config:

{
  "mcpServers": {
    "pgedge": {
      "command": "/absolute/path/to/bin/pgedge-postgres-mcp",
      "env": {
        "PGHOST": "localhost",
        "PGPORT": "5432",
        "PGDATABASE": "mydb",
        "PGUSER": "myuser"
      }
    }
  }
}

What Claude Can Do With Your Database

Once connected, here are some real workflows you can enable:

Schema exploration and documentation

Generate markdown documentation for all tables in the public schema, including column descriptions and relationships

Query optimization

This query is running slow: [paste query]. Analyze the execution plan and suggest indexes or rewrites.

Migration assistance

I need to add a new column to track user subscription tiers. Look at my users table and write a safe migration script.

Data analysis

Find all users who signed up in the last month but haven't completed onboarding

Debugging

I'm getting a foreign key violation on the orders table. Show me all foreign keys and help me understand what's wrong.

Under the Hood: How It Works

The pgEdge MCP server implements the full Model Context Protocol specification. When the LLM wants to interact with your database, here's what happens:

  • Discovery: The LLM queries the MCP server for available tools and resources

  • Schema introspection: The MCP server queries Postgres system catalogs (pg_class, pg_attribute, pg_constraint, etc.) to build a complete picture of your schema

  • Tool execution: When the LLM needs to run a query or get performance metrics, it calls the appropriate MCP tool

  • Response streaming: Results are streamed back to the LLM in a structured format

  • Context building: the LLM uses this information to inform its responses and code generation

The server maintains a connection pool to your database, so repeated queries don't create new connections each time.

Troubleshooting

"Connection refused" errors

Check that your database is accessible from wherever you're running Claude Desktop/Code. Try connecting with psql first:

psql "postgresql://username:password@host:5432/database"

MCP server not showing up in Claude Desktop

  • Verify the JSON syntax in your config file (use a JSON validator)

  • Check that the path to the MCP server binary is correct and executable

  • Look at Claude Desktop logs: ~/Library/Logs/Claude/ (macOS) or %APPDATA%/Claude/logs/ (Windows)

"Permission denied" on database queries

Make sure your database user has appropriate permissions. For read-only access, you need at minimum:

GRANT CONNECT ON DATABASE your_db TO your_user;
GRANT USAGE ON SCHEMA public TO your_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO your_user;

What's Next

We're actively developing additional features for the MCP server:

  • Support for write operations with appropriate safeguards, including a readonly by default switch

  • Improved optimization to save on token usage in database queries

  • Better optimization of schema discovery

  • Additional work on database performance monitoring

  • Further work on security, authorization and governance (dependent on feedback from users on requirements for real-world enterprise use cases)

The full pgEdge Agentic AI Toolkit (MCP server, vectorizer, RAG server, docloader) is available now in beta. Everything is open source under the Postgres license, and we're eager for feedback from the community.

If you're building AI applications on Postgres and need your agents to have direct, intelligent access to your data, give the pgEdge Postgres MCP server a try. It's built to work with your existing infrastructure, whether you're on community Postgres or running our distributed platform.

Download the toolkit – we can’t wait to see what you build with it – and send us your feedback!

— Phillip Merrick
Chairman & Chief Product Officer, pgEdge


Got questions or feedback about the pgEdge Postgres MCP server? Hit us up on the pgEdge Discord or open an issue on GitHub. We're here to help.