Cette page est affichée en anglais. Une traduction française est en cours.
MCP ConfigsMar 29, 2026·1 min de lecture

PostgreSQL MCP Server — Database Queries for AI

MCP server for PostgreSQL database access. Run read-only SQL queries, inspect schemas, list tables, and analyze data directly from Claude Code or Cursor.

MCP Hub
MCP Hub · Community
Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 17/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
Mcp Config
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
PostgreSQL MCP Server — Database Queries for AI
Commande de staging sûr
npx -y tokrepo@latest install 1ca69a22-de42-4722-af49-3d0869362e2d --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

TL;DR
Connect Claude Code or Cursor to PostgreSQL for read-only queries, schema inspection, and data analysis via MCP.
§01

What it is

PostgreSQL MCP Server is an MCP integration that connects AI coding tools directly to PostgreSQL databases. It enables schema inspection, read-only SQL queries, and data analysis through natural language. The server runs as a local process and communicates with AI agents using the Model Context Protocol standard.

This tool targets developers and data analysts who want to explore databases, debug queries, and generate reports without switching between their AI coding assistant and a database client.

§02

How it saves time or tokens

Instead of copying table schemas and query results between a database client and your AI assistant, the MCP server gives the agent direct read access. The agent can inspect column types, run SELECT queries, and iterate on results in a single conversation. Read-only mode by default prevents accidental data modifications.

§03

How to use

  1. Add the MCP server to your .mcp.json configuration with your PostgreSQL connection string.
  2. Restart your AI coding tool (Claude Code, Cursor, or similar MCP-compatible client).
  3. Ask the agent to list tables, inspect schemas, or run SQL queries in natural language.
§04

Example

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost:5432/mydb"]
    }
  }
}

After configuration, ask your AI agent: 'List all tables in the public schema' or 'Show me the top 10 orders by total amount.'

§05

Related on TokRepo

§06

Common pitfalls

  • The connection string is passed as a command argument, which may be visible in process listings; use environment variables for production databases.
  • Read-only mode only restricts the MCP server layer; ensure your database user also has limited permissions as defense in depth.
  • Large query results consume context window tokens; add LIMIT clauses to keep responses manageable.

Questions fréquentes

Is PostgreSQL MCP Server read-only by default?+

Yes. The server restricts operations to SELECT queries by default. DDL and DML operations like INSERT, UPDATE, and DELETE are blocked unless you explicitly enable write mode in the configuration.

Which AI coding tools support PostgreSQL MCP Server?+

Any MCP-compatible tool works, including Claude Code, Cursor, and Gemini CLI. The server uses the standard Model Context Protocol, so future tools that adopt MCP will also be compatible.

How do I connect to a remote PostgreSQL database?+

Pass the full connection string including host, port, username, password, and database name in the args array. For SSL connections, append sslmode=require to the connection string.

Can I use this with multiple databases?+

Yes. Add multiple entries in your .mcp.json, each with a different server name and connection string. Your AI agent can then switch between databases during a conversation.

What happens if a query is too large?+

Large result sets consume context window tokens and may cause truncation. Use LIMIT and WHERE clauses to keep results focused. The MCP server does not impose its own row limits by default.

Sources citées (3)
🙏

Source et remerciements

Created by Anthropic. Licensed under MIT. modelcontextprotocol/servers

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.