@berthojoris/mcp-mysql-server 1.42.2 → 1.43.2
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/CHANGELOG.md +25 -0
- package/DOCUMENTATIONS.md +43 -6
- package/README.md +5 -3
- package/bin/mcp-mysql.js +9 -5
- package/dist/config/featureConfig.js +14 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +27 -0
- package/dist/mcp-server.js +130 -2
- package/dist/tools/analysisTools.d.ts +57 -0
- package/dist/tools/analysisTools.js +544 -13
- package/dist/tools/databaseTools.js +1 -0
- package/dist/tools/toolArgumentValidation.js +113 -1
- package/dist/tools/utilityTools.js +10 -1
- package/manifest.json +154 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ All notable changes to the MySQL MCP Server will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.43.2] - 2026-07-23
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Version bump to `1.43.2` for npm publish.
|
|
12
|
+
- Synchronized version across `package.json`, `src/mcp-server.ts`, `DOCUMENTATIONS.md`, `README.md`, and `manifest.json`.
|
|
13
|
+
|
|
14
|
+
## [1.43.1] - 2026-05-26
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- **URL-encoded credentials in MySQL connection strings** (#4): authentication failed when the username or password contained URL-encoded special characters (e.g. `@` → `%40`, `:` → `%3A`).
|
|
18
|
+
- Both `url.username` and `url.password` are now passed through `decodeURIComponent()` before being handed to the MySQL client.
|
|
19
|
+
- The decoding is also applied when only one of the two is set (e.g. `mysql://:p%40ss%3Aw0rd@host/db` or `mysql://us%40er@host/db`), which previously bypassed decoding entirely.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Synchronized version to `1.43.1` across `package.json`, `src/mcp-server.ts`, `DOCUMENTATIONS.md`, and `README.md`.
|
|
23
|
+
|
|
24
|
+
## [1.43.0] - 2026-05-25
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Added `find_tables_by_keyword`, `search_schema`, and `search_data_across_tables` to help agents answer natural-language schema discovery questions such as “which table stores survey data?”.
|
|
28
|
+
- Added keyword filtering and optional TABLE/COLUMN comments to `get_schema_rag_context`.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Updated analysis tool totals and version metadata to `1.43.0`.
|
|
32
|
+
|
|
8
33
|
## [1.42.2] - 2026-05-25
|
|
9
34
|
|
|
10
35
|
### Fixed
|
package/DOCUMENTATIONS.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# MySQL MCP Server - Documentation
|
|
2
2
|
|
|
3
|
-
**Last Updated:** 2026-
|
|
4
|
-
**Version:** 1.
|
|
5
|
-
**Total Tools:**
|
|
3
|
+
**Last Updated:** 2026-07-23 05:00:00
|
|
4
|
+
**Version:** 1.43.2
|
|
5
|
+
**Total Tools:** 88
|
|
6
6
|
|
|
7
7
|
Comprehensive documentation for the MySQL MCP Server. For quick start, see [README.md](README.md).
|
|
8
8
|
|
|
@@ -47,6 +47,8 @@ Configure MySQL MCP with two access-control layers:
|
|
|
47
47
|
**Layer 1 (Permissions)**: Broad operation control
|
|
48
48
|
**Layer 2 (Categories)**: Fine-grained tool filtering
|
|
49
49
|
|
|
50
|
+
> **Credentials with special characters**: if the username or password in the connection string contains URL-reserved characters (`@`, `:`, `/`, `?`, `#`, `%`, `&`, etc.), URL-encode them — e.g. the password `p@ss:w0rd` becomes `p%40ss%3Aw0rd`, giving `mysql://user:p%40ss%3Aw0rd@host:3306/db`. The server passes both the username and password through `decodeURIComponent()` before connecting, including when only one of the two is set.
|
|
51
|
+
|
|
50
52
|
### Environment Variables
|
|
51
53
|
|
|
52
54
|
```json
|
|
@@ -134,11 +136,14 @@ Tool enabled = (Has Permission) AND (Has Category OR No categories specified)
|
|
|
134
136
|
- `read_table_schema` - Get table structure
|
|
135
137
|
- `get_all_tables_relationships` - Get all FK relationships
|
|
136
138
|
|
|
137
|
-
### 2. Analysis (
|
|
139
|
+
### 2. Analysis (7 tools)
|
|
138
140
|
- `get_database_summary` - Database overview with statistics
|
|
139
141
|
- `get_schema_erd` - Generate Mermaid.js ER diagram
|
|
140
|
-
- `get_schema_rag_context` - Compact schema for LLM context
|
|
142
|
+
- `get_schema_rag_context` - Compact schema for LLM context, with optional comments and keyword filtering
|
|
141
143
|
- `get_column_statistics` - Column data profiling
|
|
144
|
+
- `find_tables_by_keyword` - Ranked schema keyword search across table names, column names, and comments
|
|
145
|
+
- `search_schema` - Unified discovery for “where is X?” questions using schema metadata and optional sample-data search
|
|
146
|
+
- `search_data_across_tables` - Guarded read-only keyword search across text-like data columns
|
|
142
147
|
|
|
143
148
|
### 3. Data Operations (7 tools)
|
|
144
149
|
- `create_record` - Insert single record
|
|
@@ -270,6 +275,35 @@ await mcp.call("get_database_summary", {
|
|
|
270
275
|
await mcp.call("get_schema_erd", {});
|
|
271
276
|
```
|
|
272
277
|
|
|
278
|
+
### Schema & Data Discovery
|
|
279
|
+
|
|
280
|
+
Use these tools when users ask natural-language questions like “which table stores survey data?” or “where is customer feedback saved?”:
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
// Fast metadata search across table names, column names, and comments
|
|
284
|
+
await mcp.call("find_tables_by_keyword", {
|
|
285
|
+
keyword: "survey",
|
|
286
|
+
search_in: "all",
|
|
287
|
+
limit: 20
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Unified discovery with optional guarded sample-data scan
|
|
291
|
+
await mcp.call("search_schema", {
|
|
292
|
+
query: "survey",
|
|
293
|
+
modes: ["table_names", "column_names", "comments", "sample_data"],
|
|
294
|
+
max_results: 20
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Direct bounded data scan when the keyword may only exist in row values
|
|
298
|
+
await mcp.call("search_data_across_tables", {
|
|
299
|
+
keyword: "survey",
|
|
300
|
+
max_tables: 20,
|
|
301
|
+
limit_per_table: 3
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
`find_tables_by_keyword` requires `list`; `search_data_across_tables` requires `read`; `search_schema` uses `list` and requires `read` only when `sample_data` mode is enabled.
|
|
306
|
+
|
|
273
307
|
### Data Operations
|
|
274
308
|
|
|
275
309
|
Basic CRUD operations:
|
|
@@ -326,8 +360,11 @@ The server includes analysis tools for database insights:
|
|
|
326
360
|
|
|
327
361
|
- **Database Summary**: Provides readable overviews with statistics
|
|
328
362
|
- **ER Diagram Generation**: Automatic Mermaid.js diagrams
|
|
329
|
-
- **RAG Context**: Compact schema for LLM prompts
|
|
363
|
+
- **RAG Context**: Compact schema for LLM prompts, with optional `TABLE_COMMENT` / `COLUMN_COMMENT` inclusion and keyword filtering
|
|
330
364
|
- **Column Profiling**: Data quality and distribution analysis
|
|
365
|
+
- **Schema Keyword Discovery**: Ranked search for concepts across table names, column names, and metadata comments
|
|
366
|
+
- **Unified Search**: One entry point for schema and bounded sample-data discovery
|
|
367
|
+
- **Guarded Data Search**: Read-only LIKE scans across text-like columns with strict table/result limits
|
|
331
368
|
|
|
332
369
|
### Bulk Operations
|
|
333
370
|
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**A production-ready Model Context Protocol (MCP) server for MySQL database integration with AI agents**
|
|
6
6
|
|
|
7
|
-
**Last Updated:** 2026-
|
|
7
|
+
**Last Updated:** 2026-07-23 05:00:00
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
|
|
10
10
|
[](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
|
|
@@ -66,6 +66,8 @@ npm install -g @berthojoris/mcp-mysql-server
|
|
|
66
66
|
mcp-mysql mysql://user:pass@localhost:3306/db "list,read,utility"
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
> **Credentials with special characters**: if your username or password contains characters that have a special meaning in URLs (`@`, `:`, `/`, `?`, `#`, `%`, `&`, etc.), URL-encode them before putting them in the connection string. For example, the password `p@ss:w0rd` becomes `p%40ss%3Aw0rd`, giving `mysql://user:p%40ss%3Aw0rd@host:3306/db`. The server decodes both the username and password before connecting.
|
|
70
|
+
|
|
69
71
|
---
|
|
70
72
|
|
|
71
73
|
## Quick Start
|
|
@@ -294,7 +296,7 @@ Use documentation categories to fine-tune which tools are exposed (Layer 2):
|
|
|
294
296
|
| `constraint_management` | Manage data integrity constraints | `add_check_constraint, add_foreign_key, add_unique_constraint, drop_constraint, drop_foreign_key, list_constraints, list_foreign_keys` |
|
|
295
297
|
| `table_maintenance` | Table optimization, repair, and maintenance | `analyze_table, check_table, flush_table, get_table_size, get_table_status, optimize_table, repair_table, truncate_table` |
|
|
296
298
|
| `query_optimization` | Analyze and optimize SQL queries | `analyze_query, get_optimization_hints` |
|
|
297
|
-
| `analysis` | Data analysis and reporting tools | `get_column_statistics, get_database_summary, get_schema_erd, get_schema_rag_context` |
|
|
299
|
+
| `analysis` | Data analysis, schema discovery, and reporting tools | `find_tables_by_keyword, get_column_statistics, get_database_summary, get_schema_erd, get_schema_rag_context, search_data_across_tables, search_schema` |
|
|
298
300
|
|
|
299
301
|
<details>
|
|
300
302
|
<summary>Copy/paste list (comma-separated, no spaces)</summary>
|
|
@@ -311,7 +313,7 @@ Full category → tool mapping (and examples) lives in **[DOCUMENTATIONS.md →
|
|
|
311
313
|
|
|
312
314
|
## Available Tools
|
|
313
315
|
|
|
314
|
-
The server exposes **
|
|
316
|
+
The server exposes **88 tools** organized into categories (CRUD, seed, schema, discovery, and utilities).
|
|
315
317
|
|
|
316
318
|
- Complete list of tools: **[DOCUMENTATIONS.md → Complete Tools Reference](DOCUMENTATIONS.md#🔧-complete-tools-reference)**
|
|
317
319
|
|
package/bin/mcp-mysql.js
CHANGED
|
@@ -95,11 +95,15 @@ try {
|
|
|
95
95
|
// Remove leading slash from pathname and make database optional
|
|
96
96
|
database = url.pathname.replace(/^\//, "") || null;
|
|
97
97
|
|
|
98
|
-
// Extract username and password from auth
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
// Extract username and password from auth.
|
|
99
|
+
// Both fields may be URL-encoded (e.g. "@" -> "%40"), so always decode
|
|
100
|
+
// whatever the URL parser hands us, including when only one side is set.
|
|
101
|
+
const decodeAuthField = (value) =>
|
|
102
|
+
value ? decodeURIComponent(value) : value;
|
|
103
|
+
const auth = {
|
|
104
|
+
user: decodeAuthField(url.username) || "root",
|
|
105
|
+
password: decodeAuthField(url.password) || "",
|
|
106
|
+
};
|
|
103
107
|
|
|
104
108
|
connectionConfig = {
|
|
105
109
|
host: url.hostname,
|
|
@@ -62,6 +62,13 @@ exports.toolCategoryMap = {
|
|
|
62
62
|
getSchemaErd: ToolCategory.LIST,
|
|
63
63
|
get_schema_erd: ToolCategory.LIST,
|
|
64
64
|
getSchemaRagContext: ToolCategory.LIST,
|
|
65
|
+
findTablesByKeyword: ToolCategory.LIST,
|
|
66
|
+
find_tables_by_keyword: ToolCategory.LIST,
|
|
67
|
+
searchSchema: ToolCategory.LIST,
|
|
68
|
+
search_schema: ToolCategory.LIST,
|
|
69
|
+
searchSchemaWithSampleData: ToolCategory.READ,
|
|
70
|
+
searchDataAcrossTables: ToolCategory.READ,
|
|
71
|
+
search_data_across_tables: ToolCategory.READ,
|
|
65
72
|
// CRUD tools
|
|
66
73
|
createRecord: ToolCategory.CREATE,
|
|
67
74
|
readRecords: ToolCategory.READ,
|
|
@@ -287,6 +294,13 @@ exports.toolDocCategoryMap = {
|
|
|
287
294
|
get_schema_erd: DocCategory.ANALYSIS,
|
|
288
295
|
getColumnStatistics: DocCategory.ANALYSIS,
|
|
289
296
|
getSchemaRagContext: DocCategory.ANALYSIS,
|
|
297
|
+
findTablesByKeyword: DocCategory.ANALYSIS,
|
|
298
|
+
find_tables_by_keyword: DocCategory.ANALYSIS,
|
|
299
|
+
searchSchema: DocCategory.ANALYSIS,
|
|
300
|
+
search_schema: DocCategory.ANALYSIS,
|
|
301
|
+
searchSchemaWithSampleData: DocCategory.ANALYSIS,
|
|
302
|
+
searchDataAcrossTables: DocCategory.ANALYSIS,
|
|
303
|
+
search_data_across_tables: DocCategory.ANALYSIS,
|
|
290
304
|
// Full-Text Search
|
|
291
305
|
createFulltextIndex: DocCategory.INDEX_MANAGEMENT,
|
|
292
306
|
fulltextSearch: DocCategory.INDEX_MANAGEMENT,
|
package/dist/index.d.ts
CHANGED
|
@@ -140,11 +140,49 @@ export declare class MySQLMCP {
|
|
|
140
140
|
data?: any;
|
|
141
141
|
error?: string;
|
|
142
142
|
}>;
|
|
143
|
+
findTablesByKeyword(params: {
|
|
144
|
+
keyword: string;
|
|
145
|
+
search_in?: "table_names" | "column_names" | "comments" | "all";
|
|
146
|
+
database?: string;
|
|
147
|
+
limit?: number;
|
|
148
|
+
}): Promise<{
|
|
149
|
+
status: string;
|
|
150
|
+
data?: any;
|
|
151
|
+
error?: string;
|
|
152
|
+
}>;
|
|
153
|
+
searchSchema(params: {
|
|
154
|
+
query: string;
|
|
155
|
+
modes?: Array<"table_names" | "column_names" | "comments" | "sample_data">;
|
|
156
|
+
max_results?: number;
|
|
157
|
+
database?: string;
|
|
158
|
+
tables?: string[];
|
|
159
|
+
columns?: string[];
|
|
160
|
+
max_tables?: number;
|
|
161
|
+
limit_per_table?: number;
|
|
162
|
+
}): Promise<{
|
|
163
|
+
status: string;
|
|
164
|
+
data?: any;
|
|
165
|
+
error?: string;
|
|
166
|
+
}>;
|
|
167
|
+
searchDataAcrossTables(params: {
|
|
168
|
+
keyword: string;
|
|
169
|
+
tables?: string[];
|
|
170
|
+
columns?: string[];
|
|
171
|
+
database?: string;
|
|
172
|
+
limit_per_table?: number;
|
|
173
|
+
max_tables?: number;
|
|
174
|
+
}): Promise<{
|
|
175
|
+
status: string;
|
|
176
|
+
data?: any;
|
|
177
|
+
error?: string;
|
|
178
|
+
}>;
|
|
143
179
|
getSchemaRagContext(params: {
|
|
144
180
|
database?: string;
|
|
145
181
|
max_tables?: number;
|
|
146
182
|
max_columns?: number;
|
|
147
183
|
include_relationships?: boolean;
|
|
184
|
+
include_comments?: boolean;
|
|
185
|
+
keyword_filter?: string;
|
|
148
186
|
}): Promise<{
|
|
149
187
|
status: string;
|
|
150
188
|
data?: any;
|
package/dist/index.js
CHANGED
|
@@ -169,6 +169,33 @@ class MySQLMCP {
|
|
|
169
169
|
}
|
|
170
170
|
return await this.analysisTools.getColumnStatistics(params);
|
|
171
171
|
}
|
|
172
|
+
async findTablesByKeyword(params) {
|
|
173
|
+
const check = this.checkToolEnabled("findTablesByKeyword");
|
|
174
|
+
if (!check.enabled) {
|
|
175
|
+
return { status: "error", error: check.error };
|
|
176
|
+
}
|
|
177
|
+
return await this.analysisTools.findTablesByKeyword(params);
|
|
178
|
+
}
|
|
179
|
+
async searchSchema(params) {
|
|
180
|
+
const check = this.checkToolEnabled("searchSchema");
|
|
181
|
+
if (!check.enabled) {
|
|
182
|
+
return { status: "error", error: check.error };
|
|
183
|
+
}
|
|
184
|
+
if (params?.modes?.includes("sample_data")) {
|
|
185
|
+
const readCheck = this.checkToolEnabled("searchSchemaWithSampleData");
|
|
186
|
+
if (!readCheck.enabled) {
|
|
187
|
+
return { status: "error", error: readCheck.error };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return await this.analysisTools.searchSchema(params);
|
|
191
|
+
}
|
|
192
|
+
async searchDataAcrossTables(params) {
|
|
193
|
+
const check = this.checkToolEnabled("searchDataAcrossTables");
|
|
194
|
+
if (!check.enabled) {
|
|
195
|
+
return { status: "error", error: check.error };
|
|
196
|
+
}
|
|
197
|
+
return await this.analysisTools.searchDataAcrossTables(params);
|
|
198
|
+
}
|
|
172
199
|
async getSchemaRagContext(params) {
|
|
173
200
|
const check = this.checkToolEnabled("getSchemaRagContext");
|
|
174
201
|
if (!check.enabled) {
|
package/dist/mcp-server.js
CHANGED
|
@@ -18,7 +18,7 @@ const toolArgumentValidation_js_1 = require("./tools/toolArgumentValidation.js")
|
|
|
18
18
|
const permissions = process.env.MCP_PERMISSIONS || process.env.MCP_CONFIG || "";
|
|
19
19
|
const categories = process.env.MCP_CATEGORIES || "";
|
|
20
20
|
const SERVER_NAME = "mysql-mcp-server";
|
|
21
|
-
const SERVER_VERSION = "1.
|
|
21
|
+
const SERVER_VERSION = "1.43.2";
|
|
22
22
|
// Declare the MySQL MCP instance (will be initialized in main())
|
|
23
23
|
let mysqlMCP;
|
|
24
24
|
// Define all available tools with their schemas
|
|
@@ -80,7 +80,7 @@ const TOOLS = [
|
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
name: "get_schema_rag_context",
|
|
83
|
-
description: "🎯 AI-OPTIMIZED: Returns ultra-compact schema information (tables, columns, keys, relationships, row estimates) designed specifically for LLM context windows. Use
|
|
83
|
+
description: "🎯 AI-OPTIMIZED: Returns ultra-compact schema information (tables, columns, keys, relationships, comments, row estimates) designed specifically for LLM context windows. Use keyword_filter for concept-focused schema discovery.",
|
|
84
84
|
inputSchema: {
|
|
85
85
|
type: "object",
|
|
86
86
|
properties: {
|
|
@@ -100,7 +100,126 @@ const TOOLS = [
|
|
|
100
100
|
type: "boolean",
|
|
101
101
|
description: "Whether to include FK relationships section (default: true)",
|
|
102
102
|
},
|
|
103
|
+
include_comments: {
|
|
104
|
+
type: "boolean",
|
|
105
|
+
description: "Optional: include TABLE_COMMENT and COLUMN_COMMENT metadata (default: false)",
|
|
106
|
+
},
|
|
107
|
+
keyword_filter: {
|
|
108
|
+
type: "string",
|
|
109
|
+
description: "Optional: only include tables relevant to this keyword, ranked by table names, column names, and comments",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "find_tables_by_keyword",
|
|
116
|
+
description: "🔎 Schema discovery: finds candidate tables for a concept or keyword by searching table names, column names, TABLE_COMMENT, and COLUMN_COMMENT metadata. Use when users ask 'which table stores X?' before reading sample data.",
|
|
117
|
+
inputSchema: {
|
|
118
|
+
type: "object",
|
|
119
|
+
properties: {
|
|
120
|
+
keyword: {
|
|
121
|
+
type: "string",
|
|
122
|
+
description: "Concept or keyword to find, such as survey, invoice, feedback, or customer",
|
|
123
|
+
},
|
|
124
|
+
search_in: {
|
|
125
|
+
type: "string",
|
|
126
|
+
enum: ["table_names", "column_names", "comments", "all"],
|
|
127
|
+
description: "Where to search (default: all)",
|
|
128
|
+
},
|
|
129
|
+
database: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "Optional: specific database name",
|
|
132
|
+
},
|
|
133
|
+
limit: {
|
|
134
|
+
type: "number",
|
|
135
|
+
description: "Optional: maximum number of ranked tables to return (default 20, max 100)",
|
|
136
|
+
},
|
|
103
137
|
},
|
|
138
|
+
required: ["keyword"],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "search_schema",
|
|
143
|
+
description: "🧭 Unified schema discovery for natural-language 'where is X?' questions. Searches schema metadata by default and can optionally perform a guarded sample-data scan when mode sample_data is requested.",
|
|
144
|
+
inputSchema: {
|
|
145
|
+
type: "object",
|
|
146
|
+
properties: {
|
|
147
|
+
query: {
|
|
148
|
+
type: "string",
|
|
149
|
+
description: "Concept or keyword to discover",
|
|
150
|
+
},
|
|
151
|
+
modes: {
|
|
152
|
+
type: "array",
|
|
153
|
+
items: {
|
|
154
|
+
type: "string",
|
|
155
|
+
enum: ["table_names", "column_names", "comments", "sample_data"],
|
|
156
|
+
},
|
|
157
|
+
description: "Discovery modes (default: table_names, column_names, comments). sample_data requires read permission.",
|
|
158
|
+
},
|
|
159
|
+
max_results: {
|
|
160
|
+
type: "number",
|
|
161
|
+
description: "Optional: maximum combined results to return (default 20, max 100)",
|
|
162
|
+
},
|
|
163
|
+
database: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "Optional: specific database name",
|
|
166
|
+
},
|
|
167
|
+
tables: {
|
|
168
|
+
type: "array",
|
|
169
|
+
items: { type: "string" },
|
|
170
|
+
description: "Optional: restrict sample_data mode to these tables",
|
|
171
|
+
},
|
|
172
|
+
columns: {
|
|
173
|
+
type: "array",
|
|
174
|
+
items: { type: "string" },
|
|
175
|
+
description: "Optional: restrict sample_data mode to these columns",
|
|
176
|
+
},
|
|
177
|
+
max_tables: {
|
|
178
|
+
type: "number",
|
|
179
|
+
description: "Optional: max tables scanned in sample_data mode (default 20, max 100)",
|
|
180
|
+
},
|
|
181
|
+
limit_per_table: {
|
|
182
|
+
type: "number",
|
|
183
|
+
description: "Optional: max matching rows returned per table in sample_data mode (default 5, max 20)",
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
required: ["query"],
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "search_data_across_tables",
|
|
191
|
+
description: "🔍 Guarded read-only keyword scan across text-like table data. Use only when schema metadata does not reveal where a concept is stored; enforces max table and per-table result limits.",
|
|
192
|
+
inputSchema: {
|
|
193
|
+
type: "object",
|
|
194
|
+
properties: {
|
|
195
|
+
keyword: {
|
|
196
|
+
type: "string",
|
|
197
|
+
description: "Keyword to search inside text-like column values",
|
|
198
|
+
},
|
|
199
|
+
tables: {
|
|
200
|
+
type: "array",
|
|
201
|
+
items: { type: "string" },
|
|
202
|
+
description: "Optional: restrict scan to these tables",
|
|
203
|
+
},
|
|
204
|
+
columns: {
|
|
205
|
+
type: "array",
|
|
206
|
+
items: { type: "string" },
|
|
207
|
+
description: "Optional: restrict scan to these column names",
|
|
208
|
+
},
|
|
209
|
+
database: {
|
|
210
|
+
type: "string",
|
|
211
|
+
description: "Optional: specific database name",
|
|
212
|
+
},
|
|
213
|
+
max_tables: {
|
|
214
|
+
type: "number",
|
|
215
|
+
description: "Optional: maximum tables to scan (default 20, max 100)",
|
|
216
|
+
},
|
|
217
|
+
limit_per_table: {
|
|
218
|
+
type: "number",
|
|
219
|
+
description: "Optional: maximum rows returned per table (default 5, max 20)",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
required: ["keyword"],
|
|
104
223
|
},
|
|
105
224
|
},
|
|
106
225
|
{
|
|
@@ -2306,6 +2425,15 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
2306
2425
|
case "get_schema_rag_context":
|
|
2307
2426
|
result = await mysqlMCP.getSchemaRagContext((args || {}));
|
|
2308
2427
|
break;
|
|
2428
|
+
case "find_tables_by_keyword":
|
|
2429
|
+
result = await mysqlMCP.findTablesByKeyword((args || {}));
|
|
2430
|
+
break;
|
|
2431
|
+
case "search_schema":
|
|
2432
|
+
result = await mysqlMCP.searchSchema((args || {}));
|
|
2433
|
+
break;
|
|
2434
|
+
case "search_data_across_tables":
|
|
2435
|
+
result = await mysqlMCP.searchDataAcrossTables((args || {}));
|
|
2436
|
+
break;
|
|
2309
2437
|
case "get_column_statistics":
|
|
2310
2438
|
result = await mysqlMCP.getColumnStatistics((args || {}));
|
|
2311
2439
|
break;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SecurityLayer } from "../security/securityLayer";
|
|
2
|
+
type SchemaSearchScope = "table_names" | "column_names" | "comments" | "all";
|
|
3
|
+
type SearchSchemaMode = "table_names" | "column_names" | "comments" | "sample_data";
|
|
2
4
|
export declare class AnalysisTools {
|
|
3
5
|
private db;
|
|
4
6
|
private security;
|
|
@@ -7,6 +9,13 @@ export declare class AnalysisTools {
|
|
|
7
9
|
* Validate database access - ensures only the connected database can be accessed
|
|
8
10
|
*/
|
|
9
11
|
private validateDatabaseAccess;
|
|
12
|
+
private clampNumber;
|
|
13
|
+
private escapeLikePattern;
|
|
14
|
+
private quoteIdentifier;
|
|
15
|
+
private truncateValue;
|
|
16
|
+
private getMatchScore;
|
|
17
|
+
private addMatchedField;
|
|
18
|
+
private getTablesByName;
|
|
10
19
|
/**
|
|
11
20
|
* Get statistics for a specific column
|
|
12
21
|
*/
|
|
@@ -19,6 +28,51 @@ export declare class AnalysisTools {
|
|
|
19
28
|
data?: any;
|
|
20
29
|
error?: string;
|
|
21
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Find candidate tables by keyword across schema metadata.
|
|
33
|
+
*/
|
|
34
|
+
findTablesByKeyword(params: {
|
|
35
|
+
keyword: string;
|
|
36
|
+
search_in?: SchemaSearchScope;
|
|
37
|
+
database?: string;
|
|
38
|
+
limit?: number;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
status: string;
|
|
41
|
+
data?: any;
|
|
42
|
+
error?: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Guarded read-only keyword search across text-like data columns.
|
|
46
|
+
*/
|
|
47
|
+
searchDataAcrossTables(params: {
|
|
48
|
+
keyword: string;
|
|
49
|
+
tables?: string[];
|
|
50
|
+
columns?: string[];
|
|
51
|
+
database?: string;
|
|
52
|
+
limit_per_table?: number;
|
|
53
|
+
max_tables?: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
status: string;
|
|
56
|
+
data?: any;
|
|
57
|
+
error?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Unified discovery entry point for "where is X?" questions.
|
|
61
|
+
*/
|
|
62
|
+
searchSchema(params: {
|
|
63
|
+
query: string;
|
|
64
|
+
modes?: SearchSchemaMode[];
|
|
65
|
+
max_results?: number;
|
|
66
|
+
database?: string;
|
|
67
|
+
tables?: string[];
|
|
68
|
+
columns?: string[];
|
|
69
|
+
max_tables?: number;
|
|
70
|
+
limit_per_table?: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
status: string;
|
|
73
|
+
data?: any;
|
|
74
|
+
error?: string;
|
|
75
|
+
}>;
|
|
22
76
|
/**
|
|
23
77
|
* Build a compact, schema-aware context pack for RAG (tables, PK/FK, columns, row estimates)
|
|
24
78
|
*/
|
|
@@ -27,9 +81,12 @@ export declare class AnalysisTools {
|
|
|
27
81
|
max_tables?: number;
|
|
28
82
|
max_columns?: number;
|
|
29
83
|
include_relationships?: boolean;
|
|
84
|
+
include_comments?: boolean;
|
|
85
|
+
keyword_filter?: string;
|
|
30
86
|
}): Promise<{
|
|
31
87
|
status: string;
|
|
32
88
|
data?: any;
|
|
33
89
|
error?: string;
|
|
34
90
|
}>;
|
|
35
91
|
}
|
|
92
|
+
export {};
|