PostgreSQL Query MCP Server
MCP Postgres 查询服务器
模型上下文协议 (MCP) 服务器实现,用于以只读模式查询 PostgreSQL 数据库,旨在与 Claude Desktop 和其他 MCP 客户端配合使用。
概述
该项目实现了模型上下文协议(MCP)服务器,它提供:
PostgreSQL 数据库的安全只读接口
通过 MCP 协议与 Claude Desktop 集成
SQL 查询验证以确保仅执行 SELECT 查询
查询超时保护(10秒)
Related MCP server: PostgreSQL MCP Server
先决条件
Node.js(v14 或更高版本)
npm(Node.js 附带)
PostgreSQL 数据库(通过命令行提供连接详细信息)
安装
# Clone the repository
git clone https://github.com/RathodDarshil/mcp-postgres-query-server.git
cd mcp-postgres-query-server
# Install dependencies
npm install
# Build the project
npm run build连接到 Claude Desktop
您可以配置 Claude Desktop 自动启动并连接到 MCP 服务器:
访问 Claude Desktop 配置文件:
打开 Claude 桌面
前往“设置”>“开发者”>“编辑配置”
这将在您的默认文本编辑器中打开配置文件
将 postgres-query-server 添加到
claude_desktop_config.json的mcpServers部分:
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:port/database"
]
}
}
}将
/path/to/your/替换为项目目录的实际路径。将 PostgreSQL 连接字符串替换为您的实际数据库凭据。
保存文件并重启 Claude Desktop。MCP 服务器现在应该出现在“设置”中的 MCP 服务器选择下拉菜单中。
示例配置
以下是 postgres-query 配置文件的完整示例:
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/Users/darshilrathod/mcp-servers/mcp-postgres-query-server/dist/index.js",
"postgresql://user:password@localhost:5432/mydatabase"
]
}
}
}更新配置
要更新您的 Claude Desktop 配置:
打开 Claude 桌面
前往“设置”>“开发者”>“编辑配置”
对配置文件进行更改
保存文件
重新启动 Claude Desktop 以使更改生效
如果您已更新 MCP 服务器代码,请确保在重新启动之前使用
npm run build重新构建它
特征
只读数据库访问:出于安全考虑,只允许执行 SELECT 查询
查询验证:防止潜在的有害 SQL 操作
超时保护:运行时间超过 10 秒的查询将自动终止
MCP 协议支持:完整实现模型上下文协议
JSON 响应格式:查询结果以结构化的 JSON 格式返回
API
工具
查询-postgres
对配置的 PostgreSQL 数据库执行只读 SQL 查询。
参数:
query(字符串):要执行的 SQL SELECT 查询
回复:
JSON 对象包含:
rows:结果集行rowCount:返回的行数fields:列元数据
例子:
query-postgres: SELECT * FROM users LIMIT 5发展
主服务器实现位于src/index.ts中。关键组件:
PostgreSQL 连接池设置
查询验证逻辑
MCP 服务器配置
工具和资源定义
要修改服务器的行为,您可以:
编辑
isReadOnlyQuery()中的查询验证逻辑向 MCP 服务器添加额外的工具或资源
修改查询超时时长(目前为10秒)
安全注意事项
服务器验证所有查询以确保它们是只读的
使用 SSL 连接数据库
查询超时可防止资源耗尽
不允许进行任何写入操作
数据库凭证直接通过命令行参数传递,而不是存储在文件中
执照
国际学习中心
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
Available Tools
1 toolquery-postgresD
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
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?
Tool has no description.
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?
Tool has no description.
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?
Tool has no description.
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?
Tool has no description.
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?
Tool has no description.
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. Dates show when Glama detected each change.
1 tool update
- First observed
query-postgres
TDQS
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is singular and clear, eliminating any risk of misselection.
A single tool inherently has perfect naming consistency, as there are no other tools to compare it against. The name 'query-postgres' follows a clear verb-noun pattern without any conflicting conventions.
A single tool is too few for a PostgreSQL server's apparent scope, which typically involves multiple operations like querying, inserting, updating, and deleting data. This minimal set severely limits functionality and agent workflows.
The tool surface is severely incomplete for a PostgreSQL domain, covering only querying. Obvious gaps include create, update, delete, schema management, and transaction handling, which will cause frequent agent failures in database interactions.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- -licenseNot gradedqualityAmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.100,74590,042MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.100,745MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.100,745MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries.100,745MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/RathodDarshil/mcp-postgres-query-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server