这是一个提供对PostgreSQL数据库只读访问的Model Context Protocol服务器。此服务器使LLMs能够检查数据库模式并执行只读查询。
sql(字符串):要执行的SQL查询该服务器提供了数据库中每个表的模式信息:
postgres://<host>/<table>/schema)
要在Claude Desktop应用中使用此服务器,请在您的claude_desktop_config.json文件的“mcpServers”部分添加以下配置:
host.docker.internalpostgresql://user:password@host:port/db-name{
"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文件。