MCP Configs2026年3月29日·1 分钟阅读

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.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Mcp Config
安装
Stage only
信任
信任等级:Established
入口
PostgreSQL MCP Server — Database Queries for AI
安全暂存命令
npx -y tokrepo@latest install 1ca69a22-de42-4722-af49-3d0869362e2d --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

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.

常见问题

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.

引用来源 (3)
🙏

来源与感谢

Created by Anthropic. Licensed under MIT. modelcontextprotocol/servers

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产