Skip to main content
Glama

go-mcp-postgres

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语句检查查询计划。

请注意,这是一项正在进行的工作,可能尚未准备好投入生产使用。

安装

  1. 获取最新版本并将其放在您的$PATH或您可以轻松访问的地方。
  2. 或者如果你已经安装了 Go,你可以从源代码构建它:
go install -v github.com/guoling2008/go-mcp-postgres@latest

用法

方法 A:使用 stdio 模式的命令行参数

{ "mcpServers": { "postgres": { "command": "go-mcp-postgres", "args": [ "--dsn", "postgresql://user:pass@host:port/db" ] } } }

注意:对于将二进制文件放在$PATH之外的人,您需要将go-mcp-postgres替换为二进制文件的完整路径:例如:如果将二进制文件放在下载文件夹中,则可以使用以下路径:

{ "mcpServers": { "postgres": { "command": "C:\\Users\\<username>\\Downloads\\go-mcp-postgres.exe", "args": [ ... ] } } }

方法 B:使用 sse 模式的命令行参数

./go-mcp-postgres --t sse --ip xxxx --port nnnn --dsn postgresql://user@host/db --lang en

可选标志

  • --lang :设置语言选项(en/zh-CN),默认为系统语言
  • 添加--read-only标志以启用只读模式。在此模式下,只有以listread_desc_开头的工具可用。添加此标志后,请务必刷新/重启 MCP 服务器。
  • 默认情况下,CRUD 查询将首先使用EXPLAIN ?语句执行,以检查生成的查询计划是否符合预期模式。添加--with-explain-check标志可禁用此行为。

工具

多语言支持:所有工具描述将根据语言参数自动本地化

如果您想添加自己的语言支持,请参考 [locales](for i18n) 文件夹。如果您想在命令行中使用,则需要创建新的 locales/xxx/active-xx.toml 文件。

架构工具

  1. list_database
    • ${mcp.tool.list_database.desc}
    • 参数:无
    • 返回:匹配的数据库名称列表。
  2. list_table
    • ${mcp.tool.list_table.desc}
    • 参数:
      • name :如果提供,则列出具有指定名称的表,否则,列出所有表。
    • 返回:匹配的表名列表。
  3. create_table
    • ${mcp.tool.create_table.desc}
    • 参数:
      • query :创建表的 SQL 查询。
    • 返回:受影响的 x 行。
  4. alter_table
    • 修改 Postgres 服务器中现有的表。LLM 被告知不要删除现有的表或列。
    • 参数:
      • query :用于修改表的 SQL 查询。
    • 返回:受影响的 x 行。
  5. desc_table
    • 描述表的结构。
    • 参数:
      • name :要描述的表的名称。
    • 返回:表的结构。

数据工具

  1. read_query
    • 执行只读 SQL 查询。
    • 参数:
      • query :要执行的 SQL 查询。
    • 返回:查询的结果。
  2. write_query
    • 执行写入 SQL 查询。
    • 参数:
      • query :要执行的 SQL 查询。
    • 返回:受影响的 x 行,最后插入 ID:<last_insert_id>。
  3. update_query
    • 执行更新 SQL 查询。
    • 参数:
      • query :要执行的 SQL 查询。
    • 返回:受影响的 x 行。
  4. delete_query
    • 执行删除 SQL 查询。
    • 参数:
      • query :要执行的 SQL 查询。
    • 返回:受影响的 x 行。
  5. count_query
    • 查询某个表的行数..
    • 参数:
      • name :要计数的表的名称。
    • 返回:表的行号。

再次感谢https://github.com/Zhwt/go-mcp-mysql/

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

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 环境。

  1. 概述
    1. 安装
      1. 用法
        1. 方法 A:使用 stdio 模式的命令行参数
        2. 方法 B:使用 sse 模式的命令行参数
        3. 可选标志
      2. 工具
        1. 架构工具
        2. 数据工具
      3. 执照

        Related MCP Servers

        • A
          security
          A
          license
          A
          quality
          A 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 -
          3
          9
          36
          JavaScript
          Apache 2.0
        • -
          security
          F
          license
          -
          quality
          A 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
          • Linux
          • Apple
        • A
          security
          A
          license
          A
          quality
          A 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 -
          5
          65
          TypeScript
          MIT License
          • Apple
          • Linux
        • -
          security
          F
          license
          -
          quality
          A 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

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/guoling2008/go-mcp-postgres'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server