PostgreSQL MCP Server
PostgreSQL MCP 服务器
一个模型上下文协议 (MCP) 服务器,提供直接执行 PostgreSQL 数据库查询的功能。该服务器支持针对 PostgreSQL 数据库执行自定义 SQL 查询,并支持参数化查询和可配置的超时。该项目专为与 Cursor IDE 配合使用而设计。
先决条件
Node.js >= 18.0.0
PostgreSQL 服务器(用于目标数据库操作)
对目标 PostgreSQL 实例的网络访问
Related MCP server: PostgreSQL MCP Server
安装
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 PostgreSQL 数据库查询服务器:
npx -y @smithery/cli install @1Levick3/postgresql-mcp-server --client claude手动安装
克隆存储库
安装依赖项:
npm install构建服务器:
npm run build添加到 MCP 设置文件:
{ "mcpServers": { "postgresql-mcp": { "command": "node", "args": ["/Users/1Levick3/Desktop/postgresql-mcp-server/build/index.js"], "disabled": false, "alwaysAllow": [], "env": { "POSTGRES_CONNECTION_STRING": "postgresUrl", "POSTGRES_SSL_CERT_PATH": "/Users/1levick3/Desktop/root.crt" } } } }
发展
npm run dev- 使用热重载启动开发服务器npm run lint- 运行 ESLintnpm test运行测试
安全注意事项
连接安全
使用连接池
实现连接超时
验证连接字符串
支持 SSL/TLS 连接
贡献
分叉存储库
创建功能分支
提交你的更改
推送到分支
创建拉取请求
Available Tools
1 toolexecute_custom_queryA
Execute a custom SQL query against the database. WARNING: Use with care. Do not expose to untrusted input.
| Name | Required | Description | Default |
|---|---|---|---|
| connectionString | Yes | PostgreSQL connection string | |
| query | Yes | SQL query to execute | |
| values | No | Optional parameter values for the query | |
| timeout | No | Optional query timeout in milliseconds |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates critical behavioral traits: that this is a potentially dangerous operation (executing arbitrary SQL), includes security warnings, and implies it can modify data. However, it doesn't specify what happens on success/failure, whether transactions are used, or what format results are returned in.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is perfectly concise with just two sentences that each earn their place: the first states the core functionality, the second provides critical warnings. It's front-loaded with the main purpose and appropriately sized for the tool's complexity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a potentially destructive database operation with no annotations and no output schema, the description provides adequate but incomplete context. It covers the dangerous nature and security considerations well, but doesn't explain what happens on execution (e.g., returns results, affects rows), error handling, or result formats, leaving gaps for the agent to navigate.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
With 100% schema description coverage, the schema already documents all 4 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline expectation but doesn't provide additional value regarding parameter usage or semantics.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose with a specific verb ('execute') and resource ('custom SQL query against the database'), making it immediately understandable. It distinguishes what this tool does from potential alternatives by specifying it's for custom SQL execution rather than predefined operations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides clear contextual guidance with the 'WARNING: Use with care. Do not expose to untrusted input' statement, which helps the agent understand appropriate usage scenarios and security considerations. However, it doesn't specify when to use this tool versus alternative query methods or database tools since no sibling tools are listed.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
- First observed
execute_custom_query
TDQS
Scored across 1 tool
With only one tool, there is no possibility of confusion or overlap between tools. The tool's purpose is clearly defined and distinct by default.
The single tool follows a clear verb_noun pattern (execute_custom_query), and there are no other tools to create inconsistency. The naming is straightforward and predictable.
A single tool for a PostgreSQL server is too few for the apparent scope, as it lacks basic CRUD operations, schema management, or other database functions. This minimal set limits functionality and forces all interactions through a generic query tool.
The tool surface is severely incomplete for a database server. There are no tools for common operations like listing tables, inserting data, or managing connections, leaving significant gaps that will cause agent failures in typical database workflows.
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
- SupabaseOAuthcom.supabase
MCP server for interacting with the Supabase platform
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.181,153 npm199AGPL 3.0
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.7 npmMIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server implementation that provides a simple interface to interact with PostgreSQL databases, enabling SQL queries, database operations, and schema management through MCP.-
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server for PostgreSQL that enables database operations like querying, schema inspection, performance analysis, and administration through a JSON-RPC 2.0 interface.MIT