Postgres MCP是一个为PostgreSQL数据库实现的Model Control Protocol (MCP) 服务器。它提供了简单的HTTP接口,可通过MCP与PostgreSQL数据库交互,支持执行只读查询并探索数据库资源。
Postgres MCP是一个用于PostgreSQL数据库的MCP服务器,可通过HTTP接口与之交互。以下是使用前的准备和启动步骤。
git clone https://github.com/ipfans/postgres-mcp.git
cd postgres-mcp
go mod download
可以通过两种方式配置数据库连接:
go run cmd/postgres-mcp/main.go -db "postgres://user:password@localhost:5432/dbname"
.env
文件。DATABASE_URL=postgres://user:password@localhost:5432/dbname
go run cmd/postgres-mcp/main.go
服务器将在默认端口8080启动。
.env
文件支持环境变量,灵活配置数据库连接。POST http://localhost:8080/mcp
Content-Type: application/json
{
"type": "function",
"name": "resources"
}
POST http://localhost:8080/mcp
Content-Type: application/json
{
"type": "function",
"name": "query",
"arguments": {
"query": "SELECT * FROM your_table LIMIT 10"
}
}
该项目是开源的,采用MIT许可证。
欢迎贡献!请随意提交拉取请求。