@connect_workbench/mcp-core
v0.1.0
Published
Framework-agnostic multi-database core: config, SQL parsing, column type decoding, output formatting and MySQL runtime (no MCP dependency)
Readme
@connect_workbench/mcp-core
框架无关的多数据库核心(TypeScript),复刻 mysql-multi-mcp-rs 的核心逻辑。不依赖任何 MCP 协议库,可被 MCP 适配层或任意 TS 项目(如 VS Code 插件)复用。
能力
- 配置:多连接配置、
output_format(json / markdown / table)、cell_max_width、blocked_statements - SQL 解析与拦截:首 token 提取、跳过注释/括号、只读判定、
SHOW CREATE识别、黑名单拦截(默认DELETE / DROP / TRUNCATE) - 类型解码:
BIGINT→字符串、DECIMAL→字符串、DATETIME→YYYY-MM-DD HH:MM:SS、JSON→原生对象、BIT(1)→bool、BLOB→utf8/hex - 格式渲染:json(去 columns 冗余)/ markdown 管道表 / MySQL CLI 同款 ASCII 表,超长单元格截断 + 溢出补发
- 运行时:mysql2 懒加载连接池、参数化
execute、元数据查询(listDatabases/listTables/describeTable)、参数化分页selectPage、配置热重载
安装
npm install @connect_workbench/mcp-core快速开始
import { createRuntime } from '@connect_workbench/mcp-core';
const runtime = createRuntime({
outputFormat: 'json',
connections: [
{ name: 'dev', host: '127.0.0.1', port: 3306, username: 'root', password: '***', database: 'app' },
],
});
// 自由 SQL(危险语句会被拦截)
const result = await runtime.execute('dev', 'SELECT * FROM users LIMIT 5', { format: 'markdown' });
console.log(result.contents); // ['| id | name |...']
// 参数化单表分页
const page = await runtime.selectPage('dev', 'app', 'users', 0, 50, {
filters: [{ field: 'status', operator: '=', value: 'active' }],
sort: { field: 'id', direction: 'desc' },
});
await runtime.close();配置
interface ConnectionConfig {
name: string; // 唯一标识(工具名后缀 / execute 目标)
description?: string; // 描述(用于 MCP 工具描述)
host: string;
port: number;
username: string;
password: string; // 明文密码:由调用方在初始化前完成解密
database?: string; // 连接默认库(可选)
blockedStatements?: string[]; // 默认 ['DELETE','DROP','TRUNCATE']
useSsl?: boolean; // 默认 true
}顶层 outputFormat(json / markdown / table)与 cellMaxWidth(默认 200)为全局默认,execute 可用 format 参数临时覆盖。
License
MIT
