dynamic-db-mcp-server
This server is an MCP (Model Context Protocol) server that lets AI agents dynamically register and query MySQL-compatible databases at runtime, with built-in SQL safety controls.
Dynamic Connection Registration – Register new database instances (host/port/user/password) at runtime without preconfiguration; connections are tested and cached.
Connection Management – List all registered instances (without passwords), and connections are reused and auto-reconnect on ping failure.
SQL Execution with Safety Classification – Execute SQL with automatic classification:
Read-only (SELECT, SHOW, WITH, EXPLAIN, DESC) executes directly.
Destructive (DROP, DELETE, UPDATE, INSERT, ALTER, TRUNCATE, etc.) requires explicit
confirm_destructive=true.Dangerous (OUTFILE, DUMPFILE, LOAD_FILE, SHUTDOWN, KILL) is always rejected.
Database Exploration – List all databases on an instance.
Table Listing – List tables in a specific database, including row counts, sizes, engine, and comments.
Schema Inspection – Get detailed column information and
SHOW CREATE TABLEDDL for any table.Compatibility – Works with any MySQL wire-protocol database (MySQL, MariaDB, TDSQL, TDSQL-C).
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@dynamic-db-mcp-server Register instance demo-db on host 192.168.1.100 port 3306"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
dynamic-db-mcp-server
动态注册的 MySQL 兼容数据库 MCP Server. 运行时注册数据库连接, 执行 SQL 时自带破坏性语句拦截.
为什么造这个轮子
传统的数据库 MCP Server 要求把所有连接配置事先写进环境变量或配置文件. 这在以下场景不现实:
有几十/上百个数据库实例
实例 IP 经常变动
不想维护一份静态配置文件
需要 AI 动态发现并连接数据库
dynamic-db-mcp-server 翻转了模型: 连接在运行时通过工具调用注册. AI 提供 host/port/user/password, Server 测试连接, 缓存它, 返回 instance_id 供后续查询使用.
Related MCP server: MySQL MCP Server
特性
动态注册 — 无需预配置连接列表, 运行时注册任意 MySQL 兼容数据库
连接复用 — 注册的连接会被缓存, 不重复握手
SQL 安全 — 只读查询 (SELECT/SHOW/WITH/EXPLAIN/DESC) 直接执行; 破坏性语句 (DROP/DELETE/UPDATE/INSERT/ALTER/TRUNCATE) 需显式确认; 危险语句 (OUTFILE/DUMPFILE/LOAD_FILE/SHUTDOWN) 一律拒绝
MySQL 协议兼容 — 适用于 MySQL, MariaDB, TDSQL, TDSQL-C 等任何使用 MySQL 线协议的数据库
配置无敏感数据 — 无硬编码凭据, 所有连接均为运行时提供
无状态 — 连接存在于 MCP 进程内存中, 重启即清空
快速开始
安装
pip install dynamic-db-mcp-server或通过 uv / uvx 运行:
uvx dynamic-db-mcp-server在 MCP 客户端中配置
在你的 MCP 客户端配置中添加 (如 opencode.jsonc, claude_desktop_config.json):
{
"mcpServers": {
"dynamic-db": {
"command": "uvx",
"args": ["dynamic-db-mcp-server"]
}
}
}或从源码运行:
{
"mcpServers": {
"dynamic-db": {
"command": "python",
"args": ["-m", "dynamic_db_mcp_server"]
}
}
}使用流程
1. register_instance(name="my-db", host="10.0.0.5", port=3306, user="root", password="***")
→ {"instance_id": "my-db", "status": "connected"}
→ 连接已测试并缓存
2. list_instances()
→ [{"instance_id": "my-db", "host": "10.0.0.5", "port": 3306, "user": "root", "status": "connected"}]
3. execute_sql(instance_id="my-db", sql="SELECT 1")
→ {"columns": ["1"], "rows": [[1]], "row_count": 1}
4. execute_sql(instance_id="my-db", sql="DROP TABLE temp_test")
→ {"error": "Destructive operation requires confirmation", "sql_type": "DESTRUCTIVE", "statement": "DROP"}
5. execute_sql(instance_id="my-db", sql="DROP TABLE temp_test", confirm_destructive=true)
→ {"affected_rows": 0}工具列表
工具 | 说明 |
| 注册数据库连接 (用 |
| 列出所有已注册实例 (不返回密码) |
| 执行 SQL. 只读直接通过, 破坏性需 |
| 列出实例上的所有数据库 |
| 列出指定库的表 (含行数和大小) |
| 查看表结构 (列信息 + |
SQL 安全策略
类别 | 关键字 | 行为 |
只读 | SELECT, SHOW, WITH, EXPLAIN, DESC, DESCRIBE | 直接执行 |
破坏性 | DROP, TRUNCATE, DELETE, UPDATE, INSERT, ALTER, RENAME, GRANT, REVOKE, CREATE | 需 |
危险 | OUTFILE, DUMPFILE, LOAD_FILE, SHUTDOWN, KILL | 一律拒绝 |
架构
AI Agent
│
│ MCP 协议 (stdio)
▼
┌──────────────────────────────────────┐
│ dynamic-db-mcp-server │
│ │
│ FastMCP Server ──→ 6 个工具 │
│ │ │
│ ConnectionManager │
│ - register / get / list │
│ - ping + 自动重连 │
│ - per-instance threading.Lock │
│ │ │
│ SqlValidator │
│ - 关键字分类 │
│ - 只读 / 破坏性 / 危险 │
│ │ │
│ DbExecutor (pymysql) │
│ - execute / list / schema │
└──────────────────────────────────────┘
│
│ TCP 3306
▼
MySQL / MariaDB / TDSQL / TDSQL-CLicense
MIT
Link
Available Tools
6 toolsexecute_sqlA
Execute a SQL statement on a registered instance.
SQL is classified before execution:
Read-only (SELECT/SHOW/WITH/EXPLAIN/DESC): executes directly.
Destructive (DROP/DELETE/UPDATE/INSERT/ALTER/TRUNCATE/CREATE/...): requires confirm_destructive=true.
Blocked (OUTFILE/DUMPFILE/LOAD_FILE/SHUTDOWN/KILL): always rejected.
Args: instance_id: The instance name from register_instance. sql: The SQL statement to execute. database: Optional database to switch to before executing. confirm_destructive: Set to true to allow destructive operations.
Returns: JSON string with query results (columns/rows/row_count) or affected_rows for DML, or error/safety rejection details.
Inputs: sql (required), instance_id (required), database, confirm_destructive. Returns: result
get_table_detailA
Get column info and CREATE TABLE DDL for a specific table.
Args: instance_id: The instance name from register_instance. database: The database name. table_name: The table name.
Returns: JSON with {columns: [...], ddl: "..."}, or error details.
Inputs: database (required), table_name (required), instance_id (required). Returns: result
list_databasesA
List all databases on a registered instance.
Args: instance_id: The instance name from register_instance.
Returns: JSON array of database names, or error details.
Inputs: instance_id (required). Returns: result
list_instancesA
List all registered database instances.
Returns: JSON array of instances. Passwords are never included.
Inputs: no named parameters. Returns: result
list_tablesA
List tables in a database with row count and size.
Args: instance_id: The instance name from register_instance. database: The database name to list tables from.
Returns: JSON array of {table, rows, size_mb, engine, comment}, or error.
Inputs: database (required), instance_id (required). Returns: result
register_instanceA
Register a MySQL-compatible database connection at runtime.
Tests the connection with SELECT 1 before caching. If a connection with the same name already exists, it is closed and replaced.
Args: name: A human-readable identifier for this instance (used as instance_id). host: Database host or IP address. port: Database port (e.g. 3306). user: Database username. password: Database password. database: Optional default database/schema. charset: Connection charset, defaults to utf8mb4.
Returns: JSON string with instance_id and status, or error details.
Inputs: host (required), name (required), port (required), user (required), +3 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a distinct and non-overlapping purpose: registering instances, listing instances, listing databases, listing tables, getting table details, and executing SQL. No ambiguity between tools.
All tools follow a consistent verb_noun pattern with snake_case (e.g., execute_sql, get_table_detail, list_databases). No mixing of conventions.
With 6 tools, the server is well-scoped for managing and querying MySQL databases. It covers essential operations without being bloated or too sparse.
The tool set covers core discovery and query workflows, and destructive operations are possible via execute_sql with confirmation. Minor gaps include no dedicated unregister/update instance tool and no separate create/drop database/table tools, but these are manageable.
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Guard AI agents' PostgreSQL/MySQL access via MCP: SQL audit, auth, masking, write approval
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely connect to and manage MySQL databases with support for multiple database connections, complete CRUD operations, schema inspection, and dynamic connection management through natural language.31 npm81MIT
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to securely interact with MySQL databases through tools for query execution, schema inspection, and transaction management. It features built-in safety controls like row limits and query validation to ensure safe and standardized database access.798 npm-
- AlicenseAqualityDmaintenanceEnables AI agents to safely interact with MySQL/MariaDB databases, supporting read-only queries by default with optional write operations and access control.8MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with a MySQL database using natural language, automating SQL tasks like querying, inserting, updating, and deleting data.1-