这是一个针对PostgreSQL数据库的Model Control Protocol (MCP)服务器实现。该项目提供了一个简单的HTTP接口,通过MCP与PostgreSQL数据库进行交互,允许执行只读查询并探索数据库资源。
.env文件支持环境变量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端口启动。
列出数据库资源:
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许可证下可用。
欢迎贡献!请随时提交Pull Request。