Token导航 LogoToken导航TokenDH.com
PostgreSQL MCP Server logo
数据服务未说明官方级别未说明来源级核验

PostgreSQL MCP Server

MCP Server

This repo is an extension of PostgreSQL MCP Server providing functionalities to create tables, insert entries, update entries, delete entries, and drop tables.

工具数

6

提示词数

0

GitHub Stars

27

资源数

0
数据分析数据库交互JavaScriptClaudeAI代理Claude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

vignesh-codes

提供方

vignesh-codes

最后核验

2026/5/18 03:27

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

PostgreSQL MCP服务器

一个模型上下文协议服务器,提供对PostgreSQL数据库的访问。此服务器使LLM能够与数据库交互,以检查模式、执行查询,并对数据库条目执行CRUD(创建、读取、更新、删除)操作。此回购是 PostgreSQL MCP服务器 提供创建表、插入条目、更新条目、删除条目和删除表的功能。

安装

要安装PostgreSQL MCP服务器,请按照以下步骤操作:

  1. 安装Docker和Claude桌面
  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,通过更新连接到MCP服务器 mcpServers 字段在 claude_desktop_config.json:

使用Claude Desktop

要将此服务器与Claude Desktop应用程序一起使用,请将以下配置添加到您的“mcpServers”部分 claude_desktop_config.json:

码头工人

  • 在macOS上运行Docker时,请使用 host.docker.internal 如果服务器在主机网络(例如localhost)上运行。
  • 用户名/密码可以添加到PostgreSQL URL中 postgresql://user:password@host:port/db-name.
{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "mcp/postgres",
        "postgresql://username:password@host.docker.internal:5432/mydatabase"
      ]
    }
  }
}

请确保在更新配置文件后重新启动claude桌面应用程序。

新增功能

现有功能

  • 怎么翻译

- 对连接的数据库执行只读SQL查询。 - 输入: sql (string):要执行的SQL查询。 - 所有查询都在只读事务中执行。

新功能

  1. 创建表格

- 通过提供表名和列定义动态创建新表的能力。 - 来自Claude Desktop的输入:

     {
       "tableName": "example_table",
       "columns": [
         { "name": "id", "type": "SERIAL PRIMARY KEY" },
         { "name": "name", "type": "VARCHAR(255)" },
         { "name": "age", "type": "INTEGER" }
       ]
     }
  1. 插入条目

- 在指定表中插入新条目。 - 来自Claude Desktop的输入:

     {
       "tableName": "example_table",
       "values": {
         "name": "John Doe",
         "age": 30
       }
     }
  1. 更新条目

- 根据条件更新表中的现有条目。 - 来自Claude Desktop的输入:

     {
       "tableName": "example_table",
       "values": {
         "age": 35
       },
       "conditions": "name = 'John Doe'"
     }
  1. 删除条目

- 根据条件删除表中的特定条目。 - 来自Claude Desktop的输入:

     {
       "tableName": "example_table",
       "conditions": "name = 'John Doe'"
     }
  1. 放下桌子

- 从数据库中删除现有表。 - 来自Claude Desktop的输入:

     {
       "tableName": "example_table"
     }

资源

服务器为数据库中的每个表提供架构信息:

  • 持微软签名的表模式 (postgres:////schema)

- 每个表的JSON模式信息。 - 包括列名和数据类型。 - 从数据库元数据中自动发现。

样品

输入到克劳德桌面

lets create three tables - users, payments and orders tables. Each table must have a unique id and other required columns. Payments table must have user id as foreign key. Orders table must have payment id as foreign key. Add some sample data to these tables

Claude Desktop的输出

I'll help you create these three interconnected tables and populate them with sample data. Let's create them one by one.

1. First, let's create the users table:
{
  `columns`: [
    {
      `name`: `id`,
      `type`: `INTEGER PRIMARY KEY`
    },
    {
      `name`: `name`,
      `type`: `TEXT`
    },
    {
      `name`: `email`,
      `type`: `TEXT`
    },
    {
      `name`: `created_at`,
      `type`: `TEXT`
    }
  ],
  `tableName`: `users`
}

2. Now, let's create the payments table with a foreign key reference to users:
{
  `columns`: [
    {
      `name`: `id`,
      `type`: `INTEGER PRIMARY KEY`
    },
    {
      `name`: `user_id`,
      `type`: `INTEGER`
    },
    {
      `name`: `amount`,
      `type`: `REAL`
    },
    {
      `name`: `status`,
      `type`: `TEXT`
    },
    {
      `name`: `payment_date`,
      `type`: `TEXT`
    }
  ],
  `tableName`: `payments`
}

3. Finally, let's create the orders table with a foreign key reference to payments:
{
  `columns`: [
    {
      `name`: `id`,
      `type`: `INTEGER PRIMARY KEY`
    },
    {
      `name`: `payment_id`,
      `type`: `INTEGER`
    },
    {
      `name`: `product_name`,
      `type`: `TEXT`
    },
    {
      `name`: `quantity`,
      `type`: `INTEGER`
    },
    {
      `name`: `order_date`,
      `type`: `TEXT`
    }
  ],
  `tableName`: `orders`
}

Now, let's add some sample data to these tables.

First, let's add some users:
{
  `values`: {
    `id`: `1`,
    `name`: `John Doe`,
    `email`: `john@example.com`,
    `created_at`: `2024-01-01`
  },
  `tableName`: `users`
}

{
  `values`: {
    `id`: `2`,
    `name`: `Jane Smith`,
    `email`: `jane@example.com`,
    `created_at`: `2024-01-05`
  },
  `tableName`: `users`
}

Now, let's add some payments for these users:
{
  `values`: {
    `id`: `1`,
    `amount`: `99.99`,
    `status`: `completed`,
    `user_id`: `1`,
    `payment_date`: `2024-01-10`
  },
  `tableName`: `payments`
}

{
  `values`: {
    `id`: `2`,
    `amount`: `149.99`,
    `status`: `completed`,
    `user_id`: `2`,
    `payment_date`: `2024-01-12`
  },
  `tableName`: `payments`
}

Finally, let's add some orders linked to these payments:
{
  `values`: {
    `id`: `1`,
    `quantity`: `1`,
    `order_date`: `2024-01-10`,
    `payment_id`: `1`,
    `product_name`: `Laptop`
  },
  `tableName`: `orders`
}

{
  `values`: {
    `id`: `2`,
    `quantity`: `2`,
    `order_date`: `2024-01-12`,
    `payment_id`: `2`,
    `product_name`: `Smartphone`
  },
  `tableName`: `orders`
}

Let's verify the data by querying each table:

{
  `sql`: `SELECT * FROM users;`
}

{
  `sql`: `SELECT * FROM payments;`
}

{
  `sql`: `SELECT * FROM orders;`
}

Great! We have now created three interconnected tables with sample data. Here's a summary of what we've set up:

1. Users table with basic user information
2. Payments table linked to users through user_id
3. Orders table linked to payments through payment_id

The data shows two users who have each made one payment and placed one order. We can now perform various queries to analyze the relationships between these tables. Would you like to see any specific queries or add more data?

输入到克劳德桌面

add few more users with IN_PROGRESS and UNSUCCESSFUL payment status

Claude Desktop的输出

I'll add a few more users with different payment statuses.

First, let's add new users:

{
  `values`: {
    `id`: `3`,
    `name`: `Mike Johnson`,
    `email`: `mike@example.com`,
    `created_at`: `2024-01-08`
  },
  `tableName`: `users`
}

{
  `values`: {
    `id`: `4`,
    `name`: `Sarah Wilson`,
    `email`: `sarah@example.com`,
    `created_at`: `2024-01-09`
  },
  `tableName`: `users`
}

{
  `values`: {
    `id`: `5`,
    `name`: `Tom Brown`,
    `email`: `tom@example.com`,
    `created_at`: `2024-01-11`
  },
  `tableName`: `users`
}

Now, let's add payments with IN_PROGRESS and UNSUCCESSFUL statuses for these users:
{
  `values`: {
    `id`: `3`,
    `amount`: `299.99`,
    `status`: `IN_PROGRESS`,
    `user_id`: `3`,
    `payment_date`: `2024-01-13`
  },
  `tableName`: `payments`
}

{
  `values`: {
    `id`: `4`,
    `amount`: `199.99`,
    `status`: `UNSUCCESSFUL`,
    `user_id`: `4`,
    `payment_date`: `2024-01-13`
  },
  `tableName`: `payments`
}

{
  `values`: {
    `id`: `4`,
    `amount`: `199.99`,
    `status`: `UNSUCCESSFUL`,
    `user_id`: `4`,
    `payment_date`: `2024-01-13`
  },
  `tableName`: `payments`
}

{
  `values`: {
    `id`: `5`,
    `amount`: `399.99`,
    `status`: `IN_PROGRESS`,
    `user_id`: `5`,
    `payment_date`: `2024-01-13`
  },
  `tableName`: `payments`
}

Let's add orders for the IN_PROGRESS payments (note that we won't add orders for the UNSUCCESSFUL payment):
{
  `values`: {
    `id`: `3`,
    `quantity`: `1`,
    `order_date`: `2024-01-13`,
    `payment_id`: `3`,
    `product_name`: `Gaming Console`
  },
  `tableName`: `orders`
}

{
  `values`: {
    `id`: `4`,
    `quantity`: `1`,
    `order_date`: `2024-01-13`,
    `payment_id`: `5`,
    `product_name`: `4K TV`
  },
  `tableName`: `orders`
}

Let's verify the data by checking all payments with their status:

{
  `sql`: `SELECT u.name, p.amount, p.status, p.payment_date 
FROM users u 
JOIN payments p ON u.id = p.user_id 
ORDER BY p.payment_date;`
}

Now we have a good mix of payment statuses in our database:
- 2 completed payments (John and Jane)
- 2 in-progress payments (Mike and Tom)
- 1 unsuccessful payment (Sarah)

The orders table only contains entries for completed and in-progress payments, as it makes sense not to create orders for unsuccessful payments. Would you like to see any specific queries or add more data?

输入到克劳德桌面

Fetch the users info who have IN_PROGRESS payment status

Claude Desktop的输出

I'll write a query to fetch user information for those who have payments with IN_PROGRESS status.
{
  `sql`: `
SELECT u.*, p.amount, p.payment_date
FROM users u
JOIN payments p ON u.id = p.user_id
WHERE p.status = 'IN_PROGRESS'
ORDER BY u.id;
`
}

We can see that two users have payments in progress:
1. Mike Johnson (attempting to pay $299.99)
2. Tom Brown (attempting to pay $399.99)

Both payments were initiated on January 13, 2024. Would you like to see any additional information about these users or their orders?

输入到克劳德桌面

Lets update the payment status to completed for Mike Johnson

Claude Desktop的输出


I'll update Mike Johnson's payment status from IN_PROGRESS to completed.
{
  `values`: {
    `status`: `completed`
  },
  `tableName`: `payments`,
  `conditions`: {
    `user_id`: `3`
  }
}

Let's verify the update by checking all payments again:

{
  `sql`: `
SELECT u.name, p.amount, p.status, p.payment_date 
FROM users u 
JOIN payments p ON u.id = p.user_id 
ORDER BY p.status, p.payment_date;
`
}

The update was successful. Now we have:
- 3 completed payments (John, Jane, and Mike)
- 1 in-progress payment (Tom)
- 1 unsuccessful payment (Sarah)

Would you like to make any other updates to the data?

数据库条目

mydatabase=# SELECT * FROM users;
 id |     name     |       email       | created_at 
----+--------------+-------------------+------------
  1 | John Doe     | john@example.com  | 2024-01-01
  2 | Jane Smith   | jane@example.com  | 2024-01-05
  3 | Mike Johnson | mike@example.com  | 2024-01-08
  4 | Sarah Wilson | sarah@example.com | 2024-01-09
  5 | Tom Brown    | tom@example.com   | 2024-01-11
(5 rows)

mydatabase=# SELECT * FROM payments;
 id | user_id | amount |    status    | payment_date 
----+---------+--------+--------------+--------------
  1 |       1 |  99.99 | completed    | 2024-01-10
  2 |       2 | 149.99 | completed    | 2024-01-12
  4 |       4 | 199.99 | UNSUCCESSFUL | 2024-01-13
  5 |       5 | 399.99 | IN_PROGRESS  | 2024-01-13
  3 |       3 | 299.99 | completed    | 2024-01-13
(5 rows)

mydatabase=# SELECT * FROM orders;
 id | payment_id |  product_name  | quantity | order_date 
----+------------+----------------+----------+------------
  1 |          1 | Laptop         |        1 | 2024-01-10
  2 |          2 | Smartphone     |        2 | 2024-01-12
  3 |          3 | Gaming Console |        1 | 2024-01-13
  4 |          5 | 4K TV          |        1 | 2024-01-13
(4 rows)

许可证

此MCP服务器根据MIT许可证获得许可。这意味着您可以根据MIT许可证的条款和条件自由使用、修改和分发软件。有关更多详细信息,请参阅项目存储库中的LICENSE文件。

目录标签

目录标签

数据分析数据库交互JavaScriptClaudeAI代理databasesmcpai-agentsllm-postgres本地部署CRUD操作LLM集成PostgreSQL

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

6

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP