MCP SERVER

PostgreSQL MCP Server — 让 AI Agent 实时访问 SQL 数据库

安装 PostgreSQL MCP 服务器,让 Claude Code、Cursor 和 Windsurf 实时查询数据库。读取表结构、执行 SELECT、分析查询计划、排查慢查询——不需要来回粘贴 SQL。

6 个工具

安装 PostgreSQL MCP Server

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:password@localhost:5432/dbname"
      ]
    }
  }
}
Paste into ~/.cursor/mcp.json, replace the connection string, restart Cursor

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 30MCP Configs

Neon MCP — Serverless Postgres via AI Agents

MCP server for Neon serverless Postgres. Create projects, branch databases, run SQL, optimize queries via natural language. Safe migration workflow with branching. MIT, 574+ stars.

MCP Hub 34MCP Configs
🔌

DBHub — Universal Database MCP Server, Zero Dependencies

Token-efficient database MCP server supporting Postgres, MySQL, MariaDB, SQL Server, and SQLite. Just two MCP tools, zero dependencies, read-only safe.

TokRepo精选 22MCP Configs

Supabase MCP — Postgres + Auth Server for AI Agents

MCP server for Supabase that gives AI agents access to PostgreSQL databases, authentication, storage, and edge functions. Query data, manage users, and build full-stack features. 4,000+ stars.

MCP Hub 21MCP Configs

GenAI Toolbox — MCP Server for Databases by Google

Open-source MCP server for databases by Google. Connect AI agents to PostgreSQL, MySQL, Cloud SQL, AlloyDB, and Spanner with built-in auth, connection pooling, and safety. 13K+ stars.

MCP Hub 18MCP Configs

PostgreSQL MCP — SQL Database Server for AI Agents

MCP server that gives AI agents direct access to PostgreSQL databases. Run queries, explore schemas, manage tables, and analyze data through natural language. 3,000+ stars.

MCP Hub 16MCP Configs

AI Agent 的实时数据库上下文

The PostgreSQL MCP server solves the most frustrating failure mode in AI-assisted development: the model writes perfect-looking SQL against a schema that doesn't exist. With the MCP server installed, Claude Code and Cursor can inspect your real tables, read live column types, check actual indexes, and test queries before suggesting them. No more "hallucinated table names" — the model is grounded in what's actually in your database.

The official reference implementation ships in read-only mode by default, which is exactly what you want for a production connection. The AI can SELECT, run EXPLAIN ANALYZE, and explore pg_catalog — but it can't accidentally DROP TABLE users. For write access, point it at a separate dev database or create a bounded role with explicit grants. Both modes are production-safe when configured correctly.

Where this gets transformative is pairing the PostgreSQL MCP server with a GitHub MCP server. An agent can now: read a failing migration from a PR, check the current schema in staging, detect the conflict, rewrite the migration, and open a follow-up PR — all in one conversation. For broader database tooling including MySQL, MongoDB, and Supabase, browse the TokRepo database directory. For agent frameworks that chain these tools together, see our agent building tools.

The moment your AI stops hallucinating table names is the moment it starts shipping real migrations.

常见问题

What is the PostgreSQL MCP server?+

The PostgreSQL MCP server is an open-source implementation of the Model Context Protocol that lets AI agents query a Postgres database. It exposes a set of structured tools — list tables, describe schema, run query, explain query — and handles connection pooling and error handling. The reference implementation is read-only by default and ships under @modelcontextprotocol/server-postgres on npm.

How do I install the Postgres MCP server in Claude Code?+

Run `claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@host:5432/db` in your terminal, then restart Claude Code. Verify with `claude mcp list`. For production databases, we strongly recommend creating a dedicated read-only Postgres role and putting its credentials in the connection string — never use a superuser account.

Is it safe to connect the MCP server to a production database?+

Yes, if you use a read-only role and enable statement timeouts. Create a Postgres role with only SELECT permissions on the schemas the AI needs, set `statement_timeout` on the role to prevent runaway queries, and consider putting the connection through pgbouncer with a capped pool size. Never give the AI an account with DROP or TRUNCATE privileges on production data.

Can the MCP server write to the database?+

The official reference implementation is read-only. For write access you have two options: (1) Use a fork that supports INSERT/UPDATE with approval workflows, or (2) Run a second instance of the server against a separate dev/staging database where write access is safe. Many teams keep a read-only production connection AND a writable staging connection configured simultaneously.

Does it work with Supabase, Neon, and other hosted Postgres?+

Yes. Anything that speaks the Postgres wire protocol works — Supabase, Neon, Railway, AWS RDS, Azure Database for PostgreSQL, Google Cloud SQL, and self-hosted clusters. Just point the connection string at the host. For Supabase specifically, check the TokRepo database directory — there's a dedicated Supabase MCP server that also exposes auth and storage APIs.

What PostgreSQL versions are supported?+

The reference server uses the node-postgres driver, which supports PostgreSQL 9.4 through 17. For query-plan inspection features (EXPLAIN ANALYZE with JSON output), you need PostgreSQL 9.6+. For the best experience with modern AI workflows, we recommend PostgreSQL 15 or 16 since they expose richer pg_stat views the AI can use for performance diagnosis.

探索更多分类