go-mcp-postgres
概述
从https://github.com/Zhwt/go-mcp-mysql/复制代码,在 AI 的帮助下,我将数据库从 mysql 更改为 postgres。零负担、即用型模型上下文协议 (MCP) 服务器,用于与 Postgres 和自动化交互。无需 Node.js 或 Python 环境。该服务器提供对 MySQL 数据库和表执行 CRUD 操作的工具,以及用于防止意外写入操作的只读模式。您还可以通过添加--with-explain-check
标志,让 MCP 服务器在执行查询之前使用EXPLAIN
语句检查查询计划。
请注意,这是一项正在进行的工作,可能尚未准备好投入生产使用。
安装
- 获取最新版本并将其放在您的
$PATH
或您可以轻松访问的地方。 - 或者如果你已经安装了 Go,你可以从源代码构建它:
用法
方法 A:使用 stdio 模式的命令行参数
注意:对于将二进制文件放在$PATH
之外的人,您需要将go-mcp-postgres
替换为二进制文件的完整路径:例如:如果将二进制文件放在下载文件夹中,则可以使用以下路径:
方法 B:使用 sse 模式的命令行参数
./go-mcp-postgres --t sse --ip xxxx --port nnnn --dsn postgresql://user@host/db --lang en
可选标志
--lang
:设置语言选项(en/zh-CN),默认为系统语言- 添加
--read-only
标志以启用只读模式。在此模式下,只有以list
、read_
和desc_
开头的工具可用。添加此标志后,请务必刷新/重启 MCP 服务器。 - 默认情况下,CRUD 查询将首先使用
EXPLAIN ?
语句执行,以检查生成的查询计划是否符合预期模式。添加--with-explain-check
标志可禁用此行为。
工具
多语言支持:所有工具描述将根据语言参数自动本地化
如果您想添加自己的语言支持,请参考 [locales](for i18n) 文件夹。如果您想在命令行中使用,则需要创建新的 locales/xxx/active-xx.toml 文件。
架构工具
list_database
- ${mcp.tool.list_database.desc}
- 参数:无
- 返回:匹配的数据库名称列表。
list_table
- ${mcp.tool.list_table.desc}
- 参数:
name
:如果提供,则列出具有指定名称的表,否则,列出所有表。
- 返回:匹配的表名列表。
create_table
- ${mcp.tool.create_table.desc}
- 参数:
query
:创建表的 SQL 查询。
- 返回:受影响的 x 行。
alter_table
- 修改 Postgres 服务器中现有的表。LLM 被告知不要删除现有的表或列。
- 参数:
query
:用于修改表的 SQL 查询。
- 返回:受影响的 x 行。
desc_table
- 描述表的结构。
- 参数:
name
:要描述的表的名称。
- 返回:表的结构。
数据工具
read_query
- 执行只读 SQL 查询。
- 参数:
query
:要执行的 SQL 查询。
- 返回:查询的结果。
write_query
- 执行写入 SQL 查询。
- 参数:
query
:要执行的 SQL 查询。
- 返回:受影响的 x 行,最后插入 ID:<last_insert_id>。
update_query
- 执行更新 SQL 查询。
- 参数:
query
:要执行的 SQL 查询。
- 返回:受影响的 x 行。
delete_query
- 执行删除 SQL 查询。
- 参数:
query
:要执行的 SQL 查询。
- 返回:受影响的 x 行。
count_query
- 查询某个表的行数..
- 参数:
name
:要计数的表的名称。
- 返回:表的行号。
再次感谢https://github.com/Zhwt/go-mcp-mysql/ 。
执照
麻省理工学院
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
什么是 go-mcp-postgres?go-mcp-postgres 是一个模型上下文协议 (MCP) 服务器,旨在与 Postgres 数据库交互,允许轻松进行 CRUD 操作和自动化,而无需 Node.js 或 Python 环境。
Related MCP Servers
- AsecurityAlicenseAqualityA beginner-friendly Model Context Protocol (MCP) server that helps users understand MCP concepts, provides interactive examples, and lists available MCP servers. This server is designed to be a helpful companion for developers working with MCP. Also comes with a huge list of servers you can install.Last updated -3936JavaScriptApache 2.0
- -securityFlicense-qualityA server implementing the Model Context Protocol (MCP) for Cursor that allows using a PostgreSQL database as storage for model contexts, enabling secure database exploration and querying.Last updated -JavaScript
- AsecurityAlicenseAqualityA dynamic service that creates and manages Model Context Protocol (MCP) servers, allowing users to spawn, customize, and control multiple MCP servers as child processes.Last updated -565TypeScriptMIT License
- -securityFlicense-qualityA Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.Last updated -TypeScript