taurusdb-core 0.4.0 → 0.5.0-rc.10

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -1
  3. package/dist/audit/jsonl-writer.d.ts +47 -0
  4. package/dist/audit/jsonl-writer.js +124 -0
  5. package/dist/auth/sql-profile-loader/env-source.js +6 -10
  6. package/dist/auth/sql-profile-loader/parsing.js +8 -5
  7. package/dist/auth/sql-profile-loader/runtime-override.d.ts +1 -0
  8. package/dist/auth/sql-profile-loader/runtime-override.js +19 -1
  9. package/dist/auth/sql-profile-loader/types.d.ts +5 -0
  10. package/dist/capability/probe.js +3 -1
  11. package/dist/cloud/auth.d.ts +1 -0
  12. package/dist/cloud/auth.js +37 -0
  13. package/dist/config/env.js +16 -0
  14. package/dist/config/schema.d.ts +78 -0
  15. package/dist/config/schema.js +19 -0
  16. package/dist/context/datasource-resolver.js +7 -0
  17. package/dist/context/session-context.d.ts +7 -0
  18. package/dist/diagnostics/replication-lag.d.ts +4 -0
  19. package/dist/diagnostics/replication-lag.js +138 -0
  20. package/dist/diagnostics/types.d.ts +5 -1
  21. package/dist/diagnostics/types.js +7 -7
  22. package/dist/engine/runtime.d.ts +2 -2
  23. package/dist/engine/runtime.js +8 -14
  24. package/dist/engine/types.d.ts +3 -2
  25. package/dist/engine.d.ts +5 -5
  26. package/dist/engine.js +32 -5
  27. package/dist/executor/bounded-sql.d.ts +1 -0
  28. package/dist/executor/bounded-sql.js +10 -0
  29. package/dist/executor/concurrency-limiter.d.ts +15 -0
  30. package/dist/executor/concurrency-limiter.js +67 -0
  31. package/dist/executor/connection-pool.d.ts +3 -2
  32. package/dist/executor/connection-pool.js +35 -24
  33. package/dist/executor/sql-executor.d.ts +3 -0
  34. package/dist/executor/sql-executor.js +52 -9
  35. package/dist/executor/types.d.ts +5 -1
  36. package/dist/index.d.ts +8 -3
  37. package/dist/index.js +5 -1
  38. package/dist/safety/confirmation-store.d.ts +30 -7
  39. package/dist/safety/confirmation-store.js +154 -30
  40. package/dist/safety/guardrail.d.ts +3 -0
  41. package/dist/safety/guardrail.js +16 -6
  42. package/dist/safety/redaction.d.ts +6 -0
  43. package/dist/safety/redaction.js +47 -6
  44. package/dist/safety/sql-classifier.d.ts +1 -0
  45. package/dist/safety/sql-classifier.js +1 -0
  46. package/dist/safety/sql-validator.d.ts +1 -0
  47. package/dist/safety/sql-validator.js +25 -1
  48. package/dist/schema/adapters/mysql.js +3 -1
  49. package/dist/taurus/flashback.js +4 -10
  50. package/dist/taurus/recycle-bin.js +2 -8
  51. package/dist/utils/formatter.d.ts +11 -2
  52. package/dist/utils/formatter.js +12 -3
  53. package/dist/utils/logger.js +8 -0
  54. package/dist/utils/mysql-identifier.d.ts +1 -0
  55. package/dist/utils/mysql-identifier.js +9 -0
  56. 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 confirmation flow
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
+ }
@@ -12,7 +12,8 @@ export function parseEngineFromDsnProtocol(protocol) {
12
12
  export function parseEnvProfile(env) {
13
13
  const dsn = asString(env.TAURUSDB_SQL_DSN);
14
14
  const explicitHost = asString(env.TAURUSDB_SQL_HOST);
15
- const profileName = asString(env.TAURUSDB_SQL_DATASOURCE) ?? "taurus_mcp";
15
+ const explicitProfileName = asString(env.TAURUSDB_SQL_DATASOURCE);
16
+ const profileName = explicitProfileName ?? "taurus_mcp";
16
17
  let engine;
17
18
  let host;
18
19
  let port;
@@ -40,6 +41,7 @@ export function parseEnvProfile(env) {
40
41
  }
41
42
  if (!dsn &&
42
43
  !explicitHost &&
44
+ !explicitProfileName &&
43
45
  !asString(env.TAURUSDB_SQL_USER) &&
44
46
  !asString(env.TAURUSDB_SQL_PASSWORD) &&
45
47
  !database) {
@@ -49,16 +51,13 @@ export function parseEnvProfile(env) {
49
51
  throw new Error("Failed to resolve SQL port from environment.");
50
52
  }
51
53
  username = username ?? asString(env.TAURUSDB_SQL_USER);
52
- if (!username) {
53
- throw new Error("Missing SQL username in environment. Set TAURUSDB_SQL_USER or include it in DSN.");
54
- }
55
54
  passwordRef =
56
55
  passwordRef ??
57
56
  (Object.hasOwn(env, "TAURUSDB_SQL_PASSWORD")
58
57
  ? parseCredentialRef(env.TAURUSDB_SQL_PASSWORD, "TAURUSDB_SQL_PASSWORD")
59
58
  : undefined);
60
- if (!passwordRef) {
61
- throw new Error("Missing SQL password in environment. Set TAURUSDB_SQL_PASSWORD or include it in DSN.");
59
+ if ((username && !passwordRef) || (!username && passwordRef)) {
60
+ throw new Error("SQL credentials require both username and password. Omit both to use the local database login page.");
62
61
  }
63
62
  const poolSize = asInteger(env.TAURUSDB_SQL_POOL_SIZE);
64
63
  if (poolSize !== undefined && poolSize <= 0) {
@@ -70,10 +69,7 @@ export function parseEnvProfile(env) {
70
69
  host,
71
70
  port,
72
71
  database,
73
- user: {
74
- username,
75
- password: passwordRef,
76
- },
72
+ user: username && passwordRef ? { username, password: passwordRef } : undefined,
77
73
  poolSize,
78
74
  });
79
75
  }
@@ -190,19 +190,20 @@ 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
- // Backward compatibility for older profile field names. New configs should use `user`.
199
+ // `user` is the session credential. Keep older read-only aliases for compatibility.
198
200
  const userRaw = value.user ??
199
201
  value.readonlyUser ??
200
202
  value.readonly ??
201
203
  value.readOnlyUser;
202
- if (userRaw === undefined) {
203
- throw new Error(`Invalid datasource profile ${name} in ${context}: missing user.`);
204
- }
205
- const user = parseUserCredential(userRaw, `${context}.${name}.user`);
204
+ const user = userRaw === undefined
205
+ ? undefined
206
+ : parseUserCredential(userRaw, `${context}.${name}.user`);
206
207
  const tls = parseTlsOptions(value.tls, `${context}.${name}.tls`);
207
208
  return withRedactedToString({
208
209
  name,
@@ -210,6 +211,8 @@ export function parseProfileRecord(name, value, context) {
210
211
  host,
211
212
  port,
212
213
  database,
214
+ instanceId,
215
+ nodeId,
213
216
  user,
214
217
  tls,
215
218
  poolSize,
@@ -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
- return this.runtimeTargets.get(name);
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,6 +31,9 @@ export interface DataSourceProfile {
31
31
  host?: string;
32
32
  port: number;
33
33
  database?: string;
34
+ instanceId?: string;
35
+ nodeId?: string;
36
+ /** Session credential used by guarded query tools and the human-gated recovery path. */
34
37
  user?: UserCredential;
35
38
  tls?: TlsOptions;
36
39
  poolSize?: number;
@@ -45,11 +48,13 @@ export interface RuntimeDataSourceTarget {
45
48
  host?: string;
46
49
  port?: number;
47
50
  database?: string;
51
+ user?: UserCredential;
48
52
  instanceId?: string;
49
53
  nodeId?: string;
50
54
  }
51
55
  export interface RuntimeTargetProfileLoader extends ProfileLoader {
52
56
  setRuntimeTarget(name: string, target: RuntimeDataSourceTarget): void;
57
+ clearRuntimeUser(name: string): void;
53
58
  clearRuntimeTarget(name: string): void;
54
59
  clearAllRuntimeTargets(): void;
55
60
  getRuntimeTarget(name: string): RuntimeDataSourceTarget | undefined;
@@ -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);
@@ -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 {
@@ -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
  }
@@ -147,10 +147,26 @@ 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
+ dynamicTargetsEnabled: parseBoolean(env.TAURUSDB_ENABLE_DYNAMIC_TARGETS, "TAURUSDB_ENABLE_DYNAMIC_TARGETS"),
164
+ recycleBinRestoreEnabled: parseBoolean(env.TAURUSDB_ENABLE_RECYCLE_BIN_RESTORE, "TAURUSDB_ENABLE_RECYCLE_BIN_RESTORE"),
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"),
168
+ credentialIdleTtlMinutes: parseInteger(env.TAURUSDB_SQL_CREDENTIAL_IDLE_TTL_MINUTES, "TAURUSDB_SQL_CREDENTIAL_IDLE_TTL_MINUTES"),
169
+ credentialMaxTtlMinutes: parseInteger(env.TAURUSDB_SQL_CREDENTIAL_MAX_TTL_MINUTES, "TAURUSDB_SQL_CREDENTIAL_MAX_TTL_MINUTES"),
154
170
  },
155
171
  slowSqlSource: {
156
172
  taurusApi: {
@@ -62,26 +62,72 @@ 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
+ dynamicTargetsEnabled: z.ZodDefault<z.ZodBoolean>;
109
+ recycleBinRestoreEnabled: z.ZodDefault<z.ZodBoolean>;
110
+ requireTls: z.ZodDefault<z.ZodBoolean>;
111
+ approvalSecretPath: z.ZodOptional<z.ZodString>;
112
+ approvalTtlSeconds: z.ZodDefault<z.ZodNumber>;
113
+ credentialIdleTtlMinutes: z.ZodDefault<z.ZodNumber>;
114
+ credentialMaxTtlMinutes: z.ZodDefault<z.ZodNumber>;
115
+ }, "strip", z.ZodTypeAny, {
116
+ dynamicTargetsEnabled: boolean;
117
+ recycleBinRestoreEnabled: boolean;
118
+ requireTls: boolean;
119
+ approvalTtlSeconds: number;
120
+ credentialIdleTtlMinutes: number;
121
+ credentialMaxTtlMinutes: number;
122
+ approvalSecretPath?: string | undefined;
123
+ }, {
124
+ dynamicTargetsEnabled?: boolean | undefined;
125
+ recycleBinRestoreEnabled?: boolean | undefined;
126
+ requireTls?: boolean | undefined;
127
+ approvalSecretPath?: string | undefined;
128
+ approvalTtlSeconds?: number | undefined;
129
+ credentialIdleTtlMinutes?: number | undefined;
130
+ credentialMaxTtlMinutes?: number | undefined;
85
131
  }>>;
86
132
  slowSqlSource: z.ZodDefault<z.ZodObject<{
87
133
  taurusApi: z.ZodDefault<z.ZodObject<{
@@ -305,10 +351,26 @@ export declare const ConfigSchema: z.ZodObject<{
305
351
  maxColumns: number;
306
352
  maxStatementMs: number;
307
353
  maxFieldChars: number;
354
+ maxResultBytes: number;
355
+ maxBlobBytes: number;
356
+ maxConcurrentQueries: number;
357
+ maxQueuedQueries: number;
358
+ queueTimeoutMs: number;
308
359
  };
309
360
  audit: {
310
361
  logPath: string;
311
362
  includeRawSql: boolean;
363
+ maxBytes: number;
364
+ maxFiles: number;
365
+ };
366
+ security: {
367
+ dynamicTargetsEnabled: boolean;
368
+ recycleBinRestoreEnabled: boolean;
369
+ requireTls: boolean;
370
+ approvalTtlSeconds: number;
371
+ credentialIdleTtlMinutes: number;
372
+ credentialMaxTtlMinutes: number;
373
+ approvalSecretPath?: string | undefined;
312
374
  };
313
375
  slowSqlSource: {
314
376
  taurusApi: {
@@ -382,10 +444,26 @@ export declare const ConfigSchema: z.ZodObject<{
382
444
  maxColumns?: number | undefined;
383
445
  maxStatementMs?: number | undefined;
384
446
  maxFieldChars?: number | undefined;
447
+ maxResultBytes?: number | undefined;
448
+ maxBlobBytes?: number | undefined;
449
+ maxConcurrentQueries?: number | undefined;
450
+ maxQueuedQueries?: number | undefined;
451
+ queueTimeoutMs?: number | undefined;
385
452
  } | undefined;
386
453
  audit?: {
387
454
  logPath?: string | undefined;
388
455
  includeRawSql?: boolean | undefined;
456
+ maxBytes?: number | undefined;
457
+ maxFiles?: number | undefined;
458
+ } | undefined;
459
+ security?: {
460
+ dynamicTargetsEnabled?: boolean | undefined;
461
+ recycleBinRestoreEnabled?: boolean | undefined;
462
+ requireTls?: boolean | undefined;
463
+ approvalSecretPath?: string | undefined;
464
+ approvalTtlSeconds?: number | undefined;
465
+ credentialIdleTtlMinutes?: number | undefined;
466
+ credentialMaxTtlMinutes?: number | undefined;
389
467
  } | undefined;
390
468
  slowSqlSource?: {
391
469
  taurusApi?: {
@@ -5,12 +5,30 @@ 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
+ dynamicTargetsEnabled: z.boolean().default(true),
26
+ recycleBinRestoreEnabled: z.boolean().default(true),
27
+ requireTls: z.boolean().default(false),
28
+ approvalSecretPath: z.string().min(1).optional(),
29
+ approvalTtlSeconds: z.number().int().positive().max(3600).default(300),
30
+ credentialIdleTtlMinutes: z.number().int().positive().max(30).default(30),
31
+ credentialMaxTtlMinutes: z.number().int().positive().max(480).default(480),
14
32
  })
15
33
  .default({});
16
34
  const CloudSchema = z
@@ -89,6 +107,7 @@ export const ConfigSchema = z.object({
89
107
  cloud: CloudSchema,
90
108
  limits: LimitsSchema,
91
109
  audit: AuditSchema,
110
+ security: SecuritySchema,
92
111
  slowSqlSource: z
93
112
  .object({
94
113
  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
  }