PostgreSQL MCP服务器添加福利群:解决AI开发者的「MCP实战痛点」一个提供只读访问 PostgreSQL 数据库的模型上下文协议服务器。该服务器使 LLMs 能够检查数据库模式并执行只读查询。
sql(字符串):要执行的 SQL 查询服务器提供数据库中每个表的模式信息:
postgres://<host>/<table>/schema)
要在 Claude Desktop 应用程序中使用此服务器,请将以下配置添加到 claude_desktop_config.json 的 "mcpServers" 部分:
host.docker.internalpostgresql://user:password@host:port/db-name 添加到 PostgreSQL URL 中{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"]
}
}
}

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

将 /mydb 替换为您的数据库名称。
为了快速安装,请使用下面的一键安装按钮...
对于手动安装,请将以下 JSON 块添加到 VS Code 的用户设置(JSON)文件中。您可以通过按 Ctrl + Shift + P 并输入 Preferences: Open User Settings (JSON) 来完成此操作。
可选地,您可以将其添加到工作区中名为 .vscode/mcp.json 的文件中。这将允许您与其他人共享配置。
请注意,
.vscode/mcp.json文件中不需要mcp键。
注意:使用 Docker 并连接到主机上的 PostgreSQL 服务器时,请在连接 URL 中使用 host.docker.internal 而不是 localhost。
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@host.docker.internal:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"${input:pg_url}"
]
}
}
}
}

{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@localhost:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"${input:pg_url}"
]
}
}
}
}

Docker:
docker build -t mcp/postgres -f src/postgres/Dockerfile .
此 MCP 服务器根据 MIT 许可证授权。这意味着您可以自由使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。有关更多详细信息,请参阅项目存储库中的 LICENSE 文件。