
该仓库是 PostgreSQL MCP Server 的扩展,提供创建表、插入条目、更新条目、删除条目和丢弃表的功能。
概览
一个模型上下文协议服务器,提供对 PostgreSQL 数据库的访问。该服务器使大型语言模型能够与数据库交互,检查模式、执行查询,并对数据库条目执行 CRUD(创建、读取、更新、删除)操作。该仓库是 PostgreSQL MCP 服务器的扩展,提供创建表、插入条目、更新条目、删除条目和丢弃表的功能。 要安装PostgreSQL MCP服务器,请按照以下步骤操作: 1. 安装 Docker 和 Claude Desktop 2.克隆仓库:git clone https://github.com/vignesh-codes/ai-agents-mcp-pg.git 3.运行 PG Docker 容器 docker run --name postgres-container -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin_password -e POSTGRES_DB=mydatabase -p 5432:5432 -d postgres:latest 4.构建 mcp 服务器: docker build -t mcp/postgres -f src/Dockerfile 。5. 打开 Claude Desktop,通过更新 mcpServers 字段连接到 MCP 服务器claude_desktop_config。
概述(AI 翻译)
一个模型上下文协议服务器,提供对 PostgreSQL 数据库的访问。该服务器使大型语言模型能够与数据库交互,检查模式、执行查询,并对数据库条目执行 CRUD(创建、读取、更新、删除)操作。该仓库是 PostgreSQL MCP 服务器的扩展,提供创建表、插入条目、更新条目、删除条目和丢弃表的功能。
安装
要安装PostgreSQL MCP服务器,请按照以下步骤操作:
- 安装 Docker 和 Claude Desktop
- 克隆仓库:
git clone https://github.com/vignesh-codes/ai-agents-mcp-pg.git - 运行 PG Docker 容器
docker run --name postgres-container -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin_password -e POSTGRES_DB=mydatabase -p 5432:5432 -d postgres:latest - 建设MCP服务器:
docker build -t mcp/postgres -f src/Dockerfile . - 打开 Claude 桌面,并通过更新
mcpServers字段连接到 MCP 服务器:
使用 Claude Desktop
要将此服务器与 Claude Desktop 应用结合使用,请在你的 claude_desktop_config.json 的“mcpServers” 部分添加以下配置:
Docker
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
PostgreSQL MCP Server
A Model Context Protocol server that provides access to PostgreSQL databases. This server enables LLMs to interact with databases to inspect schemas, execute queries, and perform CRUD (Create, Read, Update, Delete) operations on database entries. This repo is an extension of PostgreSQL MCP Server providing functionalities to create tables, insert entries, update entries, delete entries, and drop tables.
Installation
To install the PostgreSQL MCP Server, follow these steps:
- Install Docker and Claude Desktop
- Clone the repository:
git clone https://github.com/vignesh-codes/ai-agents-mcp-pg.git - Run PG Docker container
docker run --name postgres-container -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin_password -e POSTGRES_DB=mydatabase -p 5432:5432 -d postgres:latest - Build the mcp server:
docker build -t mcp/postgres -f src/Dockerfile . - Open Claude Desktop and connect to the MCP server by updating the
mcpServersfield inclaude_desktop_config.json:
Usage with Claude Desktop
To use this server with the Claude Desktop app, add the following configuration to the “mcpServers” section of your claude_desktop_config.json:
Docker
- When running Docker on macOS, use
host.docker.internalif the server is running on the host network (e.g., localhost). - Username/password can be added to the PostgreSQL URL with
postgresql://user:password@host:port/db-name.
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://username:[email protected]:5432/mydatabase"
]
}
}
}
Make sure to restart the claude desktop app after updating the config file.
Features Added
Existing Functionality
- query
- Execute read-only SQL queries against the connected database.
- Input:
sql(string): The SQL query to execute. - All queries are executed within a READ-ONLY transaction.
New Functionality
-
Create Tables
- Ability to create new tables dynamically by providing a table name and column definitions.
- Input from Claude Desktop:
{ "tableName": "example_table", "columns": [ { "name": "id", "type": "SERIAL PRIMARY KEY" }, { "name": "name", "type": "VARCHAR(255)" }, { "name": "age", "type": "INTEGER" } ] }
-
Insert Entries
- Insert new entries into a specified table.
- Input from Claude Desktop:
{ "tableName": "example_table", "values": { "name": "John Doe", "age": 30 } }
-
Update Entries
- Update existing entries in a table based on conditions.
- Input from Claude Desktop:
安装
docker run -i --rm mcp/postgres postgresql://username:[email protected]:5432/mydatabase配置
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://username:[email protected]:5432/mydatabase"
]
}
}
}