Skip to main content
Glama
GaussDB-MCP

GaussDB-MCP

by mengqi1436

GaussDB MCP

Huawei Cloud GaussDB cloud database MCP server. Built on Huawei's official GaussDB dedicated Node.js driver gaussdb-node, following the MCP 2026-07-28 specification, providing 24 tools and 1 table structure resource covering connection testing, querying, data writing, transactions, metadata, diagnostics and operations, user permissions, etc.

Quick Start

npm install
cp .env.example .env   # Windows: copy .env.example .env 后编辑
# 编辑 .env,填入 GaussDB 实例地址、密码等
npm run build
node build/index.js    # 启动(stdio,供 MCP 客户端拉起)

Requires Node.js ≥ 20.

Related MCP server: mcp-database

Connection Configuration

All Environment Variables

Variable

Required

Default

Description

GAUSSDB_HOST

Yes

—

GaussDB instance address; for primary/standby multi-node, separate with English commas (e.g. 10.0.0.1,10.0.0.2)

GAUSSDB_PORT

No

8000

Database port; Huawei Cloud GaussDB cloud instances default to 8000

GAUSSDB_DATABASE

No

postgres

Database name

GAUSSDB_USER

No

root

Login user; default administrator is root

GAUSSDB_PASSWORD

Yes

—

Login password

GAUSSDB_SEARCH_PATH

No

—

Default schema, corresponding to JDBC's currentSchema (delivered via connection options as the search_path GUC, e.g. gycwd)

GAUSSDB_MASTER_ONLY

No

0

For primary/standby multi-node, connect only to the primary node (corresponds to JDBC targetServerType=master, determined by pg_is_in_recovery())

GAUSSDB_SSL

No

0

Set to 1 to enable SSL encrypted connection

GAUSSDB_SSL_CA

No

—

CA root certificate path (download root.crt from Huawei Cloud console)

GAUSSDB_SSL_CERT

No

—

Client certificate path (only needed for mutual authentication)

GAUSSDB_SSL_KEY

No

—

Client private key path (only needed for mutual authentication)

GAUSSDB_SSL_REJECT_UNAUTHORIZED

No

true

Whether to verify the server certificate; can be set to false for debugging (insecure, testing only)

Intranet Connection Configuration

Used when the application and the GaussDB instance are in the same VPC. SSL is not required (intranet traffic does not leak externally; Huawei Cloud officially defaults to direct intranet connection):

GAUSSDB_HOST=10.0.1.11              # 实例"节点列表"中的内网地址
GAUSSDB_PORT=8000
GAUSSDB_DATABASE=postgres
GAUSSDB_USER=root
GAUSSDB_PASSWORD=你的密码
# 不设置任何 GAUSSDB_SSL_* 变量,保持 GAUSSDB_SSL=0(默认)

Public Network Connection Configuration

Used when the application is not in the instance's VPC and accesses it via an elastic public IP. SSL must be enabled and a CA certificate configured (Huawei Cloud official sslmode=verify-ca approach):

GAUSSDB_HOST=114.114.114.114        # 实例绑定的弹性公网 IP
GAUSSDB_PORT=8000
GAUSSDB_DATABASE=postgres
GAUSSDB_USER=root
GAUSSDB_PASSWORD=你的密码
GAUSSDB_SSL=1
GAUSSDB_SSL_CA=C:/path/to/root.crt   # 华为云控制台下载的 CA 证书(公网连接必需)
GAUSSDB_SSL_REJECT_UNAUTHORIZED=true

Before public network connection, you also need to allow the client's egress IP access to port 8000 in the Huawei Cloud console security group.

How to Add Environment Variables

Two methods, choose either one (when both exist, environment variables take precedence over .env):

  1. Project .env file (recommended): Copy .env.example to .env in the project root directory and fill it in. The .env location is anchored to the project root directory, independent of which directory the server is started from — the MCP client can read it when launching build/index.js from any working directory. Write either of the two configurations above directly into .env.

  2. MCP client env field: Pass environment variables directly in the mcpServers configuration (see integration examples below), suitable for scenarios where you don't want to put credential files in the project.

For primary/standby deployments, separate multiple node IPs in GAUSSDB_HOST with English commas. The server tries connecting to each in sequence at startup and automatically selects the first available node.

Tool Overview (24 tools)

All tools are annotated with annotations (readOnlyHint/destructiveHint) per the MCP specification, allowing clients to prompt for confirmation on write operations.

Connection and Status

Tool

Description

test_connection

Test connection, returns GaussDB version, current database, current user

Query and Write

Tool

Description

query

Execute read-only queries (starting with SELECT/WITH/EXPLAIN/SHOW/VALUES, single statement; write statements and multi-statements are rejected), truncated by limit (default 100)/offset, optional tx_handle

execute

Execute arbitrary SQL (DDL/DML), returns affected row count, optional tx_handle

insert_rows

Parameterized batch insert (table name + row array, optional schema)

update_rows

Parameterized update (set + where, where is required to prevent accidental full-table updates, optional schema)

delete_rows

Parameterized delete (where is required to prevent accidental full-table deletes, optional schema, destructive annotation)

Transactions (explicit handle mode)

Tool

Description

transaction_begin

Begin a transaction, returns tx_handle (auto-rollback and reclamation after 5 minutes idle)

transaction_commit

Commit the transaction

transaction_rollback

Roll back the transaction

Usage: transaction_begin → multiple query/execute (passing the same tx_handle) → transaction_commit or transaction_rollback.

Metadata (read-only)

Tool

Description

list_databases / list_schemas / list_tables

Database / schema / table lists

describe_table

Column definitions: type, length, nullable, default, primary key

list_indexes / list_views / list_sequences

Index / view / sequence lists

Diagnostics and Operations (read-only)

Tool

Description

explain_query

Execution plan; with analyze=true actually executes and collects statistics (auto transaction rollback, write statements not persisted); rejects multi-statements containing semicolons

list_sessions

Current active sessions

list_lock_conflicts

Lock conflicts (blocked party and blocking source)

database_stats

Version, database size, connection count, server address and time

Users and Permissions

Tool

Description

list_users

User list (read-only)

create_user

Create a login-enabled user

grant_privilege / revoke_privilege

Grant / revoke (e.g. ALL ON DATABASE d)

Resources

Resource URI

Description

gaussdb://{schema}/{table}/schema

Read table structure as JSON

MCP Client Integration

After building, register in the client configuration file (using Claude Desktop / Cursor's mcpServers format as an example). Windows uses double backslash paths (E:\\MCP\\GaussDBMCP\\build\\index.js), Linux/macOS uses forward slashes (/home/user/GaussDBMCP/build/index.js).

Intranet Connection Integration

{
  "mcpServers": {
    "gaussdb": {
      "command": "node",
      "args": ["E:\\MCP\\GaussDBMCP\\build\\index.js"],
      "env": {
        "GAUSSDB_HOST": "10.0.1.11",
        "GAUSSDB_PORT": "8000",
        "GAUSSDB_DATABASE": "postgres",
        "GAUSSDB_USER": "root",
        "GAUSSDB_PASSWORD": "你的密码"
      }
    }
  }
}

Intranet connection does not require SSL; simply do not set any GAUSSDB_SSL_* variables.

Public Network Connection Integration

{
  "mcpServers": {
    "gaussdb": {
      "command": "node",
      "args": ["E:\\MCP\\GaussDBMCP\\build\\index.js"],
      "env": {
        "GAUSSDB_HOST": "114.114.114.114",
        "GAUSSDB_PORT": "8000",
        "GAUSSDB_DATABASE": "postgres",
        "GAUSSDB_USER": "root",
        "GAUSSDB_PASSWORD": "你的密码",
        "GAUSSDB_SSL": "1",
        "GAUSSDB_SSL_CA": "C:\\path\\to\\root.crt",
        "GAUSSDB_SSL_REJECT_UNAUTHORIZED": "true"
      }
    }
  }
}

Public network connection must enable SSL and configure a CA certificate, and ensure the security group allows the client's egress IP access to port 8000.

You can also omit env and rely on the .env file in the project root directory (automatically read at server startup, anchored to the project root, independent of the startup directory).

Multi-Tenant Isolation (stream = schema)

GAUSSDB_SEARCH_PATH also serves as the MCP-layer schema whitelist: once configured, access is restricted to the corresponding stream's own schema, and tables of other streams cannot be seen.

MCP-layer interception (reliable, based on structural parameters):

  • list_schemas only returns schemas in the whitelist, not leaking other schema names

  • list_tables/list_indexes/list_views/list_sequences default to pinning to the first whitelisted schema when no schema is passed, no longer returning all database tables

  • describe_table/insert_rows/update_rows/delete_rows with an explicit schema parameter will directly error and reject if it is not in the whitelist

  • The table structure resource gaussdb://{schema}/{table}/schema is also subject to the whitelist; cross-schema reads are rejected

Database permission-layer fallback (required, cannot be omitted): execute accepts arbitrary SQL, and the MCP layer does not parse SQL (a hand-written parser will always have bypass paths); although query enforces read-only (first-keyword whitelist + write-keyword blacklist + rejection of multi-statements), side-effect functions in SELECT form (such as pg_terminate_backend, setval) cannot be exhaustively intercepted. Cross-schema access and side-effect functions are guaranteed by GaussDB permissions. Each stream uses an independent restricted account, authorized only for its own schema:

-- 以管理员执行:为 stream 建受限账号,只授予自己 schema 的权限
CREATE USER gycwd_app WITH PASSWORD 'xxx' LOGIN;
REVOKE ALL ON DATABASE postgres FROM PUBLIC;            -- 收紧库级默认权限
GRANT CONNECT ON DATABASE postgres TO gycwd_app;
GRANT USAGE ON SCHEMA gycwd TO gycwd_app;               -- 只给自己的 schema
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA gycwd TO gycwd_app;
-- 该账号未授予其他 schema 的 USAGE,即使手写跨 schema SQL 也会被数据库拒绝

Then in .env set GAUSSDB_USER=gycwd_app, GAUSSDB_SEARCH_PATH=gycwd, with two layers combined: structural entry points intercepted by MCP, arbitrary SQL intercepted by the database.

Security Notes

  • stdio server logs are all written to stderr; stdout only carries MCP messages

  • Identifiers such as table names/column names/user names in structured tools (insert_rows/update_rows/delete_rows, etc.) are all character-validated, and values always use parameterized placeholders to prevent SQL injection; query/explain_query are free-form SQL entry points, narrowed down by read-only validation and single-statement restrictions (see above)

  • delete_rows/update_rows enforce a where condition

  • explain_query with analyze=true actually executes the statement, only allowing statements starting with SELECT/WITH and automatically wrapping in a transaction rollback (sequence advancement and function side effects are not rollback-able)

  • Statements such as DROP/TRUNCATE can be executed via execute; clients should rely on the destructiveHint annotation for confirmation

  • Do not commit .env to version control

Development and Build

npm run build   # tsc 编译到 build/

Source structure: src/config.ts (configuration), src/db.ts (connection pool and transaction handles), src/sql.ts (SQL construction and read-only validation), src/format.ts (result formatting), src/index.ts (MCP server and tool registration).

Once you have a real GaussDB instance: fill in .env → npm run build → node build/index.js and test with any MCP client; or first verify the connection separately: configure env and run the test_connection tool.

Available Tools

24 tools
create_userB

创建可登录的数据库用户

Inputs: password (required), username (required).

database_statsA
Read-only

查看数据库统计:版本、大小、连接数、当前用户、服务器地址与时间

Inputs: no named parameters.

delete_rowsA
DestructiveIdempotent

参数化删除:指定表名与 WHERE(列→值,AND 连接,必填防全表误删除),可选 schema

Inputs: table (required), where (required), schema.

describe_tableA
Read-only

查看表结构:列名、数据类型、长度、可空、默认值、是否主键

Inputs: table (required), schema.

executeB
DestructiveIdempotent

执行任意 SQL(INSERT/UPDATE/DELETE/DDL 等),返回受影响行数。可选 tx_handle 在事务内执行。危险操作(DROP/TRUNCATE/DELETE)请谨慎

Inputs: sql (required), tx_handle.

explain_queryA
Read-only

查看 SQL 执行计划。analyze=true 时真实执行并统计耗时(自动包裹事务回滚,写语句不落盘)

Inputs: sql (required), analyze.

grant_privilegeB

授予权限。privilege 示例:SELECT ON TABLE t、ALL PRIVILEGES ON DATABASE d、USAGE ON SCHEMA s

Inputs: grantee (required), privilege (required).

insert_rowsA

参数化批量插入:指定表名与行数组(对象数组,键为列名),可选 schema(缺省 public)

Inputs: rows (required), table (required), schema.

list_databasesA
Read-only

列出 GaussDB 实例中所有可连接的数据库及大小

Inputs: no named parameters.

list_indexesA
Read-only

列出索引及所属表,可选按 schema 过滤

Inputs: schema.

list_lock_conflictsA
Read-only

查看当前锁冲突:被阻塞会话与阻塞来源

Inputs: no named parameters.

list_schemasA
Read-only

列出当前数据库的所有 schema(排除系统 schema);配置白名单后仅列出允许的 schema

Inputs: no named parameters.

list_sequencesB
Read-only

列出序列,可选按 schema 过滤

Inputs: schema.

list_sessionsB
Read-only

查看当前活跃会话(pg_stat_activity)

Inputs: no named parameters.

list_tablesA
Read-only

列出当前数据库的所有表及大小,可选按 schema 过滤

Inputs: schema.

list_usersA
Read-only

列出数据库用户及属性

Inputs: no named parameters.

list_viewsA
Read-only

列出视图,可选按 schema 过滤

Inputs: schema.

queryA
Read-only

在 GaussDB 上执行只读查询(SELECT/WITH/EXPLAIN/SHOW/VALUES 开头,单语句,写语句会被拒绝)并返回结果行。支持 limit/offset 截断返回(不修改 SQL 本身),可选 tx_handle 在事务内执行

Inputs: sql (required), limit, offset, tx_handle. Returns: rows, rowCount, truncated

revoke_privilegeC
DestructiveIdempotent

回收权限。privilege 格式同 grant_privilege

Inputs: grantee (required), privilege (required).

test_connectionA
Read-only

测试 GaussDB 连接,返回数据库版本、当前库、当前用户与服务器时间

Inputs: no named parameters.

transaction_beginA

开启 GaussDB 事务,返回事务句柄 tx_handle。后续 query/execute/写入工具可传入该句柄在同一事务内执行。空闲 5 分钟自动回滚回收

Inputs: no named parameters.

transaction_commitA

提交事务。需提供 transaction_begin 返回的句柄

Inputs: tx_handle (required).

transaction_rollbackB
DestructiveIdempotent

回滚事务。需提供 transaction_begin 返回的句柄

Inputs: tx_handle (required).

update_rowsA

参数化更新:指定表名、SET(列→新值)与 WHERE(列→值,AND 连接,必填防全表误更新),可选 schema

Inputs: set (required), table (required), where (required), schema.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 24 tools

    Disambiguation4/5

    大部分工具以资源类型清晰区分,list_*、query/execute、insert/update/delete_rows、事务三件套等边界明确。但 test_connection 与 database_stats 在返回版本、当前用户、时间等信息上存在重叠,可能造成轻微混淆。

    Naming Consistency4/5

    整体采用蛇形命名,且以动词开头为主,如 list_tables、create_user、grant_privilege、delete_rows。但 database_stats、query、execute、transaction_begin 等少量工具偏离 verb_noun 模式,存在轻微不一致。

    Tool Count3/5

    24 个工具落在 16-25 的偏重区间,虽然每个工具都有明确用途,但元数据浏览、写操作、事务控制、权限管理等维度拆分较细,整体数量感觉偏多,仍有合并空间。

    Completeness4/5

    覆盖了查询、写入、批量操作、事务、权限、元数据与监控,核心数据库操作较为完整。但用户管理仅有 create_user 而无 alter/drop_user,表级 DDL 也主要依赖通用 execute,存在可通过 execute 弥补的轻微生命周期缺口。

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      MCP server for connecting to databases (PostgreSQL, MySQL, SQL Server, Redis) enabling SQL queries, table exploration, and Redis key-value operations.
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      MCP server for multiple databases (PostgreSQL, MySQL, MariaDB, SQLite, MongoDB, Redis) with tools for schema inspection, querying, performance diagnostics, and safe write operations, featuring access modes, PII masking, and audit logging.
      Apache 2.0
    • A
      license
      A
      quality
      C
      maintenance
      A comprehensive PostgreSQL MCP server providing 27 tools for database management and administration, including connection management, query execution, schema introspection, CRUD operations, and server monitoring.
      27
      38 npm
      AGPL 3.0
    • A
      license
      A
      quality
      C
      maintenance
      A multi-database MCP server that supports MySQL, GaussDB, Oracle, and DM8, providing a unified interface for executing queries, data manipulation, and schema inspection via natural language.
      5
      1
      MIT