|Tutorial

Connect PostgreSQL to ChatGPT: MCP Setup Guide (2026)

Connect ChatGPT to PostgreSQL without pasting a database URL into the chat. Set up a remote MCP app with OAuth, read-only access, and scoped permissions.

Andrei
Founder of datamcp

The short answer

To connect PostgreSQL to ChatGPT, use a remote Model Context Protocol (MCP) app between ChatGPT and the database. ChatGPT does not open a PostgreSQL socket or need the database connection string pasted into the conversation.

The connection path is:

  1. ChatGPT authenticates to a remote MCP server.
  2. The MCP server exposes approved database tools.
  3. The server validates permissions and executes SQL through a PostgreSQL role.
  4. ChatGPT receives the permitted result and uses it in the conversation.

datamcp provides that hosted MCP layer for PostgreSQL. You add the database once, create a permission-scoped remote HTTPS MCP link, and connect that link to ChatGPT through OAuth 2.0 with PKCE.

The hosted PostgreSQL MCP server page explains the underlying database tools, credential handling, and per-link controls.

OpenAI's current documentation says ChatGPT Apps are supported on all plans. Developer mode can still be unavailable when an organization administrator disables it. For the client-wide setup flow and current terminology, read the ChatGPT MCP setup guide.

Requirements

Before starting, confirm that you have:

  • a ChatGPT account with Developer mode available
  • workspace approval when organization policy controls developer-mode apps
  • ChatGPT on the web for app creation; OpenAI currently says a linked app is then available on mobile clients
  • a PostgreSQL database reachable from the hosted MCP service
  • a dedicated PostgreSQL role with the minimum required grants
  • a datamcp account

OpenAI's current Connect from ChatGPT documentation is the source of truth for availability and interface details.

What ChatGPT can access

The effective permission is the intersection of three boundaries:

BoundaryWhat it controls
ChatGPT workspace and app policyWho may install or use the custom app and which actions are enabled
datamcp MCP linkRead-only, read-write, full-access, or custom table operations
PostgreSQL roleThe database privileges the connection can actually exercise

An MCP link cannot create a PostgreSQL privilege that the connected role does not have. Start with a dedicated read-only role and a read-only MCP link for analytics or exploration.

Step 1: Create a datamcp account

Create a datamcp account. The Free plan supports one source connection and one MCP link, which is enough to test the complete setup.

You will configure two separate authentication boundaries:

  • ChatGPT to datamcp uses OAuth 2.0 with PKCE.
  • datamcp to PostgreSQL uses the database credential stored with the connection.

Do not paste the PostgreSQL password into ChatGPT or into the custom app configuration.

Step 2: Add your database

In datamcp:

  1. Create a new connection.
  2. Select PostgreSQL.
  3. Enter a recognizable connection name.
  4. Add the PostgreSQL host, port, database, username, password, and applicable TLS settings.
  5. Test and save the connection.

datamcp uses the connection to discover schema information and execute approved database tools. PostgreSQL credentials are encrypted at rest with AES-256-GCM.

For a production database, create a dedicated role rather than reusing an owner or migration account. Grant only the schemas, tables, and operations ChatGPT needs.

Open the connection and create an MCP link. Choose the narrowest permission preset that supports the workflow:

  • Read Only permits SELECT queries.
  • Read, Write & Delete permits SELECT, INSERT, UPDATE, and DELETE, but not DDL.
  • Full Access permits everything allowed by the effective PostgreSQL role.
  • Custom selects table-level operations and remains bounded by the PostgreSQL role.

Use Read Only for the first connection. A successful analytics question does not require write or schema-change access.

datamcp's PostgreSQL MCP surface currently includes:

  • query
  • get_permissions
  • get_schema
  • get_table_details
  • get_schema_changes
  • resync_schema

Step 4: Get your ChatGPT URL

Open the ChatGPT tab for the MCP link and copy the generated remote MCP URL intended for the ChatGPT OAuth flow.

The URL identifies the hosted MCP endpoint. It does not contain the PostgreSQL password. Keep the link scoped to this ChatGPT app so it can be revoked without rotating the underlying database credential used by other clients.

Step 5: Connect in ChatGPT

The exact controls can depend on current account and workspace policy.

Enable developer mode

Open Settings → Security and login and turn on Developer mode. If the toggle is unavailable, ask the workspace administrator to allow developer-mode apps.

Create the custom app

In ChatGPT on the web:

  1. Open Settings → Plugins or go to chatgpt.com/plugins.
  2. Select the plus button to create a developer-mode app.
  3. Give the app a recognizable name such as Production analytics — read only.
  4. Paste the datamcp remote MCP URL.
  5. Use OAuth authentication.
  6. Review the disclosed tools and requested access.
  7. Create the app and begin the authentication flow.

During datamcp authorization, select the intended database and MCP link, then approve the connection. Confirm that the app returns to ChatGPT as connected.

Only publish the app to other workspace members after testing its tools and denial behavior. OpenAI notes that custom apps are not verified by OpenAI; the workspace is responsible for vetting the MCP server.

Step 6: Use it

Start a new ChatGPT conversation, select the custom app, and begin with schema or read-only questions.

Good first tests:

  • “Use the database app to list the schemas I can access.”
  • “Show the available tables without returning table data.”
  • “Explain the columns and relationships for the orders table.”
  • “Count completed orders by month for the last six months.”
  • “Show my effective database permissions.”

Then test a denial. If the link is read-only, ask for an UPDATE and confirm that the operation is rejected rather than silently executed.

Review the PostgreSQL query activity in datamcp after the test. The activity page records database tool activity and denied operations and can be exported as CSV or JSON.

Example ChatGPT prompts for PostgreSQL

Explore the schema

Use the PostgreSQL app to inspect the schema. Identify the tables related to customers, subscriptions, and payments. Do not run write queries.

Build an analytics query

Calculate monthly recurring revenue by plan for the last 12 months. First explain which tables and columns you will use, then run a read-only query.

Investigate data quality

Find subscriptions whose customer record is missing or whose status conflicts with the latest payment. Return counts and a small sample, but do not modify anything.

Prepare a query for review

Draft the SQL needed to update expired trials, but do not execute it. Explain the affected rows and rollback strategy.

The final prompt is useful even with a read-only link: ChatGPT can reason about a write operation without receiving permission to perform it.

Can ChatGPT connect directly to a SQL database?

Not through a raw PostgreSQL connection string in the ChatGPT app interface. ChatGPT connects to a remote MCP app, and that server connects to the database or another backend.

This separation matters because the MCP server becomes the place to implement:

  • database-tool definitions
  • OAuth or client authentication
  • link permissions
  • credential storage
  • query execution
  • revocation
  • activity review

For architecture and alternatives, compare hosted and local MCP servers and the best PostgreSQL MCP servers.

ChatGPT PostgreSQL troubleshooting

Developer mode is missing

  • Confirm you are looking under Settings → Security and login.
  • Confirm you are using the intended personal or organization workspace.
  • Ask the workspace administrator whether Developer mode is allowed.
  • Check the current OpenAI availability documentation because the interface can change.

The MCP app cannot connect

  • Confirm the datamcp MCP link is active.
  • Copy the ChatGPT-specific remote URL again.
  • Confirm the endpoint is publicly reachable over HTTPS.
  • Remove a stale app draft and repeat the OAuth flow if the configuration changed.

OAuth completes but no database is available

  • Confirm the datamcp connection is active.
  • Confirm the intended MCP link belongs to that connection.
  • Verify that the authorizing datamcp user can access the organization and connection.
  • Revoke and reconnect the ChatGPT app if the authorization was made against the wrong link.

Schema works but queries fail

  • Inspect the MCP link preset.
  • Check the connected PostgreSQL role's grants.
  • Confirm the requested table is included in a custom policy.
  • Review the denied activity entry for the exact operation and reason.

That is not itself a policy failure. The important test is whether execution is denied. Keep the PostgreSQL role restricted so the backend remains the final enforcement layer.

Security recommendations

  1. Use a dedicated PostgreSQL role.
  2. Start with Read Only.
  3. Scope the link to the required tables and operations.
  4. Test a denied write before sharing the app.
  5. Review ChatGPT app actions before publishing.
  6. Give each environment a separate connection or link.
  7. Revoke the MCP link when the app is no longer needed.
  8. Review query activity regularly.

Read MCP authorization, permissions, and scopes for the complete identity and policy model, or visit the ChatGPT PostgreSQL integration page for the product overview.

ChatGPTPostgreSQLMCPdatabaseOAuth

Ready to connect an AI client?

Create a hosted MCP link for a supported PostgreSQL, MySQL, or OpenAPI source.

Create MCP link

Explore the ChatGPT integration · Questions? Read the docs or view pricing.