@mokoenterprises/mokomysql-mcp 0.0.0-stage → 2.7.0

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 (46) hide show
  1. package/LICENSE +696 -0
  2. package/README.md +177 -2
  3. package/config.example.json +38 -0
  4. package/dist/README.md +7 -0
  5. package/dist/client.d.ts +71 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +236 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/config.d.ts +21 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +92 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/guards.d.ts +74 -0
  14. package/dist/guards.d.ts.map +1 -0
  15. package/dist/guards.js +269 -0
  16. package/dist/guards.js.map +1 -0
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1017 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/migrate.d.ts +57 -0
  22. package/dist/migrate.d.ts.map +1 -0
  23. package/dist/migrate.js +224 -0
  24. package/dist/migrate.js.map +1 -0
  25. package/dist/secrets.d.ts +8 -0
  26. package/dist/secrets.d.ts.map +1 -0
  27. package/dist/secrets.js +164 -0
  28. package/dist/secrets.js.map +1 -0
  29. package/dist/state.d.ts +13 -0
  30. package/dist/state.d.ts.map +1 -0
  31. package/dist/state.js +59 -0
  32. package/dist/state.js.map +1 -0
  33. package/dist/types.d.ts +157 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +16 -0
  36. package/dist/types.js.map +1 -0
  37. package/package.json +42 -4
  38. package/source/client.ts +275 -0
  39. package/source/config.ts +104 -0
  40. package/source/guards.ts +264 -0
  41. package/source/index.ts +1434 -0
  42. package/source/migrate.ts +263 -0
  43. package/source/secrets.ts +163 -0
  44. package/source/state.ts +62 -0
  45. package/source/types.ts +176 -0
  46. package/tsconfig.json +19 -0
package/README.md CHANGED
@@ -1,3 +1,178 @@
1
- # Temporary Holding Version
1
+ # mokomysql-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Model Context Protocol (MCP) server for MySQL database management — run queries, inspect
4
+ and modify schema, manage users, perform maintenance, and use Joomla-aware helpers, all
5
+ exposed as MCP tools that AI assistants and MCP clients can call.
6
+
7
+ ## Features
8
+
9
+ - Execute SQL queries against a configured MySQL/MariaDB database
10
+ - Inspect and manage schema (tables, columns, indexes)
11
+ - User and privilege management
12
+ - Maintenance operations (analyze, optimize, repair)
13
+ - Joomla-specific helpers for common CMS database tasks
14
+
15
+ ## Requirements
16
+
17
+ - An MCP-capable client (for example, Claude Code or another MCP host)
18
+ - Network access to a MySQL or MariaDB server
19
+ - Database credentials with the privileges required for the operations you intend to run
20
+
21
+ ## Installation
22
+
23
+ The server is published to npm as `@mokoenterprises/mokomysql-mcp`. No manual clone or
24
+ build is required — your MCP client runs it on demand with `npx`:
25
+
26
+ ```bash
27
+ npx -y @mokoenterprises/mokomysql-mcp
28
+ ```
29
+
30
+ Or install it globally:
31
+
32
+ ```bash
33
+ npm install -g @mokoenterprises/mokomysql-mcp
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ Connections are read from a JSON config file at `~/.mcp_mokomysql.json` (override the path
39
+ with the `MYSQL_MCP_CONFIG` environment variable). See [`config.example.json`](config.example.json):
40
+
41
+ ```json
42
+ {
43
+ "defaultConnection": "local",
44
+ "connections": {
45
+ "local": {
46
+ "host": "127.0.0.1",
47
+ "port": 3306,
48
+ "user": "dbuser",
49
+ "password": "secret",
50
+ "database": "joomla",
51
+ "ssl": false
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ Full configuration reference is in the wiki — docs are **wiki-first** at MokoEnterprises:
58
+
59
+ **→ [Configuration (wiki)](https://git.mokoenterprises.us/MokoEnterprises/mokomysql-mcp/wiki/Configuration)**
60
+
61
+ It covers TLS options, environment variables (`MYSQL_MCP_CONFIG`, `MYSQL_MCP_STATE`), the sidecar
62
+ state file, and **Joomla write safety** — writes to a Joomla database require a two-step
63
+ `confirm_token` (the first call returns a token and does not execute); reads are never gated.
64
+
65
+ The write gate is **operation-aware**. The two-step `confirm_token` is required for *every* Joomla
66
+ write, but the "raw SQL can corrupt the ACL nested set" warning is only shown for the operations
67
+ that can actually cause it. Joomla creates, removes, and renumbers `#__assets` / nested-set rows
68
+ only when a row is **created or deleted** through its Table API (`Table::store()` / `Table::delete()`),
69
+ which raw SQL bypasses — so:
70
+
71
+ - A pure **in-place `UPDATE`** that does not reference a nested-set table (`#__assets`, `#__categories`,
72
+ `#__menu`) gets a lighter message: it still needs the token, but it cannot touch the asset tree.
73
+ - **`INSERT` / `DELETE`** of an asset-bearing row (any table with an `asset_id` column), **DDL**, and
74
+ **any write to a nested-set table** keep the full nested-set/ACL warning and the integrity reminder.
75
+
76
+ Additional fail-safes:
77
+
78
+ - **Hard block on raw `INSERT`/`DELETE` into `#__assets`.** The ACL asset tree is never correct to
79
+ hand-edit, so those statements are refused — the `confirm_token` cannot authorize them. A deliberate,
80
+ verified repair can override with `force: true` on `mysql_query_execute`.
81
+ - **Automatic post-write integrity check.** After a confirmed structural write to a nested-set table,
82
+ the server verifies the tree in place and reports pass/fail: contiguity, no duplicate `lft`/`rgt`,
83
+ no `lft >= rgt`, and every child fully within its parent's interval. The contiguity formula is
84
+ **root-base aware** — a valid tree has `MAX(rgt) = 2N − 1` when 0-based (`MIN(lft) = 0`, as Joomla's
85
+ `#__assets` and `#__menu` roots are) and `2N` only when 1-based. (The earlier blanket `MAX(rgt) = 2N`
86
+ hint was wrong for Joomla and flagged healthy trees.)
87
+ - **Configurable nested-set tables.** Beyond the Joomla defaults (`assets`, `categories`, `menu`), a
88
+ connection may list extra `nestedSetSuffixes`; any table named `*_nested` is also covered by convention.
89
+
90
+ ### Table-name write guards (`tableGuards`)
91
+
92
+ Beyond whole-database Joomla detection, you can guard **specific tables by regex** — globally and/or
93
+ per connection (the lists are UNIONed). Patterns are case-insensitive; anchor them (`^name$`) for
94
+ exact matches.
95
+
96
+ - **`hardBlock`** — a write touching a matching table is **hard-blocked** and **fails loudly**
97
+ (returned as a tool error, `isError: true`). The block is **absolute**: no `confirm`, `confirm_token`,
98
+ or `force` overrides it, and the MCP exposes no tool to change it at runtime — **an AI agent cannot
99
+ bypass or disable it.** The only way to write such a table is for a human to remove the pattern from
100
+ the config file.
101
+ - **`doubleConfirm`** — a write touching a matching table requires the two-step `confirm_token`
102
+ handshake on **any** database (the same gate Joomla DBs get, scoped to chosen tables). Neutral framing.
103
+ - **`warn`** — same two-step `confirm_token` gate as `doubleConfirm`, but the challenge also carries a
104
+ prominent **sensitivity warning** (the agent cannot suppress it). Use for editable-but-risky tables
105
+ (config/state, auth, anything with downstream side effects).
106
+ - **`joomlaAssetTables`** — policy for the tables the server auto-learns as asset-affecting on a
107
+ Joomla target (every table with an `asset_id` column, plus `<prefix>assets`/`<prefix>categories`/
108
+ `<prefix>menu`): `"block"` (default — absolute hard write-block), `"confirm"` (two-step token), or
109
+ `"off"`. Layers **on top of** the database-wide Joomla gate and the targeted `#__assets`
110
+ INSERT/DELETE block, both of which still apply.
111
+
112
+ The **hard-block tier is fail-closed**: it matches a protected pattern against *every* identifier in
113
+ the (comment-stripped, versioned-comment-aware) statement — not just recognized table positions — so
114
+ comma-lists or exotic syntax can't slip a protected table past it, and a whole-database `DROP DATABASE`
115
+ enumerates the schema's tables (refusing if it can't).
116
+
117
+ ```json
118
+ {
119
+ "tableGuards": {
120
+ "hardBlock": ["^audit_log$", "_ledger$"],
121
+ "doubleConfirm": ["^wp_users$"],
122
+ "warn": ["_config$", "_session$"],
123
+ "joomlaAssetTables": "block"
124
+ },
125
+ "connections": { "...": { "tableGuards": { "hardBlock": ["_session$"] } } }
126
+ }
127
+ ```
128
+
129
+ An invalid guard regex is logged to stderr and skipped — it never crashes the server or disables the
130
+ other guards.
131
+
132
+ ### Exports and the `mysql_export_table_sql` replay foot-gun
133
+
134
+ `mysql_export_table_sql` produces a self-contained SQL dump whose output **begins with
135
+ `DROP TABLE IF EXISTS <table>;`** and whose rows are emitted as hand-quoted `INSERT` statements
136
+ (not parameterized). This is convenient for a one-shot restore, but **replaying the dump drops the
137
+ existing table — and all of its current rows — before recreating it.** Never run the output against
138
+ a database where the target table already holds data you intend to keep, and treat the file as
139
+ destructive input. Values are escaped only for single quotes, not full binary-safe encoding, so for
140
+ authoritative or binary-heavy backups prefer `mysqldump`.
141
+
142
+ ## Usage
143
+
144
+ Register the server with your MCP client. A typical MCP client configuration entry looks like:
145
+
146
+ ```json
147
+ {
148
+ "mcpServers": {
149
+ "mokomysql": {
150
+ "command": "npx",
151
+ "args": ["-y", "@mokoenterprises/mokomysql-mcp"],
152
+ "env": {
153
+ "MYSQL_MCP_CONFIG": "/home/you/.mcp_mokomysql.json",
154
+ "MYSQL_MCP_STATE": "/home/you/.mcp_mokomysql.state.json"
155
+ }
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ The `env` block is where the config and sidecar paths belong — server-instance settings, kept out
162
+ of any project repository (both are optional; see the [Configuration wiki](https://git.mokoenterprises.us/MokoEnterprises/mokomysql-mcp/wiki/Configuration)).
163
+ Once connected, the client can call the server's tools to query data, inspect schema, manage
164
+ users, run maintenance, and invoke the Joomla helpers.
165
+
166
+ ## Contributing
167
+
168
+ Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) and follow the
169
+ [MokoStandards](https://git.mokoenterprises.us/MokoEnterprises/mokocli/wiki/Home) for
170
+ coding style, commit conventions, and the pull request process.
171
+
172
+ ## License
173
+
174
+ Licensed under GPL-3.0-or-later — see [LICENSE](LICENSE).
175
+
176
+ ---
177
+
178
+ *[Moko Enterprises](https://mokoenterprises.us)*
@@ -0,0 +1,38 @@
1
+ {
2
+ "_comment": "No-inline-secrets policy (MokoCLI #1043): every password must be a file-backed ref, 'file:~/.ssh/tokens/<name>.token'. The referenced file holds the RAW password (no JSON, no trailing newline). An inline 'password' literal still works but is auto-migrated to a token file on first run (config rewritten, original kept at .bak). Legacy inline form, deprecated: \"password\": \"<raw-password>\".",
3
+ "_comment_tableGuards": "Optional table-name regex write guards (case-insensitive; anchor with ^...$ for exact matches). 'hardBlock' = absolute block: the write fails loudly and NO confirm/token/force can override it (an AI agent cannot bypass it — only editing this file removes the block). 'doubleConfirm' = two-step confirm_token on any DB. 'warn' = two-step confirm_token PLUS a prominent sensitivity warning. 'joomlaAssetTables' policy applies to auto-learned asset_id-bearing + nested-set tables: 'block' (default), 'confirm', or 'off'. Set globally and/or per-connection (lists are UNIONed).",
4
+ "defaultConnection": "local",
5
+ "tableGuards": {
6
+ "hardBlock": ["^audit_log$", "_ledger$"],
7
+ "doubleConfirm": ["^wp_users$"],
8
+ "warn": ["_config$", "_session$"],
9
+ "joomlaAssetTables": "block"
10
+ },
11
+ "connections": {
12
+ "local": {
13
+ "host": "127.0.0.1",
14
+ "port": 3306,
15
+ "user": "root",
16
+ "password": "file:~/.ssh/tokens/mysql-local-password.token",
17
+ "database": "mysql",
18
+ "ssl": false,
19
+ "timezone": "Z",
20
+ "tags": ["localhost", "dev-db"]
21
+ },
22
+ "joomla-site": {
23
+ "host": "db.example.com",
24
+ "port": 3306,
25
+ "user": "joomla",
26
+ "password": "file:~/.ssh/tokens/JOOMLA.db.token",
27
+ "database": "joomla_prod",
28
+ "ssl": true,
29
+ "joomla": true,
30
+ "joomlaPrefix": "vkw4n_",
31
+ "tags": ["prod"],
32
+ "tableGuards": {
33
+ "hardBlock": ["_session$"],
34
+ "joomlaAssetTables": "block"
35
+ }
36
+ }
37
+ }
38
+ }
package/dist/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # dist/
2
+
3
+ Distributable artifacts live here - the packaged installer(s) and release
4
+ bundles emitted by the **mokocli-centric build system** (mokocli clones and runs
5
+ the shared build tooling in CI). Generated output, not source.
6
+
7
+ Only this `README.md` is tracked; everything else under `dist/` is git-ignored.
@@ -0,0 +1,71 @@
1
+ import type { FieldPacket } from 'mysql2/promise';
2
+ import { type ResolvedGuards } from './guards.js';
3
+ import type { MySqlConfig } from './types.js';
4
+ /** Result of probing a (connection, database) pair for Joomla-ness. */
5
+ export interface JoomlaDetection {
6
+ /** Whether this target is treated as a Joomla database. */
7
+ isJoomla: boolean;
8
+ /** The live table prefix (e.g. "jos_", "vkw4n_"), when known. */
9
+ prefix: string | null;
10
+ /**
11
+ * Unqualified names of the asset-bearing tables (every table with an `asset_id`
12
+ * column + the nested-set tables). Empty when not Joomla or not yet learned.
13
+ */
14
+ assetTables: string[];
15
+ /** How the verdict was reached — for surfacing in warnings. */
16
+ source: 'config' | 'marker' | 'auto' | 'none';
17
+ }
18
+ export declare class MysqlClient {
19
+ private pools;
20
+ private config;
21
+ /** Memoized Joomla verdicts, keyed by `${connectionKey}::${schema}`. */
22
+ private joomlaCache;
23
+ constructor(config: MySqlConfig);
24
+ /**
25
+ * Resolve the canonical identity of a target for binding/keying: the config
26
+ * connection key and the effective schema (explicit database or the connection
27
+ * default). Keeps callers consistent with how detection and markers are keyed.
28
+ */
29
+ resolveIdentity(connectionName?: string, database?: string): {
30
+ connKey: string;
31
+ schema: string;
32
+ };
33
+ /**
34
+ * Extra nested-set table suffixes configured for a connection (beyond the Joomla
35
+ * defaults). Lets the structural write gate and integrity check cover custom
36
+ * nested-set tables without code changes.
37
+ */
38
+ nestedSetSuffixesFor(connectionName?: string): string[];
39
+ /**
40
+ * Determine whether a target is a Joomla database, so writes can be gated.
41
+ * Resolution order: in-memory cache → explicit per-connection `joomla` flag
42
+ * (authoritative) → persisted sidecar marker (learned on a prior connect) →
43
+ * live schema probe for the Joomla signature (`<prefix>extensions` paired with
44
+ * `<prefix>assets`). A fresh probe result is persisted as a marker so future
45
+ * connects skip the round-trip entirely.
46
+ */
47
+ detectJoomla(connectionName?: string, database?: string): Promise<JoomlaDetection>;
48
+ /**
49
+ * Learn the asset-bearing tables for a schema: every table carrying an
50
+ * `asset_id` column (the Joomla ACL coupling — Table.php:208-209), plus the
51
+ * nested-set tables `<prefix>assets`/`<prefix>categories`/`<prefix>menu` (which
52
+ * carry lft/rgt invariants even where asset_id is absent). Best-effort: a failed
53
+ * probe degrades to whatever prefix-derived nested-set names we can name.
54
+ */
55
+ private probeAssetTables;
56
+ /** Effective table write guards for a connection (global ∪ per-connection). */
57
+ resolveGuards(connectionName?: string): ResolvedGuards;
58
+ private cache;
59
+ private poolFor;
60
+ query(sql: string, params?: unknown[], connectionName?: string, database?: string): Promise<{
61
+ rows: Record<string, unknown>[];
62
+ fields: FieldPacket[];
63
+ }>;
64
+ execute(sql: string, params?: unknown[], connectionName?: string, database?: string): Promise<{
65
+ affectedRows: number;
66
+ insertId: number;
67
+ changedRows: number;
68
+ }>;
69
+ closeAll(): Promise<void>;
70
+ }
71
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../source/client.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAqB,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAEtF,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAK/D,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC/B,2DAA2D;IAC3D,QAAQ,EAAE,OAAO,CAAC;IAClB,iEAAiE;IACjE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,+DAA+D;IAC/D,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;CAC9C;AAED,qBAAa,WAAW;IACvB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,MAAM,CAAc;IAC5B,wEAAwE;IACxE,OAAO,CAAC,WAAW,CAA2C;gBAElD,MAAM,EAAE,WAAW;IAI/B;;;;OAIG;IACH,eAAe,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAKhG;;;;OAIG;IACH,oBAAoB,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAKvD;;;;;;;OAOG;IACG,YAAY,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAiExF;;;;;;OAMG;YACW,gBAAgB;IAqB9B,+EAA+E;IAC/E,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,cAAc;IAKtD,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,OAAO;IAoCT,KAAK,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,EAClB,cAAc,CAAC,EAAE,MAAM,EACvB,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QAAC,MAAM,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;IAiBhE,OAAO,CACZ,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,EAClB,cAAc,CAAC,EAAE,MAAM,EACvB,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBrE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM/B"}
package/dist/client.js ADDED
@@ -0,0 +1,236 @@
1
+ /* Copyright (C) 2026 Moko Enterprises <hello@mokoenterprises.us>
2
+ *
3
+ * This file is part of a Moko Enterprises project.
4
+ *
5
+ * SPDX-License-Identifier: GPL-3.0-or-later
6
+ *
7
+ * FILE INFORMATION
8
+ * DEFGROUP: mokomysql.Client
9
+ * INGROUP: mokomysql
10
+ * REPO: https://git.mokoenterprises.us/MokoEnterprises/mokomysql-mcp
11
+ * PATH: /src/client.ts
12
+ * VERSION: 01.00.00
13
+ * BRIEF: MySQL client with connection pool management
14
+ */
15
+ import mysql from 'mysql2/promise';
16
+ import { getConnection } from './config.js';
17
+ import { resolveGuards } from './guards.js';
18
+ import { getMarker, markerKey, setMarker } from './state.js';
19
+ /** The Joomla nested-set tables, as bare suffixes, always treated as asset-affecting. */
20
+ const NESTED_SET_SUFFIXES = ['assets', 'categories', 'menu'];
21
+ export class MysqlClient {
22
+ pools = new Map();
23
+ config;
24
+ /** Memoized Joomla verdicts, keyed by `${connectionKey}::${schema}`. */
25
+ joomlaCache = new Map();
26
+ constructor(config) {
27
+ this.config = config;
28
+ }
29
+ /**
30
+ * Resolve the canonical identity of a target for binding/keying: the config
31
+ * connection key and the effective schema (explicit database or the connection
32
+ * default). Keeps callers consistent with how detection and markers are keyed.
33
+ */
34
+ resolveIdentity(connectionName, database) {
35
+ const { key, conn } = getConnection(this.config, connectionName);
36
+ return { connKey: key, schema: database ?? conn.database ?? '' };
37
+ }
38
+ /**
39
+ * Extra nested-set table suffixes configured for a connection (beyond the Joomla
40
+ * defaults). Lets the structural write gate and integrity check cover custom
41
+ * nested-set tables without code changes.
42
+ */
43
+ nestedSetSuffixesFor(connectionName) {
44
+ const { conn } = getConnection(this.config, connectionName);
45
+ return conn.nestedSetSuffixes ?? [];
46
+ }
47
+ /**
48
+ * Determine whether a target is a Joomla database, so writes can be gated.
49
+ * Resolution order: in-memory cache → explicit per-connection `joomla` flag
50
+ * (authoritative) → persisted sidecar marker (learned on a prior connect) →
51
+ * live schema probe for the Joomla signature (`<prefix>extensions` paired with
52
+ * `<prefix>assets`). A fresh probe result is persisted as a marker so future
53
+ * connects skip the round-trip entirely.
54
+ */
55
+ async detectJoomla(connectionName, database) {
56
+ const { key, conn } = getConnection(this.config, connectionName);
57
+ const schema = database ?? conn.database ?? '';
58
+ const cacheKey = `${key}::${schema}`;
59
+ const cached = this.joomlaCache.get(cacheKey);
60
+ if (cached)
61
+ return cached;
62
+ // Explicit config flag is authoritative for the VERDICT — no detection probe,
63
+ // and it overrides any marker. We still learn the asset-bearing tables when a
64
+ // schema is resolvable, so the table-level hard-block/confirm guards can apply.
65
+ if (conn.joomla === true) {
66
+ const prefix = conn.joomlaPrefix ?? null;
67
+ const assetTables = schema ? await this.probeAssetTables(schema, prefix, connectionName) : [];
68
+ return this.cache(cacheKey, { isJoomla: true, prefix, assetTables, source: 'config' });
69
+ }
70
+ if (conn.joomla === false) {
71
+ return this.cache(cacheKey, { isJoomla: false, prefix: null, assetTables: [], source: 'config' });
72
+ }
73
+ // Without a resolvable target schema we cannot probe or key a marker.
74
+ if (!schema) {
75
+ return this.cache(cacheKey, { isJoomla: false, prefix: null, assetTables: [], source: 'none' });
76
+ }
77
+ // Learned marker from a previous connect — instant, no round-trip.
78
+ const mKey = markerKey(conn.host, conn.port ?? 3306, schema);
79
+ const marker = await getMarker(mKey);
80
+ if (marker) {
81
+ let assetTables = marker.assetTables ?? [];
82
+ // Upgrade a pre-feature marker (no assetTables field) once: learn and persist
83
+ // the asset tables so the hard-block/confirm guards apply without a re-detect.
84
+ if (marker.joomla && marker.assetTables === undefined) {
85
+ assetTables = await this.probeAssetTables(schema, marker.prefix, connectionName);
86
+ await setMarker(mKey, { ...marker, assetTables });
87
+ }
88
+ return this.cache(cacheKey, { isJoomla: marker.joomla, prefix: marker.prefix, assetTables, source: 'marker' });
89
+ }
90
+ try {
91
+ const { rows } = await this.query("SELECT TABLE_NAME AS name FROM information_schema.TABLES " +
92
+ "WHERE TABLE_SCHEMA = ? AND TABLE_NAME REGEXP '(extensions|assets)$'", [schema], connectionName);
93
+ const names = new Set(rows.map((r) => String(r.name)));
94
+ let prefix = null;
95
+ for (const name of names) {
96
+ if (!name.endsWith('extensions'))
97
+ continue;
98
+ const candidate = name.slice(0, -'extensions'.length);
99
+ if (names.has(`${candidate}assets`)) {
100
+ prefix = candidate;
101
+ break;
102
+ }
103
+ }
104
+ const assetTables = prefix !== null ? await this.probeAssetTables(schema, prefix, connectionName) : [];
105
+ const verdict = prefix !== null
106
+ ? { isJoomla: true, prefix, assetTables, source: 'auto' }
107
+ : { isJoomla: false, prefix: null, assetTables: [], source: 'auto' };
108
+ // Persist what we learned so the next connect just knows.
109
+ await setMarker(mKey, { joomla: verdict.isJoomla, prefix: verdict.prefix, assetTables, detectedAt: new Date().toISOString() });
110
+ return this.cache(cacheKey, verdict);
111
+ }
112
+ catch {
113
+ // Probe failed (permissions, missing schema). Degrade to "none" and do
114
+ // not cache or persist, so a later successful probe can still classify it.
115
+ return { isJoomla: false, prefix: null, assetTables: [], source: 'none' };
116
+ }
117
+ }
118
+ /**
119
+ * Learn the asset-bearing tables for a schema: every table carrying an
120
+ * `asset_id` column (the Joomla ACL coupling — Table.php:208-209), plus the
121
+ * nested-set tables `<prefix>assets`/`<prefix>categories`/`<prefix>menu` (which
122
+ * carry lft/rgt invariants even where asset_id is absent). Best-effort: a failed
123
+ * probe degrades to whatever prefix-derived nested-set names we can name.
124
+ */
125
+ async probeAssetTables(schema, prefix, connectionName) {
126
+ const found = new Set();
127
+ if (prefix !== null) {
128
+ for (const suffix of NESTED_SET_SUFFIXES)
129
+ found.add(`${prefix}${suffix}`);
130
+ }
131
+ try {
132
+ const { rows } = await this.query("SELECT DISTINCT TABLE_NAME AS name FROM information_schema.COLUMNS " +
133
+ "WHERE TABLE_SCHEMA = ? AND COLUMN_NAME = 'asset_id'", [schema], connectionName);
134
+ for (const r of rows) {
135
+ const name = r.name;
136
+ if (typeof name === 'string' && name)
137
+ found.add(name);
138
+ }
139
+ }
140
+ catch {
141
+ // Permissions / missing schema — keep the prefix-derived nested-set names.
142
+ }
143
+ return [...found];
144
+ }
145
+ /** Effective table write guards for a connection (global ∪ per-connection). */
146
+ resolveGuards(connectionName) {
147
+ const { conn } = getConnection(this.config, connectionName);
148
+ return resolveGuards(this.config, conn);
149
+ }
150
+ cache(cacheKey, verdict) {
151
+ this.joomlaCache.set(cacheKey, verdict);
152
+ return verdict;
153
+ }
154
+ poolFor(connectionName) {
155
+ const { key, conn } = getConnection(this.config, connectionName);
156
+ let pool = this.pools.get(key);
157
+ if (!pool) {
158
+ const opts = {
159
+ host: conn.host,
160
+ port: conn.port ?? 3306,
161
+ user: conn.user,
162
+ password: conn.password,
163
+ database: conn.database,
164
+ connectionLimit: 5,
165
+ waitForConnections: true,
166
+ timezone: conn.timezone ?? 'Z',
167
+ multipleStatements: false,
168
+ };
169
+ if (conn.ssl) {
170
+ // Default to verified TLS. A bare `ssl: true` is never silently
171
+ // downgraded — callers who must skip verification (trusted internal
172
+ // hosts with self-signed certs) opt out explicitly via
173
+ // `ssl: { rejectUnauthorized: false }` in their config.
174
+ opts.ssl = typeof conn.ssl === 'object'
175
+ ? conn.ssl
176
+ : { rejectUnauthorized: true };
177
+ }
178
+ pool = mysql.createPool(opts);
179
+ this.pools.set(key, pool);
180
+ // On first connect, learn (and persist) the Joomla verdict for the
181
+ // connection's default database so the write-gate knows immediately.
182
+ // Best-effort and non-blocking — never let it break pool creation.
183
+ if (conn.database) {
184
+ void this.detectJoomla(connectionName, conn.database).catch(() => undefined);
185
+ }
186
+ }
187
+ return pool;
188
+ }
189
+ async query(sql, params, connectionName, database) {
190
+ const pool = this.poolFor(connectionName);
191
+ const p = (params ?? []);
192
+ if (database) {
193
+ const conn = await pool.getConnection();
194
+ try {
195
+ await conn.query(`USE \`${database.replace(/`/g, '``')}\``);
196
+ const [rows, fields] = await conn.query(sql, p);
197
+ return { rows: rows, fields };
198
+ }
199
+ finally {
200
+ conn.release();
201
+ }
202
+ }
203
+ const [rows, fields] = await pool.query(sql, p);
204
+ return { rows: rows, fields };
205
+ }
206
+ async execute(sql, params, connectionName, database) {
207
+ const pool = this.poolFor(connectionName);
208
+ const p = (params ?? []);
209
+ if (database) {
210
+ const conn = await pool.getConnection();
211
+ try {
212
+ await conn.query(`USE \`${database.replace(/`/g, '``')}\``);
213
+ const [result] = await conn.execute(sql, p);
214
+ const r = result;
215
+ return { affectedRows: r.affectedRows ?? 0, insertId: r.insertId ?? 0, changedRows: r.changedRows ?? 0 };
216
+ }
217
+ finally {
218
+ conn.release();
219
+ }
220
+ }
221
+ const [result] = await pool.execute(sql, p);
222
+ const r = result;
223
+ return {
224
+ affectedRows: r.affectedRows ?? 0,
225
+ insertId: r.insertId ?? 0,
226
+ changedRows: r.changedRows ?? 0,
227
+ };
228
+ }
229
+ async closeAll() {
230
+ for (const [, pool] of this.pools) {
231
+ await pool.end();
232
+ }
233
+ this.pools.clear();
234
+ }
235
+ }
236
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../source/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,yFAAyF;AACzF,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAU,CAAC;AAiBtE,MAAM,OAAO,WAAW;IACf,KAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;IACrC,MAAM,CAAc;IAC5B,wEAAwE;IAChE,WAAW,GAAiC,IAAI,GAAG,EAAE,CAAC;IAE9D,YAAY,MAAmB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,cAAuB,EAAE,QAAiB;QACzD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QACjE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AAC;QAClB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACD"}
@@ -0,0 +1,21 @@
1
+ import type { MySqlConfig, MySqlConnection } from './types.js';
2
+ /** Absolute path to the active config file (`MYSQL_MCP_CONFIG` or ~/.mcp_mokomysql.json). */
3
+ export declare function getConfigPath(): string;
4
+ /**
5
+ * Absolute path to the sidecar state file — the MCP-managed learned-marker store.
6
+ * `MYSQL_MCP_STATE` overrides it outright; otherwise it sits beside the config as
7
+ * `<config>.state.json`, so learned state always follows the config that produced it.
8
+ */
9
+ export declare function getStatePath(): string;
10
+ export declare function loadConfig(): Promise<MySqlConfig>;
11
+ /**
12
+ * Normalize a name for tag matching: lowercase and strip every character
13
+ * that isn't a letter or digit. This makes "moko.live", "moko-live",
14
+ * "Moko Live" and "mokolive" all collapse to the same key.
15
+ */
16
+ export declare function normalizeTag(value: string): string;
17
+ export declare function getConnection(config: MySqlConfig, name?: string): {
18
+ key: string;
19
+ conn: MySqlConnection;
20
+ };
21
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../source/config.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAM/D,6FAA6F;AAC7F,wBAAgB,aAAa,IAAI,MAAM,CAItC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,CA+BvD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,CAoBxG"}