💻 go-mcp-db-postgresql(可译为“用于MCP的Go语言PostgreSQL数据库驱动”或根据具体上下文调整)
描述:\ 用Go语言实现的MCP(模型上下文协议)服务器,提供了一个工具用于在PostgreSQL中执行SQL查询,并以JSON格式返回结果。
______________________________________________________________________
🛠 暴露的工具
run_sql
- 描述: 执行一个SQL查询
SELECT在 PostgreSQL 中执行,并以 JSON 格式返回结果。 - 安全限制: 只允许以以下内容开始的查询:
SELECT。
使用示例(输入JSON):
{
"query": "SELECT id, name FROM users;"
}输出示例:
[
{"id":1,"name":"UserName1"},
{"id":2,"name":"UserName2"}
]______________________________________________________________________
🔌 安装(Windows)
- 克隆此仓库:
git clone https://github.com/tu_usuario/go-mcp-db-postgresql.git- 编译二进制文件:
go build -o go-mcp-db-postgresql.exe ./cmd二进制 go-mcp-db-postgresql.exe 这是通过STDIO运行的MCP服务器。______________________________________________________________________
⚡ 与客户端一起使用(mcpServers)
在你的客户端配置文件中添加此设置:
{
"mcpServers": {
"postgres": {
"name": "MCP DB PostgreSQL",
"command": "C:\\Users\\TU_USUARIO\\Proyectos\\go-mcp-db-postgresql.exe",
"description": "Servidor MCP que expone el tool run_sql",
"env": {
"PG_DSN": "postgres://postgres:admin@localhost:5432/dbTest?sslmode=disable"
}
}
}
}nameMCP服务器的友好标题。command编译后的可执行文件的绝对路径。description客户端可选显示的描述性文本。
根据你编译/保存的位置调整二进制文件的路径。\ 启动客户端时,它会自动发现服务器和工具 run_sql。______________________________________________________________________
