db-mcp

db-mcp

MCP server for HighGo and MySQL databases, providing tools for querying, executing DDL, listing tables, and inspecting table structures.

Category
访问服务器

README

<div align="center"> <strong> <h1>db-mcp</h1> HighGo & MySQL database MCP server<br><br> Query · Execute · DDL · List tables · Inspect schema<br> Permission-controlled · stdio transport · Single-file build </strong> <br> <br>

GitHub Stars License 简体中文

</div>

db-mcp is a Model Context Protocol (MCP) server that exposes database operations for HighGo (瀚高) and MySQL databases as MCP tools. AI assistants such as OpenCode and Claude Code can query, modify, and inspect databases through a permission-controlled, stdio-based interface.

Features

  • Two database types: HighGo (PostgreSQL-compatible) and MySQL, selected via configuration
  • Five MCP tools: query, execute, DDL, list tables, and describe table
  • Fine-grained permissions: per-operation allowlist (SELECT / INSERT / UPDATE / DELETE / DDL)
  • Flexible configuration: environment variables or a JSON config file (env vars take precedence), with ${ENV_VAR} placeholder support in config files
  • Connection pooling: configurable pool size per connection
  • Single-file build: build:prod bundles everything into one self-contained dist/index.js — no node_modules needed at runtime

Requirements

  • Node.js >= 18

Quick Start

npm install
npm run build:prod

npm run build:prod runs tsc and then bundles the output with esbuild into a single file:

dist/
└── index.js    # self-contained, run directly with node

Note: npm run build (tsc only) also compiles to dist/, but that output still requires node_modules/ at runtime. Use build:prod for a portable single-file build.

Run the server (it speaks MCP over stdio, so it is normally launched by an MCP client, not run interactively):

node dist/index.js

Configuration

Two ways to configure a connection; environment variables take precedence over the config file.

Option 1: Environment variables

Variable Required Default Description
DB_HOST yes Database host
DB_DATABASE yes Database name
DB_USERNAME yes Username
DB_PASSWORD yes Password
DB_TYPE no highgo highgo or mysql
DB_PORT no 5866 / 3306 Auto-selected per type when omitted
DB_PERMISSIONS no all Comma-separated, e.g. SELECT,INSERT,DDL
DB_POOL_MAX no 10 Max pool size
DB_HOST=127.0.0.1 DB_PORT=5866 DB_DATABASE=mydb DB_USERNAME=admin DB_PASSWORD=xxx node dist/index.js

Option 2: Config file

The server loads ./db-mcp-config.mysql.example.json from the current working directory by default. Copy one of the examples from config/ and point DB_MCP_CONFIG at it:

# e.g. on Windows
set DB_MCP_CONFIG=D:\path\to\db-mcp\config\db-mcp-config.highgo.example.json
node dist/index.js

Or place a config file named db-mcp-config.mysql.example.json in the working directory (the default path).

Example config:

{
  "name": "highgo-dev",
  "type": "highgo",
  "host": "127.0.0.1",
  "port": 5866,
  "database": "your_database",
  "username": "your_username",
  "password": "your_password",
  "pool": { "max": 10 },
  "permissions": ["SELECT", "INSERT", "UPDATE", "DELETE", "DDL"]
}

Config file fields: name, type (highgo | mysql), host, port, database, username, password, pool.max, permissions. Values may reference environment variables with ${ENV_VAR} syntax, e.g. "password": "${DB_PASSWORD}".

⚠️ The config file contains database credentials — never commit real values to git. The shipped examples under config/ only contain placeholders.

Connecting an MCP Client

OpenCode

Add the server to the mcp field of opencode.json (project root) or your global config:

Via environment variables:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "db-mcp": {
      "type": "local",
      "command": ["node", "/path/to/db-mcp/dist/index.js"],
      "enabled": true,
      "environment": {
        "DB_TYPE": "highgo",
        "DB_HOST": "127.0.0.1",
        "DB_PORT": "5866",
        "DB_DATABASE": "your_database",
        "DB_USERNAME": "your_username",
        "DB_PASSWORD": "your_password",
        "DB_PERMISSIONS": "SELECT,INSERT,UPDATE,DELETE,DDL"
      }
    }
  }
}

Via config file:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "db-mcp": {
      "type": "local",
      "command": ["node", "/path/to/db-mcp/dist/index.js"],
      "enabled": true,
      "environment": {
        "DB_MCP_CONFIG": "/path/to/db-mcp/config/db-mcp-config.mysql.example.json"
      }
    }
  }
}

Or add it interactively with the CLI:

opencode mcp add

OpenCode walks you through the setup step by step:

  1. Run opencode mcp add — an interactive prompt opens.
  2. Select local as the server type.
  3. Give the server a name, e.g. db-mcp.
  4. Enter the command: node /path/to/db-mcp/dist/index.js.
  5. Add the environment variables when prompted (DB_TYPE, DB_HOST, ... or DB_MCP_CONFIG).
  6. Verify the server is connected with opencode mcp list.

If the server is slow to start up, raise the tool-fetch timeout with "timeout": 10000 (defaults to 5000 ms).

Codex

MCP servers are configured in ~/.codex/config.toml under the [mcp_servers] section. Add the server with the Codex CLI:

codex mcp add db-mcp --env DB_MCP_CONFIG=/path/to/db-mcp/config/db-mcp-config.mysql.example.json -- node /path/to/db-mcp/dist/index.js

Or edit ~/.codex/config.toml directly:

[mcp_servers.db-mcp]
command = "node"
args = ["/path/to/db-mcp/dist/index.js"]
enabled = true

[mcp_servers.db-mcp.env]
DB_MCP_CONFIG = "/path/to/db-mcp/config/db-mcp-config.mysql.example.json"

To connect via environment variables instead, list them in the env table (see Option 1).

Claude Code

Add the server with the Claude Code CLI (saved to ~/.claude/settings.json by default; pass --scope project to save it to .mcp.json in the project root instead):

claude mcp add -e DB_MCP_CONFIG=/path/to/db-mcp/config/db-mcp-config.mysql.example.json db-mcp -- node /path/to/db-mcp/dist/index.js

Or edit .mcp.json (project scope) or ~/.claude/settings.json (user scope) directly:

{
  "mcpServers": {
    "db-mcp": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/db-mcp/dist/index.js"],
      "env": {
        "DB_MCP_CONFIG": "/path/to/db-mcp/config/db-mcp-config.mysql.example.json"
      }
    }
  }
}

Tools

Tool Description Risk
db_query Execute a SELECT query; returns column names and data rows Read-only
db_execute Execute INSERT / UPDATE / DELETE; returns affected row count Write
db_ddl Execute DDL statements (CREATE / ALTER / DROP / indexes, etc.) Write
db_list_tables List all tables in the current database Read-only
db_describe_table Inspect a table's structure (columns, types, primary key, etc.) Read-only

Permission Control

Every connection carries a permissions allowlist. Requests are rejected with an error when the required permission is missing:

  • db_query / db_list_tables / db_describe_table require SELECT
  • db_execute checks the statement prefix and requires INSERT, UPDATE, or DELETE accordingly
  • db_ddl requires DDL

To restrict a connection, set DB_PERMISSIONS (comma-separated) or the permissions array in the config file. Restrictive example: SELECT,DDL allows reads and schema changes but no DML writes.

Project Structure

src/
├── index.ts                    # MCP server entry: tool registration + stdio transport
├── config.ts                   # config loading, permission checks, SQL validation
├── types.ts                    # shared types (ConnectionConfig, QueryResult, ...)
└── clients/
    ├── highgo-client.ts        # HighGo client implementation
    └── mysql-client.ts         # MySQL client implementation
config/
├── db-mcp-config.highgo.example.json
└── db-mcp-config.mysql.example.json
highgodb/                       # vendored HighGo database driver (based on pg), installed via file: dependency

Development

npm install
npm run dev        # watch mode via tsx (src/index.ts)
npm run build      # tsc compile only
npm run build:prod # tsc + esbuild single-file bundle

Security Notes

  • The server executes arbitrary SQL within the granted permissions — run it with the least-privileged database account your use case allows.
  • The MCP transport is stdio and does not enforce authentication on its own; control access to the machine/process that hosts it.
  • Read-only tools are marked with readOnlyHint so clients can route them accordingly, but enforcement happens through the permission allowlist.
  • Keep credentials out of version control (see the config section).

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选