本项目的 PostgreSQL MCP 服务器,可助力用户高效搭建并运行相关服务,为数据库操作提供便利。
按照以下步骤,您可以快速完成 PostgreSQL MCP 服务器的安装与配置。
创建一个 PostgreSQL MCP 服务器
我将指导您逐步安装 PostgreSQL MCP 服务器。
1. **下载 PostgreSQL**:
- 访问 [PostgreSQL 官方网站](https://www.postgresql.org/) 下载适合您操作系统的版本。
2. **安装 PostgreSQL**:
- 根据操作系统提供的指南完成安装过程。
3. **配置数据库**:
- 打开 PostgreSQL 配置文件 (`postgresql.conf`) 并进行以下设置:
```plaintext
listen_addresses = '*'
port = 5432
```
- 启动 PostgreSQL 服务并应用更改。
4. **创建 MCP 数据库**:
- 使用 PostgreSQL 命令行工具登录数据库:
```plaintext
psql -U postgres
```
- 创建新数据库:
```plaintext
CREATE DATABASE mcp;
```
- 将用户权限授予 MCP 用户:
```plaintext
GRANT ALL PRIVILEGES ON DATABASE mcp TO mcp_user;
\q
```
5. **安装 MCP 服务器**:
- 克隆 MCP 仓库到本地计算机。
- 进入项目目录并运行安装脚本:
```plaintext
cd mcp-server
npm install
```
- 配置 MCP 环境变量:
```plaintext
export DB_NAME=mcp
export DB_USER=mcp_user
export DB_PASSWORD=your_password
export DB_HOST=localhost
export DB_PORT=5432
```
- 启动 MCP 服务器:
```plaintext
node index.js
```
6. **测试安装**:
- 访问 `http://localhost:3000` 检查 MCP 服务器是否正常运行。
该 PostgreSQL MCP 服务器已成功安装并准备就绪。
查看数据库条目示例:
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 | 99.99 | completed | 2024-01-11
(5 rows)
mydatabase=# SELECT * FROM orders;
id | user_id | product_name | order_date
----+---------+---------------+------------
1 | 1 | Laptop | 2024-01-01
2 | 2 | Phone | 2024-01-05
3 | 3 | Headphones | 2024-01-08
4 | 4 | Mouse | 2024-01-09
5 | 5 | Keyboard | 2024-01-11
(5 rows)
PostgreSQL MCP 服务器的源代码和相关文档受 MIT 许可证保护。完整的许可证内容请参考项目文件中的 LICENSE 文件。
MIT License
Copyright (c) [年份] [作者姓名]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
属性 | 详情 |
---|---|
数据库版本 | PostgreSQL 14.6 |
操作系统 | Ubuntu 22.04 LTS |
Node.js 版本 | v18.12.1 |
MCP 服务器版本 | 1.0.0 |