@ty_krystal/sei-ai 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  独立的 SEI MCP 服务,使用 `@modelcontextprotocol/sdk` 运行。
4
4
  支持 `stdio`、`streamable-http` 和开发者 CLI 启动,默认只开放受控的低代码查询、保存和字段元数据工具,`querySql` 默认关闭。
5
- 构建改为使用 Vite 进行 Node 侧打包,产物输出到 `dist/`。
5
+ CLI 已迁移到 `oclif`,命令面改为顶层子命令。
6
6
 
7
7
  ## 安装
8
8
 
@@ -26,30 +26,28 @@ pnpm -F sei-ai-mcp run test
26
26
  sei-ai help
27
27
  sei-ai stdio --config ./config.example.json
28
28
  sei-ai streamable-http --host 0.0.0.0 --port 3000 --path /mcp --config ./config.example.json
29
- sei-ai cli api-docs --format markdown
30
- sei-ai cli query-sql "SELECT _UID,_NAME FROM _SYS_USER"
31
- sei-ai cli call POST /api/sei/data/removeAllCache --json '{}'
29
+ sei-ai api-docs --format markdown
30
+ sei-ai relogin
31
+ sei-ai query-sql "SELECT _UID,_NAME FROM _SYS_USER"
32
+ sei-ai call POST /api/sei/data/removeAllCache --json '{}'
33
+ sei-ai dict:list --type status
34
+ sei-ai dict:add-category sex 性别
35
+ sei-ai dict:add-item sex male 男
36
+ sei-ai init:base-data --sysid sys --admin-uid admin
32
37
  ```
33
38
 
34
39
  ## 开发者 CLI
35
40
 
36
41
  CLI 是新增的开发者命令面,不会改变现有 MCP server 的启动方式、tool 列表或 Host 集成配置。
37
42
 
38
- 首版支持:
39
-
40
- - `call`
41
- - `query`
42
- - `save`
43
- - `query-sql`
44
- - `api-docs`
45
-
46
43
  命令示例:
47
44
 
48
45
  ```bash
49
- sei-ai cli query --json '{"head":{"module":"sys_user"},"option":{"fields":"_UID,_NAME"}}'
50
- sei-ai cli save --json '{"head":{"module":"sys_user"},"data":[{"action":"edit","rows":[{"keyVal":"admin","row":{"_NAME":"管理员"}}]}]}'
51
- sei-ai cli query-sql "SELECT _UID,_NAME FROM _SYS_USER" --page 1 --size 20
52
- sei-ai cli api-docs --keyword login --format json
46
+ sei-ai query --json '{"head":{"module":"sys_user"},"option":{"fields":"_UID,_NAME"}}'
47
+ sei-ai save --json '{"head":{"module":"sys_user"},"data":[{"action":"edit","rows":[{"keyVal":"admin","row":{"_NAME":"管理员"}}]}]}'
48
+ sei-ai query-sql "SELECT _UID,_NAME FROM _SYS_USER" --page 1 --size 20
49
+ sei-ai api-docs --keyword login --format json
50
+ sei-ai relogin --role admin
53
51
  ```
54
52
 
55
53
  常用认证参数:
@@ -76,12 +74,21 @@ sei-ai cli api-docs --keyword login --format json
76
74
  - `--file ./payload.json`
77
75
  - `--stdin`
78
76
 
79
- 当前仍未覆盖:
77
+ 当前命令面:
80
78
 
81
- - `init-base-data`
82
- - 字典相关命令
83
- - DDL/DML
84
- - 文件上传下载
79
+ - `stdio`
80
+ - `streamable-http`
81
+ - `query`
82
+ - `save`
83
+ - `call`
84
+ - `query-sql`
85
+ - `sql`
86
+ - `api-docs`
87
+ - `relogin`
88
+ - `dict:list`
89
+ - `dict:add-category`
90
+ - `dict:add-item`
91
+ - `init:base-data`
85
92
 
86
93
  HTTP 模式:
87
94
 
package/dist/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  独立的 SEI MCP 服务,使用 `@modelcontextprotocol/sdk` 运行。
4
4
  支持 `stdio`、`streamable-http` 和开发者 CLI 启动,默认只开放受控的低代码查询、保存和字段元数据工具,`querySql` 默认关闭。
5
- 构建改为使用 Vite 进行 Node 侧打包,产物输出到 `dist/`。
5
+ CLI 已迁移到 `oclif`,命令面改为顶层子命令。
6
6
 
7
7
  ## 安装
8
8
 
@@ -26,30 +26,28 @@ pnpm -F sei-ai-mcp run test
26
26
  sei-ai help
27
27
  sei-ai stdio --config ./config.example.json
28
28
  sei-ai streamable-http --host 0.0.0.0 --port 3000 --path /mcp --config ./config.example.json
29
- sei-ai cli api-docs --format markdown
30
- sei-ai cli query-sql "SELECT _UID,_NAME FROM _SYS_USER"
31
- sei-ai cli call POST /api/sei/data/removeAllCache --json '{}'
29
+ sei-ai api-docs --format markdown
30
+ sei-ai relogin
31
+ sei-ai query-sql "SELECT _UID,_NAME FROM _SYS_USER"
32
+ sei-ai call POST /api/sei/data/removeAllCache --json '{}'
33
+ sei-ai dict:list --type status
34
+ sei-ai dict:add-category sex 性别
35
+ sei-ai dict:add-item sex male 男
36
+ sei-ai init:base-data --sysid sys --admin-uid admin
32
37
  ```
33
38
 
34
39
  ## 开发者 CLI
35
40
 
36
41
  CLI 是新增的开发者命令面,不会改变现有 MCP server 的启动方式、tool 列表或 Host 集成配置。
37
42
 
38
- 首版支持:
39
-
40
- - `call`
41
- - `query`
42
- - `save`
43
- - `query-sql`
44
- - `api-docs`
45
-
46
43
  命令示例:
47
44
 
48
45
  ```bash
49
- sei-ai cli query --json '{"head":{"module":"sys_user"},"option":{"fields":"_UID,_NAME"}}'
50
- sei-ai cli save --json '{"head":{"module":"sys_user"},"data":[{"action":"edit","rows":[{"keyVal":"admin","row":{"_NAME":"管理员"}}]}]}'
51
- sei-ai cli query-sql "SELECT _UID,_NAME FROM _SYS_USER" --page 1 --size 20
52
- sei-ai cli api-docs --keyword login --format json
46
+ sei-ai query --json '{"head":{"module":"sys_user"},"option":{"fields":"_UID,_NAME"}}'
47
+ sei-ai save --json '{"head":{"module":"sys_user"},"data":[{"action":"edit","rows":[{"keyVal":"admin","row":{"_NAME":"管理员"}}]}]}'
48
+ sei-ai query-sql "SELECT _UID,_NAME FROM _SYS_USER" --page 1 --size 20
49
+ sei-ai api-docs --keyword login --format json
50
+ sei-ai relogin --role admin
53
51
  ```
54
52
 
55
53
  常用认证参数:
@@ -76,12 +74,21 @@ sei-ai cli api-docs --keyword login --format json
76
74
  - `--file ./payload.json`
77
75
  - `--stdin`
78
76
 
79
- 当前仍未覆盖:
77
+ 当前命令面:
80
78
 
81
- - `init-base-data`
82
- - 字典相关命令
83
- - DDL/DML
84
- - 文件上传下载
79
+ - `stdio`
80
+ - `streamable-http`
81
+ - `query`
82
+ - `save`
83
+ - `call`
84
+ - `query-sql`
85
+ - `sql`
86
+ - `api-docs`
87
+ - `relogin`
88
+ - `dict:list`
89
+ - `dict:add-category`
90
+ - `dict:add-item`
91
+ - `init:base-data`
85
92
 
86
93
  HTTP 模式:
87
94
 
@@ -0,0 +1,157 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { BASE_SEED_DEFAULT_ADMIN_ROLE, BASE_SEED_DEFAULT_ADMIN_UID } from './constants.js';
4
+ import { formatCliError, SeiMcpError } from './errors.js';
5
+ import { buildBaseSeedSqlVars, buildDictCategoryRow, buildDictItemRow, buildDictQueryPayload, buildDictSavePayload, buildDictTree, removeSqlCommentLines, renderBaseSeedSql, splitSqlStatements, } from './cli-helpers.js';
6
+ import { buildOpenApiDocSummary, renderOpenApiMarkdown } from './openapi.js';
7
+ export async function runApiDocs(options) {
8
+ const raw = await options.client.readApiDocs();
9
+ const summary = buildOpenApiDocSummary(raw, options.keyword);
10
+ const output = options.format === 'json' ? `${JSON.stringify(summary, null, 2)}\n` : renderOpenApiMarkdown(summary);
11
+ await writeOutput(options.outputPath, output);
12
+ }
13
+ export async function runRelogin(options) {
14
+ const token = await options.client.relogin();
15
+ printJson({
16
+ success: true,
17
+ code: 1,
18
+ message: '重新登录成功',
19
+ data: { token },
20
+ });
21
+ }
22
+ export async function runCall(options) {
23
+ const response = await options.client.call(options.method, options.path, options.payload, {
24
+ allowFailure: options.allowFailure,
25
+ allowEmpty: options.allowEmpty,
26
+ skipAuth: options.skipAuth,
27
+ });
28
+ printJson(response);
29
+ }
30
+ export async function runQuery(options) {
31
+ const response = await options.client.query(options.payload, {
32
+ allowFailure: options.allowFailure,
33
+ });
34
+ printJson(response);
35
+ }
36
+ export async function runSave(options) {
37
+ const response = await options.client.save(options.payload, {
38
+ allowFailure: options.allowFailure,
39
+ });
40
+ printJson(response);
41
+ }
42
+ export async function runQuerySql(options) {
43
+ const response = await options.client.querySql(options.sql, options.page, options.size, {
44
+ allowFailure: options.allowFailure,
45
+ });
46
+ printJson(response);
47
+ }
48
+ export async function runDictList(options) {
49
+ const payload = buildDictQueryPayload(options.typeCode, options.keyword, options.size ?? 1000);
50
+ const response = await options.client.query(payload, {
51
+ allowFailure: options.allowFailure,
52
+ });
53
+ if (!options.flat && isObject(response) && isObject(response.data) && Array.isArray(response.data.rows)) {
54
+ response.data.tree = buildDictTree(response.data.rows);
55
+ }
56
+ printJson(response);
57
+ }
58
+ export async function runDictAddCategory(options) {
59
+ const payload = buildDictSavePayload(buildDictCategoryRow({
60
+ body: stringOrUndefined(options.rowOptions?.body),
61
+ code: stringOrUndefined(options.rowOptions?.code),
62
+ ctype: stringOrUndefined(options.rowOptions?.ctype),
63
+ dictFlag: numberOrUndefined(options.rowOptions?.dictFlag),
64
+ ename: stringOrUndefined(options.rowOptions?.ename),
65
+ memo: stringOrUndefined(options.rowOptions?.memo),
66
+ name: options.name,
67
+ sort: numberOrUndefined(options.rowOptions?.sort),
68
+ sysid: stringOrUndefined(options.rowOptions?.sysid),
69
+ typeCode: options.typeCode,
70
+ uuid: stringOrUndefined(options.rowOptions?.uuid),
71
+ }));
72
+ const response = await options.client.save(payload, {
73
+ allowFailure: options.allowFailure,
74
+ });
75
+ printJson(response);
76
+ }
77
+ export async function runDictAddItem(options) {
78
+ const payload = buildDictSavePayload(buildDictItemRow({
79
+ body: stringOrUndefined(options.rowOptions?.body),
80
+ code: options.code,
81
+ ctype: stringOrUndefined(options.rowOptions?.ctype),
82
+ dictFlag: numberOrUndefined(options.rowOptions?.dictFlag),
83
+ ename: stringOrUndefined(options.rowOptions?.ename),
84
+ memo: stringOrUndefined(options.rowOptions?.memo),
85
+ name: options.name,
86
+ parent: stringOrUndefined(options.rowOptions?.parent),
87
+ sort: numberOrUndefined(options.rowOptions?.sort),
88
+ sysid: stringOrUndefined(options.rowOptions?.sysid),
89
+ typeCode: options.typeCode,
90
+ uuid: stringOrUndefined(options.rowOptions?.uuid),
91
+ }));
92
+ const response = await options.client.save(payload, {
93
+ allowFailure: options.allowFailure,
94
+ });
95
+ printJson(response);
96
+ }
97
+ export async function runInitBaseData(options) {
98
+ const sqlFile = resolveBaseSeedSqlPath(options.sqlFile);
99
+ const template = await readFile(sqlFile, 'utf8');
100
+ const sql = renderBaseSeedSql(template, buildBaseSeedSqlVars({
101
+ adminName: options.adminName,
102
+ adminPassword: options.adminPassword,
103
+ adminRole: options.adminRole,
104
+ adminRoleName: options.adminRoleName,
105
+ adminUid: options.adminUid,
106
+ resetAdminPassword: options.resetAdminPassword,
107
+ sysid: options.sysid,
108
+ }));
109
+ const statements = splitSqlStatements(removeSqlCommentLines(sql));
110
+ if (statements.length === 0) {
111
+ throw new SeiMcpError('初始化 SQL 文件没有可执行语句', 'INVALID_PARAMS');
112
+ }
113
+ const executed = await options.client.executeDdlStatements(statements, {
114
+ allowFailure: options.allowFailure,
115
+ });
116
+ await options.client.call('POST', '/api/sei/data/removeAllCache', {}, { allowFailure: false }).catch(() => undefined);
117
+ printJson({
118
+ success: true,
119
+ code: 1,
120
+ message: '基础源数据初始化完成',
121
+ data: {
122
+ executed: Array.isArray(executed) ? executed.length : 0,
123
+ sqlFile,
124
+ admin: options.adminUid ?? BASE_SEED_DEFAULT_ADMIN_UID,
125
+ role: options.adminRole ?? BASE_SEED_DEFAULT_ADMIN_ROLE,
126
+ },
127
+ });
128
+ }
129
+ export async function writeOutput(path, text) {
130
+ if (!path) {
131
+ process.stdout.write(text);
132
+ return;
133
+ }
134
+ await writeFile(path, text, 'utf8');
135
+ process.stdout.write(`已写入:${path}\n`);
136
+ }
137
+ export function printJson(value) {
138
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
139
+ }
140
+ export function resolveBaseSeedSqlPath(path) {
141
+ if (path) {
142
+ return resolve(path);
143
+ }
144
+ return resolve(process.cwd(), '.codex/skills/sei-ai/scripts/init-base-data.sql');
145
+ }
146
+ export function formatActionError(error) {
147
+ return formatCliError(error);
148
+ }
149
+ function stringOrUndefined(value) {
150
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
151
+ }
152
+ function numberOrUndefined(value) {
153
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
154
+ }
155
+ function isObject(value) {
156
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
157
+ }
@@ -0,0 +1,246 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { BASE_SEED_DEFAULT_ADMIN_PASSWORD, BASE_SEED_DEFAULT_ADMIN_ROLE, BASE_SEED_DEFAULT_ADMIN_UID, BASE_SEED_DEFAULT_SYSID, DICT_DEFAULT_SYSID, DICT_FIELDS, DICT_MODULE, } from './constants.js';
3
+ import { SeiMcpError } from './errors.js';
4
+ export function buildDictQueryPayload(typeCode, keyword, size = 1000) {
5
+ return {
6
+ head: {
7
+ module: DICT_MODULE,
8
+ },
9
+ option: {
10
+ keyField: true,
11
+ privilege: true,
12
+ fields: DICT_FIELDS.join(','),
13
+ filter: buildDictQueryFilter(typeCode, keyword),
14
+ order: '_SORT ASC,_CODE ASC',
15
+ page: 1,
16
+ size,
17
+ },
18
+ };
19
+ }
20
+ export function buildDictSavePayload(row) {
21
+ return {
22
+ head: {
23
+ module: DICT_MODULE,
24
+ },
25
+ data: [
26
+ {
27
+ action: 'add',
28
+ option: {
29
+ keyVal: true,
30
+ },
31
+ rows: [
32
+ {
33
+ row,
34
+ },
35
+ ],
36
+ },
37
+ ],
38
+ };
39
+ }
40
+ export function buildDictCategoryRow(input) {
41
+ const typeCode = requiredText(input.typeCode, '字典类别');
42
+ const name = requiredText(input.name, '字典名称');
43
+ const uuid = requiredText(input.uuid || typeCode, '字典编号');
44
+ const code = requiredText(input.code || typeCode, '字典代码');
45
+ return {
46
+ _UUID: uuid,
47
+ _PID: '',
48
+ _SYSID: requiredText(input.sysid || DICT_DEFAULT_SYSID, '所属系统'),
49
+ _TYPE: typeCode,
50
+ _CTYPE: normalizeText(input.ctype),
51
+ _CODE: code,
52
+ _NAME: name,
53
+ _ENAME: normalizeText(input.ename),
54
+ _DICT: normalizeDictFlag(input.dictFlag),
55
+ _SORT: normalizeSort(input.sort),
56
+ _BODY: normalizeText(input.body),
57
+ _MEMO: normalizeText(input.memo),
58
+ };
59
+ }
60
+ export function buildDictItemRow(input) {
61
+ const typeCode = requiredText(input.typeCode, '字典类别');
62
+ const code = requiredText(input.code, '字典代码');
63
+ const name = requiredText(input.name, '字典名称');
64
+ const parent = requiredText(input.parent || typeCode, '父级编号');
65
+ const uuid = requiredText(input.uuid || `${parent}_${code}`, '字典编号');
66
+ return {
67
+ _UUID: uuid,
68
+ _PID: parent,
69
+ _SYSID: requiredText(input.sysid || DICT_DEFAULT_SYSID, '所属系统'),
70
+ _TYPE: typeCode,
71
+ _CTYPE: normalizeText(input.ctype),
72
+ _CODE: code,
73
+ _NAME: name,
74
+ _ENAME: normalizeText(input.ename),
75
+ _DICT: normalizeDictFlag(input.dictFlag),
76
+ _SORT: normalizeSort(input.sort),
77
+ _BODY: normalizeText(input.body),
78
+ _MEMO: normalizeText(input.memo),
79
+ };
80
+ }
81
+ export function buildDictTree(rows) {
82
+ if (!Array.isArray(rows)) {
83
+ return [];
84
+ }
85
+ const recordMap = new Map();
86
+ const childrenMap = new Map();
87
+ const roots = [];
88
+ for (const row of rows) {
89
+ if (!isObject(row)) {
90
+ continue;
91
+ }
92
+ const key = normalizeText(row._UUID);
93
+ if (!key) {
94
+ continue;
95
+ }
96
+ recordMap.set(key, { ...row });
97
+ }
98
+ for (const record of recordMap.values()) {
99
+ const parentId = normalizeText(record._PID);
100
+ if (!parentId || !recordMap.has(parentId)) {
101
+ roots.push(record);
102
+ continue;
103
+ }
104
+ const children = childrenMap.get(parentId) ?? [];
105
+ children.push(record);
106
+ childrenMap.set(parentId, children);
107
+ }
108
+ for (const [key, record] of recordMap.entries()) {
109
+ const children = childrenMap.get(key);
110
+ if (children && children.length > 0) {
111
+ record.children = children.sort(dictSortKey);
112
+ }
113
+ }
114
+ return roots.sort(dictSortKey);
115
+ }
116
+ export function buildBaseSeedSqlVars(input) {
117
+ const adminPassword = input.adminPassword || BASE_SEED_DEFAULT_ADMIN_PASSWORD;
118
+ const passwordHash = createHash('md5').update(adminPassword, 'utf8').digest('hex');
119
+ const adminUid = input.adminUid || BASE_SEED_DEFAULT_ADMIN_UID;
120
+ const adminRole = input.adminRole || BASE_SEED_DEFAULT_ADMIN_ROLE;
121
+ const resetSql = input.resetAdminPassword === true
122
+ ? `UPDATE _SYS_USER\nSET _PWD = ${sqlLiteral(passwordHash)}\nWHERE _UID = ${sqlLiteral(adminUid)};`
123
+ : '';
124
+ return {
125
+ SYSID: sqlLiteral(input.sysid || BASE_SEED_DEFAULT_SYSID),
126
+ ADMIN_UID: sqlLiteral(adminUid),
127
+ ADMIN_NAME: sqlLiteral(input.adminName || '管理员'),
128
+ ADMIN_ROLE: sqlLiteral(adminRole),
129
+ ADMIN_ROLE_NAME: sqlLiteral(input.adminRoleName || '管理员'),
130
+ ADMIN_PASSWORD_MD5: sqlLiteral(passwordHash),
131
+ RESET_ADMIN_PASSWORD_SQL: resetSql,
132
+ };
133
+ }
134
+ export function renderBaseSeedSql(template, values) {
135
+ let rendered = template;
136
+ for (const [key, value] of Object.entries(values)) {
137
+ rendered = rendered.replaceAll(`{{${key}}}`, value);
138
+ }
139
+ const missing = [...rendered.matchAll(/\{\{[A-Z0-9_]+\}\}/g)].map((item) => item[0]);
140
+ if (missing.length > 0) {
141
+ throw new SeiMcpError(`初始化 SQL 存在未替换变量:${[...new Set(missing)].join(', ')}`, 'INVALID_PARAMS');
142
+ }
143
+ return rendered;
144
+ }
145
+ export function removeSqlCommentLines(sql) {
146
+ return sql
147
+ .split('\n')
148
+ .filter((line) => !line.trimStart().startsWith('--'))
149
+ .join('\n');
150
+ }
151
+ export function splitSqlStatements(sql) {
152
+ const statements = [];
153
+ let current = '';
154
+ let quote = null;
155
+ let escaped = false;
156
+ for (const char of sql) {
157
+ if (escaped) {
158
+ current += char;
159
+ escaped = false;
160
+ continue;
161
+ }
162
+ if (char === '\\' && quote !== null) {
163
+ current += char;
164
+ escaped = true;
165
+ continue;
166
+ }
167
+ if (quote !== null) {
168
+ current += char;
169
+ if (char === quote) {
170
+ quote = null;
171
+ }
172
+ continue;
173
+ }
174
+ if (char === '\'' || char === '"' || char === '`') {
175
+ current += char;
176
+ quote = char;
177
+ continue;
178
+ }
179
+ if (char === ';') {
180
+ const statement = current.trim();
181
+ if (statement) {
182
+ statements.push(statement);
183
+ }
184
+ current = '';
185
+ continue;
186
+ }
187
+ current += char;
188
+ }
189
+ const finalStatement = current.trim();
190
+ if (finalStatement) {
191
+ statements.push(finalStatement);
192
+ }
193
+ return statements;
194
+ }
195
+ function buildDictQueryFilter(typeCode, keyword) {
196
+ const filters = [];
197
+ const normalizedType = normalizeText(typeCode);
198
+ const normalizedKeyword = normalizeText(keyword);
199
+ if (normalizedType) {
200
+ filters.push({ _TYPE: { '=': normalizedType } });
201
+ }
202
+ if (normalizedKeyword) {
203
+ filters.push({
204
+ OR: [
205
+ { _UUID: { '*LIKE*': normalizedKeyword } },
206
+ { _TYPE: { '*LIKE*': normalizedKeyword } },
207
+ { _CODE: { '*LIKE*': normalizedKeyword } },
208
+ { _NAME: { '*LIKE*': normalizedKeyword } },
209
+ ],
210
+ });
211
+ }
212
+ return filters;
213
+ }
214
+ function dictSortKey(a, b) {
215
+ const sortA = normalizeSort(typeof a._SORT === 'number' ? a._SORT : Number(a._SORT ?? 0));
216
+ const sortB = normalizeSort(typeof b._SORT === 'number' ? b._SORT : Number(b._SORT ?? 0));
217
+ if (sortA !== sortB) {
218
+ return sortA - sortB;
219
+ }
220
+ return normalizeText(a._CODE).localeCompare(normalizeText(b._CODE), 'zh-CN');
221
+ }
222
+ function normalizeDictFlag(value) {
223
+ return value === 1 ? 1 : 0;
224
+ }
225
+ function normalizeSort(value) {
226
+ return Number.isInteger(value) && Number(value) >= 0 ? Number(value) : 100;
227
+ }
228
+ function requiredText(value, label) {
229
+ const normalized = normalizeText(value);
230
+ if (!normalized) {
231
+ throw new SeiMcpError(`${label} 不能为空`, 'INVALID_PARAMS');
232
+ }
233
+ return normalized;
234
+ }
235
+ function normalizeText(value) {
236
+ return typeof value === 'string' ? value.trim() : '';
237
+ }
238
+ function sqlLiteral(value) {
239
+ if (value === null || value === undefined) {
240
+ return 'NULL';
241
+ }
242
+ return `'${String(value).replace(/'/g, "''")}'`;
243
+ }
244
+ function isObject(value) {
245
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
246
+ }
@@ -0,0 +1,10 @@
1
+ import { loadConfig } from '../config.js';
2
+ import { DEFAULT_LOG_LEVEL } from '../constants.js';
3
+ import { loadWorkingDirEnv } from '../env.js';
4
+ import { createLogger } from '../logger.js';
5
+ export async function loadCliContext(argv = process.argv.slice(2), env = process.env) {
6
+ await loadWorkingDirEnv();
7
+ const logger = createLogger(env.SEI_MCP_LOG_LEVEL ?? DEFAULT_LOG_LEVEL);
8
+ const config = await loadConfig(argv, env);
9
+ return { config, logger };
10
+ }
@@ -0,0 +1,6 @@
1
+ export function printJson(value) {
2
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
3
+ }
4
+ export function writeText(text) {
5
+ process.stdout.write(text);
6
+ }
@@ -0,0 +1,33 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { SeiMcpError } from '../errors.js';
3
+ export async function loadPayload(options) {
4
+ const sources = [options.stdin, options.jsonText !== undefined, options.filePath !== undefined].filter(Boolean).length;
5
+ if (sources > 1) {
6
+ throw new SeiMcpError('只能选择一种载荷来源:--json、--file 或 --stdin', 'INVALID_PARAMS');
7
+ }
8
+ if (options.jsonText !== undefined) {
9
+ return parseJson(options.jsonText);
10
+ }
11
+ if (options.filePath !== undefined) {
12
+ return parseJson(await readFile(options.filePath, 'utf8'));
13
+ }
14
+ if (options.stdin) {
15
+ return parseJson(await readStdin());
16
+ }
17
+ return options.fallback;
18
+ }
19
+ export function parseJson(text) {
20
+ try {
21
+ return JSON.parse(text);
22
+ }
23
+ catch (error) {
24
+ throw new SeiMcpError(`载荷不是合法 JSON:${error instanceof Error ? error.message : String(error)}`, 'INVALID_PARAMS');
25
+ }
26
+ }
27
+ async function readStdin() {
28
+ const chunks = [];
29
+ for await (const chunk of process.stdin) {
30
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
31
+ }
32
+ return Buffer.concat(chunks).toString('utf8');
33
+ }