taurusdb-core 0.4.0 → 0.5.0-rc.1
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/LICENSE +21 -0
- package/README.md +3 -1
- package/dist/audit/jsonl-writer.d.ts +47 -0
- package/dist/audit/jsonl-writer.js +124 -0
- package/dist/auth/sql-profile-loader/env-source.js +10 -0
- package/dist/auth/sql-profile-loader/parsing.js +10 -1
- package/dist/auth/sql-profile-loader/runtime-override.d.ts +1 -0
- package/dist/auth/sql-profile-loader/runtime-override.js +19 -1
- package/dist/auth/sql-profile-loader/types.d.ts +7 -0
- package/dist/capability/probe.js +3 -1
- package/dist/cloud/auth.d.ts +1 -0
- package/dist/cloud/auth.js +37 -0
- package/dist/config/env.js +14 -0
- package/dist/config/schema.d.ts +68 -0
- package/dist/config/schema.js +17 -0
- package/dist/context/datasource-resolver.js +7 -0
- package/dist/context/session-context.d.ts +7 -0
- package/dist/diagnostics/replication-lag.d.ts +4 -0
- package/dist/diagnostics/replication-lag.js +138 -0
- package/dist/diagnostics/types.d.ts +5 -1
- package/dist/diagnostics/types.js +7 -7
- package/dist/engine/runtime.d.ts +2 -2
- package/dist/engine/runtime.js +8 -14
- package/dist/engine/types.d.ts +3 -2
- package/dist/engine.d.ts +4 -3
- package/dist/engine.js +34 -1
- package/dist/executor/bounded-sql.d.ts +1 -0
- package/dist/executor/bounded-sql.js +10 -0
- package/dist/executor/concurrency-limiter.d.ts +15 -0
- package/dist/executor/concurrency-limiter.js +67 -0
- package/dist/executor/connection-pool.d.ts +3 -2
- package/dist/executor/connection-pool.js +36 -24
- package/dist/executor/sql-executor.d.ts +3 -0
- package/dist/executor/sql-executor.js +52 -9
- package/dist/executor/types.d.ts +5 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -1
- package/dist/safety/confirmation-store.d.ts +30 -7
- package/dist/safety/confirmation-store.js +154 -30
- package/dist/safety/guardrail.d.ts +3 -0
- package/dist/safety/guardrail.js +16 -6
- package/dist/safety/redaction.d.ts +6 -0
- package/dist/safety/redaction.js +47 -6
- package/dist/safety/sql-classifier.d.ts +1 -0
- package/dist/safety/sql-classifier.js +1 -0
- package/dist/safety/sql-validator.d.ts +1 -0
- package/dist/safety/sql-validator.js +24 -0
- package/dist/schema/adapters/mysql.js +3 -1
- package/dist/taurus/flashback.js +4 -10
- package/dist/taurus/recycle-bin.js +2 -8
- package/dist/utils/formatter.d.ts +6 -2
- package/dist/utils/formatter.js +7 -3
- package/dist/utils/logger.js +8 -0
- package/dist/utils/mysql-identifier.d.ts +1 -0
- package/dist/utils/mysql-identifier.js +9 -0
- package/package.json +13 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TaurusDB MCP contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Shared TaurusDB data-plane engine for:
|
|
|
4
4
|
|
|
5
5
|
- schema discovery
|
|
6
6
|
- readonly and mutation SQL execution
|
|
7
|
-
- SQL guardrails and
|
|
7
|
+
- SQL guardrails and external operator-signed approval flow
|
|
8
8
|
- TaurusDB capability detection
|
|
9
9
|
- diagnostics workflows
|
|
10
10
|
|
|
@@ -19,3 +19,5 @@ npm install taurusdb-core
|
|
|
19
19
|
- Requires Node.js `>= 20`
|
|
20
20
|
- This is the shared engine package
|
|
21
21
|
- Most end users should install `taurusdb-mcp` instead
|
|
22
|
+
- TLS verification, least-privilege credentials, bounded results, and JSONL
|
|
23
|
+
auditing are enabled as production safety controls
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type AuditDecision = "allowed" | "blocked" | "approval_required" | "approval_denied" | "failed";
|
|
2
|
+
export interface AuditEvent {
|
|
3
|
+
timestamp: string;
|
|
4
|
+
task_id: string;
|
|
5
|
+
tool: string;
|
|
6
|
+
actor: string;
|
|
7
|
+
datasource?: string;
|
|
8
|
+
database?: string;
|
|
9
|
+
host?: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
project_id?: string;
|
|
12
|
+
instance_id?: string;
|
|
13
|
+
node_id?: string;
|
|
14
|
+
sql_hash?: string;
|
|
15
|
+
raw_sql?: string;
|
|
16
|
+
decision: AuditDecision;
|
|
17
|
+
outcome: "success" | "error";
|
|
18
|
+
error_code?: string;
|
|
19
|
+
duration_ms: number;
|
|
20
|
+
}
|
|
21
|
+
export interface AuditWriter {
|
|
22
|
+
write(event: AuditEvent): Promise<void>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface JsonlAuditWriterOptions {
|
|
26
|
+
logPath: string;
|
|
27
|
+
syncWrites?: boolean;
|
|
28
|
+
maxBytes?: number;
|
|
29
|
+
maxFiles?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare class JsonlAuditWriter implements AuditWriter {
|
|
32
|
+
private handle;
|
|
33
|
+
private readonly logPath;
|
|
34
|
+
private readonly syncWrites;
|
|
35
|
+
private readonly maxBytes;
|
|
36
|
+
private readonly maxFiles;
|
|
37
|
+
private currentBytes;
|
|
38
|
+
private pending;
|
|
39
|
+
private closed;
|
|
40
|
+
private constructor();
|
|
41
|
+
static create(options: JsonlAuditWriterOptions): Promise<JsonlAuditWriter>;
|
|
42
|
+
private rotate;
|
|
43
|
+
private writeLine;
|
|
44
|
+
write(event: AuditEvent): Promise<void>;
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createJsonlAuditWriter(options: JsonlAuditWriterOptions): Promise<JsonlAuditWriter>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { mkdir, open, rename, rm, } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function expandHome(input) {
|
|
6
|
+
if (input === "~") {
|
|
7
|
+
return os.homedir();
|
|
8
|
+
}
|
|
9
|
+
return input.startsWith("~/") ? path.join(os.homedir(), input.slice(2)) : input;
|
|
10
|
+
}
|
|
11
|
+
export class JsonlAuditWriter {
|
|
12
|
+
handle;
|
|
13
|
+
logPath;
|
|
14
|
+
syncWrites;
|
|
15
|
+
maxBytes;
|
|
16
|
+
maxFiles;
|
|
17
|
+
currentBytes;
|
|
18
|
+
pending = Promise.resolve();
|
|
19
|
+
closed = false;
|
|
20
|
+
constructor(opened, logPath, syncWrites, maxBytes, maxFiles) {
|
|
21
|
+
this.handle = opened.handle;
|
|
22
|
+
this.currentBytes = opened.size;
|
|
23
|
+
this.logPath = logPath;
|
|
24
|
+
this.syncWrites = syncWrites;
|
|
25
|
+
this.maxBytes = maxBytes;
|
|
26
|
+
this.maxFiles = maxFiles;
|
|
27
|
+
}
|
|
28
|
+
static async create(options) {
|
|
29
|
+
const logPath = path.resolve(expandHome(options.logPath));
|
|
30
|
+
await mkdir(path.dirname(logPath), { recursive: true, mode: 0o700 });
|
|
31
|
+
const opened = await openAuditFile(logPath);
|
|
32
|
+
const maxBytes = options.maxBytes ?? 104857600;
|
|
33
|
+
const maxFiles = options.maxFiles ?? 10;
|
|
34
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
35
|
+
await opened.handle.close();
|
|
36
|
+
throw new Error("Audit maxBytes must be a positive safe integer.");
|
|
37
|
+
}
|
|
38
|
+
if (!Number.isSafeInteger(maxFiles) || maxFiles <= 0 || maxFiles > 100) {
|
|
39
|
+
await opened.handle.close();
|
|
40
|
+
throw new Error("Audit maxFiles must be an integer between 1 and 100.");
|
|
41
|
+
}
|
|
42
|
+
return new JsonlAuditWriter(opened, logPath, options.syncWrites ?? true, maxBytes, maxFiles);
|
|
43
|
+
}
|
|
44
|
+
async rotate() {
|
|
45
|
+
if (this.syncWrites) {
|
|
46
|
+
await this.handle.sync();
|
|
47
|
+
}
|
|
48
|
+
await this.handle.close();
|
|
49
|
+
try {
|
|
50
|
+
await rm(`${this.logPath}.${this.maxFiles}`, { force: true });
|
|
51
|
+
for (let index = this.maxFiles - 1; index >= 1; index -= 1) {
|
|
52
|
+
const source = `${this.logPath}.${index}`;
|
|
53
|
+
const destination = `${this.logPath}.${index + 1}`;
|
|
54
|
+
try {
|
|
55
|
+
await rm(destination, { force: true });
|
|
56
|
+
await rename(source, destination);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.code !== "ENOENT") {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
await rm(`${this.logPath}.1`, { force: true });
|
|
65
|
+
await rename(this.logPath, `${this.logPath}.1`);
|
|
66
|
+
const opened = await openAuditFile(this.logPath);
|
|
67
|
+
this.handle = opened.handle;
|
|
68
|
+
this.currentBytes = opened.size;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const reopened = await openAuditFile(this.logPath);
|
|
72
|
+
this.handle = reopened.handle;
|
|
73
|
+
this.currentBytes = reopened.size;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async writeLine(line) {
|
|
78
|
+
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
79
|
+
if (this.currentBytes > 0 && this.currentBytes + lineBytes > this.maxBytes) {
|
|
80
|
+
await this.rotate();
|
|
81
|
+
}
|
|
82
|
+
await this.handle.write(line, undefined, "utf8");
|
|
83
|
+
this.currentBytes += lineBytes;
|
|
84
|
+
if (this.syncWrites) {
|
|
85
|
+
await this.handle.sync();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
write(event) {
|
|
89
|
+
if (this.closed) {
|
|
90
|
+
return Promise.reject(new Error("Audit writer is closed."));
|
|
91
|
+
}
|
|
92
|
+
const line = `${JSON.stringify(event)}\n`;
|
|
93
|
+
const next = this.pending.then(() => this.writeLine(line));
|
|
94
|
+
this.pending = next.catch(() => undefined);
|
|
95
|
+
return next;
|
|
96
|
+
}
|
|
97
|
+
async close() {
|
|
98
|
+
if (this.closed) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.closed = true;
|
|
102
|
+
await this.pending;
|
|
103
|
+
await this.handle.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function openAuditFile(logPath) {
|
|
107
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
108
|
+
const handle = await open(logPath, constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | noFollow, 0o600);
|
|
109
|
+
try {
|
|
110
|
+
const fileStat = await handle.stat();
|
|
111
|
+
if (!fileStat.isFile()) {
|
|
112
|
+
throw new Error("Audit log target must be a regular file.");
|
|
113
|
+
}
|
|
114
|
+
await handle.chmod(0o600);
|
|
115
|
+
return { handle, size: fileStat.size };
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
await handle.close();
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export function createJsonlAuditWriter(options) {
|
|
123
|
+
return JsonlAuditWriter.create(options);
|
|
124
|
+
}
|
|
@@ -60,6 +60,13 @@ export function parseEnvProfile(env) {
|
|
|
60
60
|
if (!passwordRef) {
|
|
61
61
|
throw new Error("Missing SQL password in environment. Set TAURUSDB_SQL_PASSWORD or include it in DSN.");
|
|
62
62
|
}
|
|
63
|
+
const mutationUsername = asString(env.TAURUSDB_SQL_MUTATION_USER);
|
|
64
|
+
const mutationPasswordRef = Object.hasOwn(env, "TAURUSDB_SQL_MUTATION_PASSWORD")
|
|
65
|
+
? parseCredentialRef(env.TAURUSDB_SQL_MUTATION_PASSWORD, "TAURUSDB_SQL_MUTATION_PASSWORD")
|
|
66
|
+
: undefined;
|
|
67
|
+
if ((mutationUsername && !mutationPasswordRef) || (!mutationUsername && mutationPasswordRef)) {
|
|
68
|
+
throw new Error("Mutation credentials require both TAURUSDB_SQL_MUTATION_USER and TAURUSDB_SQL_MUTATION_PASSWORD.");
|
|
69
|
+
}
|
|
63
70
|
const poolSize = asInteger(env.TAURUSDB_SQL_POOL_SIZE);
|
|
64
71
|
if (poolSize !== undefined && poolSize <= 0) {
|
|
65
72
|
throw new Error("Invalid TAURUSDB_SQL_POOL_SIZE: must be positive.");
|
|
@@ -74,6 +81,9 @@ export function parseEnvProfile(env) {
|
|
|
74
81
|
username,
|
|
75
82
|
password: passwordRef,
|
|
76
83
|
},
|
|
84
|
+
mutationUser: mutationUsername && mutationPasswordRef
|
|
85
|
+
? { username: mutationUsername, password: mutationPasswordRef }
|
|
86
|
+
: undefined,
|
|
77
87
|
poolSize,
|
|
78
88
|
});
|
|
79
89
|
}
|
|
@@ -190,11 +190,13 @@ export function parseProfileRecord(name, value, context) {
|
|
|
190
190
|
throw new Error(`Invalid datasource profile ${name} in ${context}: port must be positive.`);
|
|
191
191
|
}
|
|
192
192
|
const database = asString(value.database);
|
|
193
|
+
const instanceId = asString(value.instanceId ?? value.instance_id);
|
|
194
|
+
const nodeId = asString(value.nodeId ?? value.node_id);
|
|
193
195
|
const poolSize = asInteger(value.poolSize);
|
|
194
196
|
if (poolSize !== undefined && poolSize <= 0) {
|
|
195
197
|
throw new Error(`Invalid datasource profile ${name} in ${context}: poolSize must be positive.`);
|
|
196
198
|
}
|
|
197
|
-
//
|
|
199
|
+
// `user` is the read-only credential. Keep older read-only aliases for compatibility.
|
|
198
200
|
const userRaw = value.user ??
|
|
199
201
|
value.readonlyUser ??
|
|
200
202
|
value.readonly ??
|
|
@@ -203,6 +205,10 @@ export function parseProfileRecord(name, value, context) {
|
|
|
203
205
|
throw new Error(`Invalid datasource profile ${name} in ${context}: missing user.`);
|
|
204
206
|
}
|
|
205
207
|
const user = parseUserCredential(userRaw, `${context}.${name}.user`);
|
|
208
|
+
const mutationUserRaw = value.mutationUser ?? value.writeUser ?? value.rwUser;
|
|
209
|
+
const mutationUser = mutationUserRaw === undefined
|
|
210
|
+
? undefined
|
|
211
|
+
: parseUserCredential(mutationUserRaw, `${context}.${name}.mutationUser`);
|
|
206
212
|
const tls = parseTlsOptions(value.tls, `${context}.${name}.tls`);
|
|
207
213
|
return withRedactedToString({
|
|
208
214
|
name,
|
|
@@ -210,7 +216,10 @@ export function parseProfileRecord(name, value, context) {
|
|
|
210
216
|
host,
|
|
211
217
|
port,
|
|
212
218
|
database,
|
|
219
|
+
instanceId,
|
|
220
|
+
nodeId,
|
|
213
221
|
user,
|
|
222
|
+
mutationUser,
|
|
214
223
|
tls,
|
|
215
224
|
poolSize,
|
|
216
225
|
});
|
|
@@ -5,6 +5,7 @@ export declare class RuntimeOverrideProfileLoader implements RuntimeTargetProfil
|
|
|
5
5
|
private readonly runtimeTargets;
|
|
6
6
|
constructor(base: ProfileLoader);
|
|
7
7
|
setRuntimeTarget(name: string, target: RuntimeDataSourceTarget): void;
|
|
8
|
+
clearRuntimeUser(name: string): void;
|
|
8
9
|
clearRuntimeTarget(name: string): void;
|
|
9
10
|
clearAllRuntimeTargets(): void;
|
|
10
11
|
getRuntimeTarget(name: string): RuntimeDataSourceTarget | undefined;
|
|
@@ -8,6 +8,9 @@ export function applyRuntimeTarget(profile, target) {
|
|
|
8
8
|
host: target.host ?? profile.host,
|
|
9
9
|
port: target.port ?? profile.port,
|
|
10
10
|
database: target.database ?? profile.database,
|
|
11
|
+
instanceId: target.instanceId ?? profile.instanceId,
|
|
12
|
+
nodeId: target.nodeId ?? profile.nodeId,
|
|
13
|
+
user: target.user ?? profile.user,
|
|
11
14
|
});
|
|
12
15
|
}
|
|
13
16
|
export class RuntimeOverrideProfileLoader {
|
|
@@ -18,6 +21,9 @@ export class RuntimeOverrideProfileLoader {
|
|
|
18
21
|
}
|
|
19
22
|
setRuntimeTarget(name, target) {
|
|
20
23
|
const current = this.runtimeTargets.get(name);
|
|
24
|
+
const targetChanged = (target.host !== undefined && target.host !== current?.host) ||
|
|
25
|
+
(target.instanceId !== undefined && target.instanceId !== current?.instanceId);
|
|
26
|
+
const user = target.user ?? (targetChanged ? undefined : current?.user);
|
|
21
27
|
const next = {
|
|
22
28
|
host: target.host ?? current?.host,
|
|
23
29
|
port: target.port ?? current?.port,
|
|
@@ -25,6 +31,17 @@ export class RuntimeOverrideProfileLoader {
|
|
|
25
31
|
instanceId: target.instanceId ?? current?.instanceId,
|
|
26
32
|
nodeId: target.nodeId ?? current?.nodeId,
|
|
27
33
|
};
|
|
34
|
+
if (user) {
|
|
35
|
+
next.user = user;
|
|
36
|
+
}
|
|
37
|
+
this.runtimeTargets.set(name, next);
|
|
38
|
+
}
|
|
39
|
+
clearRuntimeUser(name) {
|
|
40
|
+
const current = this.runtimeTargets.get(name);
|
|
41
|
+
if (!current) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const { user: _user, ...next } = current;
|
|
28
45
|
this.runtimeTargets.set(name, next);
|
|
29
46
|
}
|
|
30
47
|
clearRuntimeTarget(name) {
|
|
@@ -34,7 +51,8 @@ export class RuntimeOverrideProfileLoader {
|
|
|
34
51
|
this.runtimeTargets.clear();
|
|
35
52
|
}
|
|
36
53
|
getRuntimeTarget(name) {
|
|
37
|
-
|
|
54
|
+
const target = this.runtimeTargets.get(name);
|
|
55
|
+
return target ? { ...target } : undefined;
|
|
38
56
|
}
|
|
39
57
|
async load() {
|
|
40
58
|
const loaded = await this.base.load();
|
|
@@ -31,7 +31,12 @@ export interface DataSourceProfile {
|
|
|
31
31
|
host?: string;
|
|
32
32
|
port: number;
|
|
33
33
|
database?: string;
|
|
34
|
+
instanceId?: string;
|
|
35
|
+
nodeId?: string;
|
|
36
|
+
/** Read-only credential used by discovery, diagnostics, and query tools. */
|
|
34
37
|
user?: UserCredential;
|
|
38
|
+
/** Separate credential required for mutation tools. No fallback is allowed. */
|
|
39
|
+
mutationUser?: UserCredential;
|
|
35
40
|
tls?: TlsOptions;
|
|
36
41
|
poolSize?: number;
|
|
37
42
|
toString(): string;
|
|
@@ -45,11 +50,13 @@ export interface RuntimeDataSourceTarget {
|
|
|
45
50
|
host?: string;
|
|
46
51
|
port?: number;
|
|
47
52
|
database?: string;
|
|
53
|
+
user?: UserCredential;
|
|
48
54
|
instanceId?: string;
|
|
49
55
|
nodeId?: string;
|
|
50
56
|
}
|
|
51
57
|
export interface RuntimeTargetProfileLoader extends ProfileLoader {
|
|
52
58
|
setRuntimeTarget(name: string, target: RuntimeDataSourceTarget): void;
|
|
59
|
+
clearRuntimeUser(name: string): void;
|
|
53
60
|
clearRuntimeTarget(name: string): void;
|
|
54
61
|
clearAllRuntimeTargets(): void;
|
|
55
62
|
getRuntimeTarget(name: string): RuntimeDataSourceTarget | undefined;
|
package/dist/capability/probe.js
CHANGED
|
@@ -111,7 +111,9 @@ export class CapabilityProbeImpl {
|
|
|
111
111
|
this.connectionPool = options.connectionPool;
|
|
112
112
|
}
|
|
113
113
|
async probe(ctx) {
|
|
114
|
-
const session = await this.connectionPool.acquire(ctx.datasource, "ro"
|
|
114
|
+
const session = await this.connectionPool.acquire(ctx.datasource, "ro", {
|
|
115
|
+
database: ctx.database,
|
|
116
|
+
});
|
|
115
117
|
try {
|
|
116
118
|
const variables = await collectVariables(session);
|
|
117
119
|
const kernelInfo = await detectKernelInfo(session, variables);
|
package/dist/cloud/auth.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface HuaweiCloudAuthOptions {
|
|
|
9
9
|
domainSuffix?: string;
|
|
10
10
|
iamEndpoint?: string;
|
|
11
11
|
language?: "en-us" | "zh-cn";
|
|
12
|
+
allowedEndpointHosts?: string[];
|
|
12
13
|
credentialProvider?: HuaweiCloudCredentialProvider;
|
|
13
14
|
}
|
|
14
15
|
export interface HuaweiCloudCredentials {
|
package/dist/cloud/auth.js
CHANGED
|
@@ -3,6 +3,24 @@ import { createSystemCredentialProvider } from "./keychain.js";
|
|
|
3
3
|
function readString(value) {
|
|
4
4
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
5
5
|
}
|
|
6
|
+
function validateHuaweiCloudUrl(url, auth) {
|
|
7
|
+
if (url.protocol !== "https:") {
|
|
8
|
+
throw new Error("Huawei Cloud API endpoints must use HTTPS.");
|
|
9
|
+
}
|
|
10
|
+
if (url.username || url.password) {
|
|
11
|
+
throw new Error("Huawei Cloud API endpoints must not contain credentials.");
|
|
12
|
+
}
|
|
13
|
+
const hostname = url.hostname.toLowerCase().replace(/\.$/, "");
|
|
14
|
+
const suffix = (readString(auth.domainSuffix) ?? "myhuaweicloud.com")
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/^\.+|\.+$/g, "");
|
|
17
|
+
const explicitHosts = new Set((auth.allowedEndpointHosts ?? []).map((host) => host.toLowerCase().replace(/\.$/, "")));
|
|
18
|
+
if (hostname !== suffix &&
|
|
19
|
+
!hostname.endsWith(`.${suffix}`) &&
|
|
20
|
+
!explicitHosts.has(hostname)) {
|
|
21
|
+
throw new Error(`Huawei Cloud API endpoint host is not allowed: ${hostname}.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
6
24
|
function sha256Hex(value) {
|
|
7
25
|
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
8
26
|
}
|
|
@@ -88,6 +106,7 @@ export async function fetchHuaweiCloud(options) {
|
|
|
88
106
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
89
107
|
const method = options.method ?? "GET";
|
|
90
108
|
const url = new URL(options.url);
|
|
109
|
+
validateHuaweiCloudUrl(url, options.auth);
|
|
91
110
|
const body = options.body ?? "";
|
|
92
111
|
const authToken = readString(options.auth.authToken);
|
|
93
112
|
const headers = new Headers(options.headers);
|
|
@@ -198,6 +217,24 @@ export function getHuaweiCloudAuthFromConfig(config) {
|
|
|
198
217
|
domainSuffix: config.cloud?.domainSuffix,
|
|
199
218
|
iamEndpoint: config.cloud?.iamEndpoint,
|
|
200
219
|
language: config.cloud?.language,
|
|
220
|
+
allowedEndpointHosts: [
|
|
221
|
+
config.cloud?.apiEndpoint,
|
|
222
|
+
config.cloud?.iamEndpoint,
|
|
223
|
+
config.cloud?.kmsEndpoint,
|
|
224
|
+
config.cloud?.csmsEndpoint,
|
|
225
|
+
config.slowSqlSource?.taurusApi?.endpoint,
|
|
226
|
+
config.slowSqlSource?.das?.endpoint,
|
|
227
|
+
config.metricsSource?.ces?.endpoint,
|
|
228
|
+
]
|
|
229
|
+
.filter((value) => Boolean(value))
|
|
230
|
+
.flatMap((value) => {
|
|
231
|
+
try {
|
|
232
|
+
return [new URL(value).hostname];
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
}),
|
|
201
238
|
credentialProvider,
|
|
202
239
|
};
|
|
203
240
|
}
|
package/dist/config/env.js
CHANGED
|
@@ -147,10 +147,24 @@ export function buildRawConfigFromEnv(env) {
|
|
|
147
147
|
maxColumns: parseInteger(env.TAURUSDB_MCP_MAX_COLUMNS, "TAURUSDB_MCP_MAX_COLUMNS"),
|
|
148
148
|
maxStatementMs: parseInteger(env.TAURUSDB_MCP_MAX_STATEMENT_MS, "TAURUSDB_MCP_MAX_STATEMENT_MS"),
|
|
149
149
|
maxFieldChars: parseInteger(env.TAURUSDB_MCP_MAX_FIELD_CHARS, "TAURUSDB_MCP_MAX_FIELD_CHARS"),
|
|
150
|
+
maxResultBytes: parseInteger(env.TAURUSDB_MCP_MAX_RESULT_BYTES, "TAURUSDB_MCP_MAX_RESULT_BYTES"),
|
|
151
|
+
maxBlobBytes: parseInteger(env.TAURUSDB_MCP_MAX_BLOB_BYTES, "TAURUSDB_MCP_MAX_BLOB_BYTES"),
|
|
152
|
+
maxConcurrentQueries: parseInteger(env.TAURUSDB_MCP_MAX_CONCURRENT_QUERIES, "TAURUSDB_MCP_MAX_CONCURRENT_QUERIES"),
|
|
153
|
+
maxQueuedQueries: parseInteger(env.TAURUSDB_MCP_MAX_QUEUED_QUERIES, "TAURUSDB_MCP_MAX_QUEUED_QUERIES"),
|
|
154
|
+
queueTimeoutMs: parseInteger(env.TAURUSDB_MCP_QUEUE_TIMEOUT_MS, "TAURUSDB_MCP_QUEUE_TIMEOUT_MS"),
|
|
150
155
|
},
|
|
151
156
|
audit: {
|
|
152
157
|
logPath: expandTildePath(readString(env.TAURUSDB_MCP_AUDIT_LOG_PATH)),
|
|
153
158
|
includeRawSql: parseBoolean(env.TAURUSDB_MCP_AUDIT_INCLUDE_RAW_SQL, "TAURUSDB_MCP_AUDIT_INCLUDE_RAW_SQL"),
|
|
159
|
+
maxBytes: parseInteger(env.TAURUSDB_MCP_AUDIT_MAX_BYTES, "TAURUSDB_MCP_AUDIT_MAX_BYTES"),
|
|
160
|
+
maxFiles: parseInteger(env.TAURUSDB_MCP_AUDIT_MAX_FILES, "TAURUSDB_MCP_AUDIT_MAX_FILES"),
|
|
161
|
+
},
|
|
162
|
+
security: {
|
|
163
|
+
mutationsEnabled: parseBoolean(env.TAURUSDB_ENABLE_MUTATIONS, "TAURUSDB_ENABLE_MUTATIONS"),
|
|
164
|
+
dynamicTargetsEnabled: parseBoolean(env.TAURUSDB_ENABLE_DYNAMIC_TARGETS, "TAURUSDB_ENABLE_DYNAMIC_TARGETS"),
|
|
165
|
+
requireTls: parseBoolean(env.TAURUSDB_REQUIRE_TLS, "TAURUSDB_REQUIRE_TLS"),
|
|
166
|
+
approvalSecretPath: expandTildePath(readString(env.TAURUSDB_MUTATION_APPROVAL_SECRET_FILE)),
|
|
167
|
+
approvalTtlSeconds: parseInteger(env.TAURUSDB_MUTATION_APPROVAL_TTL_SECONDS, "TAURUSDB_MUTATION_APPROVAL_TTL_SECONDS"),
|
|
154
168
|
},
|
|
155
169
|
slowSqlSource: {
|
|
156
170
|
taurusApi: {
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -62,26 +62,66 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
62
62
|
maxColumns: z.ZodDefault<z.ZodNumber>;
|
|
63
63
|
maxStatementMs: z.ZodDefault<z.ZodNumber>;
|
|
64
64
|
maxFieldChars: z.ZodDefault<z.ZodNumber>;
|
|
65
|
+
maxResultBytes: z.ZodDefault<z.ZodNumber>;
|
|
66
|
+
maxBlobBytes: z.ZodDefault<z.ZodNumber>;
|
|
67
|
+
maxConcurrentQueries: z.ZodDefault<z.ZodNumber>;
|
|
68
|
+
maxQueuedQueries: z.ZodDefault<z.ZodNumber>;
|
|
69
|
+
queueTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
65
70
|
}, "strip", z.ZodTypeAny, {
|
|
66
71
|
maxRows: number;
|
|
67
72
|
maxColumns: number;
|
|
68
73
|
maxStatementMs: number;
|
|
69
74
|
maxFieldChars: number;
|
|
75
|
+
maxResultBytes: number;
|
|
76
|
+
maxBlobBytes: number;
|
|
77
|
+
maxConcurrentQueries: number;
|
|
78
|
+
maxQueuedQueries: number;
|
|
79
|
+
queueTimeoutMs: number;
|
|
70
80
|
}, {
|
|
71
81
|
maxRows?: number | undefined;
|
|
72
82
|
maxColumns?: number | undefined;
|
|
73
83
|
maxStatementMs?: number | undefined;
|
|
74
84
|
maxFieldChars?: number | undefined;
|
|
85
|
+
maxResultBytes?: number | undefined;
|
|
86
|
+
maxBlobBytes?: number | undefined;
|
|
87
|
+
maxConcurrentQueries?: number | undefined;
|
|
88
|
+
maxQueuedQueries?: number | undefined;
|
|
89
|
+
queueTimeoutMs?: number | undefined;
|
|
75
90
|
}>>;
|
|
76
91
|
audit: z.ZodDefault<z.ZodObject<{
|
|
77
92
|
logPath: z.ZodDefault<z.ZodString>;
|
|
78
93
|
includeRawSql: z.ZodDefault<z.ZodBoolean>;
|
|
94
|
+
maxBytes: z.ZodDefault<z.ZodNumber>;
|
|
95
|
+
maxFiles: z.ZodDefault<z.ZodNumber>;
|
|
79
96
|
}, "strip", z.ZodTypeAny, {
|
|
80
97
|
logPath: string;
|
|
81
98
|
includeRawSql: boolean;
|
|
99
|
+
maxBytes: number;
|
|
100
|
+
maxFiles: number;
|
|
82
101
|
}, {
|
|
83
102
|
logPath?: string | undefined;
|
|
84
103
|
includeRawSql?: boolean | undefined;
|
|
104
|
+
maxBytes?: number | undefined;
|
|
105
|
+
maxFiles?: number | undefined;
|
|
106
|
+
}>>;
|
|
107
|
+
security: z.ZodDefault<z.ZodObject<{
|
|
108
|
+
mutationsEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
109
|
+
dynamicTargetsEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
110
|
+
requireTls: z.ZodDefault<z.ZodBoolean>;
|
|
111
|
+
approvalSecretPath: z.ZodOptional<z.ZodString>;
|
|
112
|
+
approvalTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
mutationsEnabled: boolean;
|
|
115
|
+
dynamicTargetsEnabled: boolean;
|
|
116
|
+
requireTls: boolean;
|
|
117
|
+
approvalTtlSeconds: number;
|
|
118
|
+
approvalSecretPath?: string | undefined;
|
|
119
|
+
}, {
|
|
120
|
+
mutationsEnabled?: boolean | undefined;
|
|
121
|
+
dynamicTargetsEnabled?: boolean | undefined;
|
|
122
|
+
requireTls?: boolean | undefined;
|
|
123
|
+
approvalSecretPath?: string | undefined;
|
|
124
|
+
approvalTtlSeconds?: number | undefined;
|
|
85
125
|
}>>;
|
|
86
126
|
slowSqlSource: z.ZodDefault<z.ZodObject<{
|
|
87
127
|
taurusApi: z.ZodDefault<z.ZodObject<{
|
|
@@ -305,10 +345,24 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
305
345
|
maxColumns: number;
|
|
306
346
|
maxStatementMs: number;
|
|
307
347
|
maxFieldChars: number;
|
|
348
|
+
maxResultBytes: number;
|
|
349
|
+
maxBlobBytes: number;
|
|
350
|
+
maxConcurrentQueries: number;
|
|
351
|
+
maxQueuedQueries: number;
|
|
352
|
+
queueTimeoutMs: number;
|
|
308
353
|
};
|
|
309
354
|
audit: {
|
|
310
355
|
logPath: string;
|
|
311
356
|
includeRawSql: boolean;
|
|
357
|
+
maxBytes: number;
|
|
358
|
+
maxFiles: number;
|
|
359
|
+
};
|
|
360
|
+
security: {
|
|
361
|
+
mutationsEnabled: boolean;
|
|
362
|
+
dynamicTargetsEnabled: boolean;
|
|
363
|
+
requireTls: boolean;
|
|
364
|
+
approvalTtlSeconds: number;
|
|
365
|
+
approvalSecretPath?: string | undefined;
|
|
312
366
|
};
|
|
313
367
|
slowSqlSource: {
|
|
314
368
|
taurusApi: {
|
|
@@ -382,10 +436,24 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
382
436
|
maxColumns?: number | undefined;
|
|
383
437
|
maxStatementMs?: number | undefined;
|
|
384
438
|
maxFieldChars?: number | undefined;
|
|
439
|
+
maxResultBytes?: number | undefined;
|
|
440
|
+
maxBlobBytes?: number | undefined;
|
|
441
|
+
maxConcurrentQueries?: number | undefined;
|
|
442
|
+
maxQueuedQueries?: number | undefined;
|
|
443
|
+
queueTimeoutMs?: number | undefined;
|
|
385
444
|
} | undefined;
|
|
386
445
|
audit?: {
|
|
387
446
|
logPath?: string | undefined;
|
|
388
447
|
includeRawSql?: boolean | undefined;
|
|
448
|
+
maxBytes?: number | undefined;
|
|
449
|
+
maxFiles?: number | undefined;
|
|
450
|
+
} | undefined;
|
|
451
|
+
security?: {
|
|
452
|
+
mutationsEnabled?: boolean | undefined;
|
|
453
|
+
dynamicTargetsEnabled?: boolean | undefined;
|
|
454
|
+
requireTls?: boolean | undefined;
|
|
455
|
+
approvalSecretPath?: string | undefined;
|
|
456
|
+
approvalTtlSeconds?: number | undefined;
|
|
389
457
|
} | undefined;
|
|
390
458
|
slowSqlSource?: {
|
|
391
459
|
taurusApi?: {
|
package/dist/config/schema.js
CHANGED
|
@@ -5,12 +5,28 @@ const LimitsSchema = z
|
|
|
5
5
|
maxColumns: z.number().int().positive().default(50),
|
|
6
6
|
maxStatementMs: z.number().int().positive().default(15000),
|
|
7
7
|
maxFieldChars: z.number().int().positive().default(2048),
|
|
8
|
+
maxResultBytes: z.number().int().positive().default(1048576),
|
|
9
|
+
maxBlobBytes: z.number().int().positive().default(65536),
|
|
10
|
+
maxConcurrentQueries: z.number().int().positive().default(8),
|
|
11
|
+
maxQueuedQueries: z.number().int().nonnegative().default(32),
|
|
12
|
+
queueTimeoutMs: z.number().int().positive().default(5000),
|
|
8
13
|
})
|
|
9
14
|
.default({});
|
|
10
15
|
const AuditSchema = z
|
|
11
16
|
.object({
|
|
12
17
|
logPath: z.string().min(1).default("~/.taurusdb-mcp/audit.jsonl"),
|
|
13
18
|
includeRawSql: z.boolean().default(false),
|
|
19
|
+
maxBytes: z.number().int().positive().default(104857600),
|
|
20
|
+
maxFiles: z.number().int().positive().max(100).default(10),
|
|
21
|
+
})
|
|
22
|
+
.default({});
|
|
23
|
+
const SecuritySchema = z
|
|
24
|
+
.object({
|
|
25
|
+
mutationsEnabled: z.boolean().default(false),
|
|
26
|
+
dynamicTargetsEnabled: z.boolean().default(false),
|
|
27
|
+
requireTls: z.boolean().default(true),
|
|
28
|
+
approvalSecretPath: z.string().min(1).optional(),
|
|
29
|
+
approvalTtlSeconds: z.number().int().positive().max(3600).default(300),
|
|
14
30
|
})
|
|
15
31
|
.default({});
|
|
16
32
|
const CloudSchema = z
|
|
@@ -89,6 +105,7 @@ export const ConfigSchema = z.object({
|
|
|
89
105
|
cloud: CloudSchema,
|
|
90
106
|
limits: LimitsSchema,
|
|
91
107
|
audit: AuditSchema,
|
|
108
|
+
security: SecuritySchema,
|
|
92
109
|
slowSqlSource: z
|
|
93
110
|
.object({
|
|
94
111
|
taurusApi: TaurusApiSlowSqlSourceSchema,
|
|
@@ -41,12 +41,19 @@ export class DefaultDatasourceResolver {
|
|
|
41
41
|
engine: profile.engine,
|
|
42
42
|
database: normalizeString(input.database) ?? profile.database,
|
|
43
43
|
schema: normalizeString(input.schema),
|
|
44
|
+
host: profile.host,
|
|
45
|
+
port: profile.port,
|
|
46
|
+
projectId: this.config.cloud.projectId,
|
|
47
|
+
instanceId: profile.instanceId ?? this.config.cloud.instanceId,
|
|
48
|
+
nodeId: profile.nodeId ?? this.config.cloud.nodeId,
|
|
44
49
|
limits: {
|
|
45
50
|
readonly: input.readonly ?? true,
|
|
46
51
|
timeoutMs: resolveTimeoutMs(input.timeout_ms, this.config.limits.maxStatementMs),
|
|
47
52
|
maxRows: this.config.limits.maxRows,
|
|
48
53
|
maxColumns: this.config.limits.maxColumns,
|
|
49
54
|
maxFieldChars: this.config.limits.maxFieldChars,
|
|
55
|
+
maxResultBytes: this.config.limits.maxResultBytes,
|
|
56
|
+
maxBlobBytes: this.config.limits.maxBlobBytes,
|
|
50
57
|
},
|
|
51
58
|
};
|
|
52
59
|
}
|
|
@@ -5,6 +5,8 @@ export interface RuntimeLimits {
|
|
|
5
5
|
maxRows: number;
|
|
6
6
|
maxColumns: number;
|
|
7
7
|
maxFieldChars: number;
|
|
8
|
+
maxResultBytes?: number;
|
|
9
|
+
maxBlobBytes?: number;
|
|
8
10
|
}
|
|
9
11
|
export interface SessionContext {
|
|
10
12
|
task_id: string;
|
|
@@ -12,6 +14,11 @@ export interface SessionContext {
|
|
|
12
14
|
engine: DatabaseEngine;
|
|
13
15
|
database?: string;
|
|
14
16
|
schema?: string;
|
|
17
|
+
host?: string;
|
|
18
|
+
port?: number;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
instanceId?: string;
|
|
21
|
+
nodeId?: string;
|
|
15
22
|
limits: RuntimeLimits;
|
|
16
23
|
}
|
|
17
24
|
export interface DatasourceResolveInput {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SessionContext } from "../context/session-context.js";
|
|
2
|
+
import type { SqlExecutor } from "../executor/sql-executor.js";
|
|
3
|
+
import type { DiagnoseReplicationLagInput, DiagnosticResult } from "./types.js";
|
|
4
|
+
export declare function diagnoseReplicationLag(executor: SqlExecutor, input: DiagnoseReplicationLagInput, ctx: SessionContext): Promise<DiagnosticResult>;
|