@connorbritain/mssql-mcp-server 0.3.6 → 0.4.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.
- package/dist/index.js +6 -751
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
- package/dist/audit/AuditLogger.d.ts +0 -37
- package/dist/audit/AuditLogger.d.ts.map +0 -1
- package/dist/audit/AuditLogger.js +0 -145
- package/dist/audit/AuditLogger.js.map +0 -1
- package/dist/config/EnvironmentManager.d.ts +0 -75
- package/dist/config/EnvironmentManager.d.ts.map +0 -1
- package/dist/config/EnvironmentManager.js +0 -305
- package/dist/config/EnvironmentManager.js.map +0 -1
- package/dist/config/ScriptManager.d.ts +0 -69
- package/dist/config/ScriptManager.d.ts.map +0 -1
- package/dist/config/ScriptManager.js +0 -166
- package/dist/config/ScriptManager.js.map +0 -1
- package/dist/config/SecretResolver.d.ts +0 -66
- package/dist/config/SecretResolver.d.ts.map +0 -1
- package/dist/config/SecretResolver.js +0 -230
- package/dist/config/SecretResolver.js.map +0 -1
- package/dist/tools/CreateIndexTool.d.ts +0 -24
- package/dist/tools/CreateIndexTool.d.ts.map +0 -1
- package/dist/tools/CreateIndexTool.js +0 -64
- package/dist/tools/CreateIndexTool.js.map +0 -1
- package/dist/tools/CreateTableTool.d.ts +0 -12
- package/dist/tools/CreateTableTool.d.ts.map +0 -1
- package/dist/tools/CreateTableTool.js +0 -49
- package/dist/tools/CreateTableTool.js.map +0 -1
- package/dist/tools/DeleteDataTool.d.ts +0 -56
- package/dist/tools/DeleteDataTool.d.ts.map +0 -1
- package/dist/tools/DeleteDataTool.js +0 -103
- package/dist/tools/DeleteDataTool.js.map +0 -1
- package/dist/tools/DescribeTableTool.d.ts +0 -32
- package/dist/tools/DescribeTableTool.d.ts.map +0 -1
- package/dist/tools/DescribeTableTool.js +0 -108
- package/dist/tools/DescribeTableTool.js.map +0 -1
- package/dist/tools/DropTableTool.d.ts +0 -12
- package/dist/tools/DropTableTool.d.ts.map +0 -1
- package/dist/tools/DropTableTool.js +0 -37
- package/dist/tools/DropTableTool.js.map +0 -1
- package/dist/tools/ExplainQueryTool.d.ts +0 -24
- package/dist/tools/ExplainQueryTool.d.ts.map +0 -1
- package/dist/tools/ExplainQueryTool.js +0 -98
- package/dist/tools/ExplainQueryTool.js.map +0 -1
- package/dist/tools/InsertDataTool.d.ts +0 -17
- package/dist/tools/InsertDataTool.d.ts.map +0 -1
- package/dist/tools/InsertDataTool.js +0 -102
- package/dist/tools/InsertDataTool.js.map +0 -1
- package/dist/tools/InspectDependenciesTool.d.ts +0 -45
- package/dist/tools/InspectDependenciesTool.d.ts.map +0 -1
- package/dist/tools/InspectDependenciesTool.js +0 -215
- package/dist/tools/InspectDependenciesTool.js.map +0 -1
- package/dist/tools/ListDatabasesTool.d.ts +0 -27
- package/dist/tools/ListDatabasesTool.d.ts.map +0 -1
- package/dist/tools/ListDatabasesTool.js +0 -107
- package/dist/tools/ListDatabasesTool.js.map +0 -1
- package/dist/tools/ListEnvironmentsTool.d.ts +0 -49
- package/dist/tools/ListEnvironmentsTool.d.ts.map +0 -1
- package/dist/tools/ListEnvironmentsTool.js +0 -73
- package/dist/tools/ListEnvironmentsTool.js.map +0 -1
- package/dist/tools/ListScriptsTool.d.ts +0 -41
- package/dist/tools/ListScriptsTool.d.ts.map +0 -1
- package/dist/tools/ListScriptsTool.js +0 -86
- package/dist/tools/ListScriptsTool.js.map +0 -1
- package/dist/tools/ListTableTool.d.ts +0 -24
- package/dist/tools/ListTableTool.d.ts.map +0 -1
- package/dist/tools/ListTableTool.js +0 -85
- package/dist/tools/ListTableTool.js.map +0 -1
- package/dist/tools/ProfileTableTool.d.ts +0 -78
- package/dist/tools/ProfileTableTool.d.ts.map +0 -1
- package/dist/tools/ProfileTableTool.js +0 -373
- package/dist/tools/ProfileTableTool.js.map +0 -1
- package/dist/tools/ReadDataTool.d.ts +0 -61
- package/dist/tools/ReadDataTool.d.ts.map +0 -1
- package/dist/tools/ReadDataTool.js +0 -299
- package/dist/tools/ReadDataTool.js.map +0 -1
- package/dist/tools/RelationshipInspectorTool.d.ts +0 -46
- package/dist/tools/RelationshipInspectorTool.d.ts.map +0 -1
- package/dist/tools/RelationshipInspectorTool.js +0 -156
- package/dist/tools/RelationshipInspectorTool.js.map +0 -1
- package/dist/tools/RunScriptTool.d.ts +0 -215
- package/dist/tools/RunScriptTool.d.ts.map +0 -1
- package/dist/tools/RunScriptTool.js +0 -177
- package/dist/tools/RunScriptTool.js.map +0 -1
- package/dist/tools/SearchSchemaTool.d.ts +0 -88
- package/dist/tools/SearchSchemaTool.d.ts.map +0 -1
- package/dist/tools/SearchSchemaTool.js +0 -237
- package/dist/tools/SearchSchemaTool.js.map +0 -1
- package/dist/tools/TestConnectionTool.d.ts +0 -38
- package/dist/tools/TestConnectionTool.d.ts.map +0 -1
- package/dist/tools/TestConnectionTool.js +0 -156
- package/dist/tools/TestConnectionTool.js.map +0 -1
- package/dist/tools/UpdateDataTool.d.ts +0 -61
- package/dist/tools/UpdateDataTool.d.ts.map +0 -1
- package/dist/tools/UpdateDataTool.js +0 -117
- package/dist/tools/UpdateDataTool.js.map +0 -1
- package/dist/tools/ValidateEnvironmentConfigTool.d.ts +0 -51
- package/dist/tools/ValidateEnvironmentConfigTool.d.ts.map +0 -1
- package/dist/tools/ValidateEnvironmentConfigTool.js +0 -320
- package/dist/tools/ValidateEnvironmentConfigTool.js.map +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
export class CreateIndexTool {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.name = "create_index";
|
|
5
|
-
this.description = "Creates an index on a specified column or columns in an MSSQL Database table";
|
|
6
|
-
this.inputSchema = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: {
|
|
9
|
-
schemaName: { type: "string", description: "Name of the schema containing the table" },
|
|
10
|
-
tableName: { type: "string", description: "Name of the table to create index on" },
|
|
11
|
-
indexName: { type: "string", description: "Name for the new index" },
|
|
12
|
-
columns: {
|
|
13
|
-
type: "array",
|
|
14
|
-
items: { type: "string" },
|
|
15
|
-
description: "Array of column names to include in the index"
|
|
16
|
-
},
|
|
17
|
-
isUnique: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
description: "Whether the index should enforce uniqueness (default: false)",
|
|
20
|
-
default: false
|
|
21
|
-
},
|
|
22
|
-
isClustered: {
|
|
23
|
-
type: "boolean",
|
|
24
|
-
description: "Whether the index should be clustered (default: false)",
|
|
25
|
-
default: false
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
required: ["tableName", "indexName", "columns"],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async run(params) {
|
|
32
|
-
try {
|
|
33
|
-
const { schemaName, tableName, indexName, columns, isUnique = false, isClustered = false } = params;
|
|
34
|
-
let indexType = isClustered ? "CLUSTERED" : "NONCLUSTERED";
|
|
35
|
-
if (isUnique) {
|
|
36
|
-
indexType = `UNIQUE ${indexType}`;
|
|
37
|
-
}
|
|
38
|
-
const columnNames = columns.join(", ");
|
|
39
|
-
const request = new sql.Request(params.pool);
|
|
40
|
-
const query = `CREATE ${indexType} INDEX ${indexName} ON ${schemaName}.${tableName} (${columnNames})`;
|
|
41
|
-
await request.query(query);
|
|
42
|
-
return {
|
|
43
|
-
success: true,
|
|
44
|
-
message: `Index [${indexName}] created successfully on table [${schemaName}.${tableName}]`,
|
|
45
|
-
details: {
|
|
46
|
-
schemaName,
|
|
47
|
-
tableName,
|
|
48
|
-
indexName,
|
|
49
|
-
columnNames,
|
|
50
|
-
isUnique,
|
|
51
|
-
isClustered
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error("Error creating index:", error);
|
|
57
|
-
return {
|
|
58
|
-
success: false,
|
|
59
|
-
message: `Failed to create index: ${error}`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
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W,CAAC,CAAC,CAAC,cAAc,CAAC;YAC3D,IAAI,QAAQ,EAAE,CAAC;gBACb,SAAS,GAAG,UAAU,SAAS,EAAE,CAAC;YACpC,CAAC;YACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEvC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,UAAU,SAAS,UAAU,SAAS,OAAO,UAAU,IAAI,SAAS,KAAK,WAAW,GAAG,CAAC;YACtG,MAAM,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAE3B,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,UAAU,SAAS,oCAAoC,UAAU,IAAI,SAAS,GAAG;gBAC1F,OAAO,EAAE;oBACP,UAAU;oBACV,SAAS;oBACT,SAAS;oBACT,WAAW;oBACX,QAAQ;oBACR,WAAW;iBACZ;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,2BAA2B,KAAK,EAAE;aAC5C,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
export declare class CreateTableTool implements Tool {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
inputSchema: any;
|
|
7
|
-
run(params: any): Promise<{
|
|
8
|
-
success: boolean;
|
|
9
|
-
message: string;
|
|
10
|
-
}>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=CreateTableTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateTableTool.d.ts","sourceRoot":"","sources":["../../src/tools/CreateTableTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE1D,qBAAa,eAAgB,YAAW,IAAI;IAC1C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,SAAkB;IACtB,WAAW,SAA2E;IACtF,WAAW,EAkBN,GAAG,CAAC;IAEH,GAAG,CAAC,MAAM,EAAE,GAAG;;;;CAqBtB"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
export class CreateTableTool {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.name = "create_table";
|
|
5
|
-
this.description = "Creates a new table in the MSSQL Database with the specified columns.";
|
|
6
|
-
this.inputSchema = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: {
|
|
9
|
-
tableName: { type: "string", description: "Name of the table to create" },
|
|
10
|
-
columns: {
|
|
11
|
-
type: "array",
|
|
12
|
-
description: "Array of column definitions (e.g., [{ name: 'id', type: 'INT PRIMARY KEY' }, ...])",
|
|
13
|
-
items: {
|
|
14
|
-
type: "object",
|
|
15
|
-
properties: {
|
|
16
|
-
name: { type: "string", description: "Column name" },
|
|
17
|
-
type: { type: "string", description: "SQL type and constraints (e.g., 'INT PRIMARY KEY', 'NVARCHAR(255) NOT NULL')" }
|
|
18
|
-
},
|
|
19
|
-
required: ["name", "type"]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
required: ["tableName", "columns"],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async run(params) {
|
|
27
|
-
try {
|
|
28
|
-
const { tableName, columns } = params;
|
|
29
|
-
if (!Array.isArray(columns) || columns.length === 0) {
|
|
30
|
-
throw new Error("'columns' must be a non-empty array");
|
|
31
|
-
}
|
|
32
|
-
const columnDefs = columns.map((col) => `[${col.name}] ${col.type}`).join(", ");
|
|
33
|
-
const query = `CREATE TABLE [${tableName}] (${columnDefs})`;
|
|
34
|
-
await new sql.Request(params.pool).query(query);
|
|
35
|
-
return {
|
|
36
|
-
success: true,
|
|
37
|
-
message: `Table '${tableName}' created successfully.`
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error("Error creating table:", error);
|
|
42
|
-
return {
|
|
43
|
-
success: false,
|
|
44
|
-
message: `Failed to create table: ${error}`
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=CreateTableTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateTableTool.js","sourceRoot":"","sources":["../../src/tools/CreateTableTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,MAAM,OAAO,eAAe;IAA5B;QAEE,SAAI,GAAG,cAAc,CAAC;QACtB,gBAAW,GAAG,uEAAuE,CAAC;QACtF,gBAAW,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,6BAA6B,EAAE;gBACzE,OAAO,EAAE;oBACP,IAAI,EAAE,OAAO;oBACb,WAAW,EAAE,oFAAoF;oBACjG,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE;4BACpD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8EAA8E,EAAE;yBACtH;wBACD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;qBAC3B;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC;SAC5B,CAAC;IAuBX,CAAC;IArBC,KAAK,CAAC,GAAG,CAAC,MAAW;QACnB,IAAI,CAAC;YACH,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;YACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrF,MAAM,KAAK,GAAG,iBAAiB,SAAS,MAAM,UAAU,GAAG,CAAC;YAC5D,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,UAAU,SAAS,yBAAyB;aACtD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,2BAA2B,KAAK,EAAE;aAC5C,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
export declare class DeleteDataTool implements Tool {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
inputSchema: any;
|
|
8
|
-
private static readonly MAX_ROWS_DEFAULT;
|
|
9
|
-
run(params: any): Promise<{
|
|
10
|
-
success: boolean;
|
|
11
|
-
message: string;
|
|
12
|
-
error: string;
|
|
13
|
-
affectedRows?: undefined;
|
|
14
|
-
maxAllowed?: undefined;
|
|
15
|
-
needsConfirmation?: undefined;
|
|
16
|
-
preview?: undefined;
|
|
17
|
-
rowsDeleted?: undefined;
|
|
18
|
-
} | {
|
|
19
|
-
success: boolean;
|
|
20
|
-
message: string;
|
|
21
|
-
error: string;
|
|
22
|
-
affectedRows: number;
|
|
23
|
-
maxAllowed?: undefined;
|
|
24
|
-
needsConfirmation?: undefined;
|
|
25
|
-
preview?: undefined;
|
|
26
|
-
rowsDeleted?: undefined;
|
|
27
|
-
} | {
|
|
28
|
-
success: boolean;
|
|
29
|
-
message: string;
|
|
30
|
-
error: string;
|
|
31
|
-
affectedRows: any;
|
|
32
|
-
maxAllowed: any;
|
|
33
|
-
needsConfirmation?: undefined;
|
|
34
|
-
preview?: undefined;
|
|
35
|
-
rowsDeleted?: undefined;
|
|
36
|
-
} | {
|
|
37
|
-
success: boolean;
|
|
38
|
-
needsConfirmation: boolean;
|
|
39
|
-
message: string;
|
|
40
|
-
affectedRows: any;
|
|
41
|
-
preview: sql.IRecordSet<any>;
|
|
42
|
-
error: string;
|
|
43
|
-
maxAllowed?: undefined;
|
|
44
|
-
rowsDeleted?: undefined;
|
|
45
|
-
} | {
|
|
46
|
-
success: boolean;
|
|
47
|
-
message: string;
|
|
48
|
-
rowsDeleted: number;
|
|
49
|
-
error?: undefined;
|
|
50
|
-
affectedRows?: undefined;
|
|
51
|
-
maxAllowed?: undefined;
|
|
52
|
-
needsConfirmation?: undefined;
|
|
53
|
-
preview?: undefined;
|
|
54
|
-
}>;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=DeleteDataTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeleteDataTool.d.ts","sourceRoot":"","sources":["../../src/tools/DeleteDataTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE1D,qBAAa,cAAe,YAAW,IAAI;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,SAAiB;IACrB,WAAW,SAAuG;IAElH,WAAW,EAyBN,GAAG,CAAC;IAET,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IAE1C,GAAG,CAAC,MAAM,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4EtB"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
export class DeleteDataTool {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.name = "delete_data";
|
|
5
|
-
this.description = "Deletes rows from an MSSQL table with preview and confirmation. Requires WHERE clause for safety.";
|
|
6
|
-
this.inputSchema = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: {
|
|
9
|
-
tableName: {
|
|
10
|
-
type: "string",
|
|
11
|
-
description: "Name of the table to delete from"
|
|
12
|
-
},
|
|
13
|
-
whereClause: {
|
|
14
|
-
type: "string",
|
|
15
|
-
description: "WHERE clause to identify which rows to delete. Example: \"status = 'archived' AND created_date < '2023-01-01'\""
|
|
16
|
-
},
|
|
17
|
-
confirmDelete: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
description: "Set to true to confirm and execute the delete after preview. First call without this to see preview.",
|
|
20
|
-
},
|
|
21
|
-
maxRows: {
|
|
22
|
-
type: "number",
|
|
23
|
-
description: "Maximum number of rows allowed to delete. Defaults to 1000 for safety.",
|
|
24
|
-
},
|
|
25
|
-
environment: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Optional environment name to target",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
required: ["tableName", "whereClause"],
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
async run(params) {
|
|
34
|
-
let query;
|
|
35
|
-
try {
|
|
36
|
-
const { tableName, whereClause, confirmDelete, maxRows, environment } = params;
|
|
37
|
-
// Basic validation: ensure whereClause is not empty
|
|
38
|
-
if (!whereClause || whereClause.trim() === '') {
|
|
39
|
-
return {
|
|
40
|
-
success: false,
|
|
41
|
-
message: "WHERE clause is required for safety. Deleting all rows requires explicit WHERE clause like 'WHERE 1=1'.",
|
|
42
|
-
error: "MISSING_WHERE_CLAUSE",
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const maxAllowed = maxRows || DeleteDataTool.MAX_ROWS_DEFAULT;
|
|
46
|
-
// Step 1: Get count of affected rows
|
|
47
|
-
const countQuery = `SELECT COUNT(*) as affectedRows FROM ${tableName} WHERE ${whereClause}`;
|
|
48
|
-
const countRequest = new sql.Request(params.pool);
|
|
49
|
-
const countResult = await countRequest.query(countQuery);
|
|
50
|
-
const affectedRows = countResult.recordset[0].affectedRows;
|
|
51
|
-
if (affectedRows === 0) {
|
|
52
|
-
return {
|
|
53
|
-
success: false,
|
|
54
|
-
message: "No rows match the WHERE clause. No deletion will be performed.",
|
|
55
|
-
error: "NO_ROWS_MATCHED",
|
|
56
|
-
affectedRows: 0,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (affectedRows > maxAllowed) {
|
|
60
|
-
return {
|
|
61
|
-
success: false,
|
|
62
|
-
message: `Delete would affect ${affectedRows} rows, which exceeds the maximum of ${maxAllowed}. Refine your WHERE clause or increase maxRows parameter.`,
|
|
63
|
-
error: "TOO_MANY_ROWS",
|
|
64
|
-
affectedRows,
|
|
65
|
-
maxAllowed,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// Step 2: Show preview if not confirmed
|
|
69
|
-
if (!confirmDelete) {
|
|
70
|
-
const previewQuery = `SELECT TOP 10 * FROM ${tableName} WHERE ${whereClause}`;
|
|
71
|
-
const previewRequest = new sql.Request(params.pool);
|
|
72
|
-
const previewResult = await previewRequest.query(previewQuery);
|
|
73
|
-
return {
|
|
74
|
-
success: false,
|
|
75
|
-
needsConfirmation: true,
|
|
76
|
-
message: `⚠️ WARNING: ${affectedRows} row(s) will be permanently deleted. Review the preview below and re-run with confirmDelete: true to proceed.`,
|
|
77
|
-
affectedRows,
|
|
78
|
-
preview: previewResult.recordset,
|
|
79
|
-
error: "CONFIRMATION_REQUIRED",
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// Step 3: Execute the delete
|
|
83
|
-
query = `DELETE FROM ${tableName} WHERE ${whereClause}`;
|
|
84
|
-
const request = new sql.Request(params.pool);
|
|
85
|
-
const result = await request.query(query);
|
|
86
|
-
return {
|
|
87
|
-
success: true,
|
|
88
|
-
message: `Successfully deleted ${result.rowsAffected[0]} row(s) from table '${tableName}'`,
|
|
89
|
-
rowsDeleted: result.rowsAffected[0],
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error("Error deleting data:", error);
|
|
94
|
-
return {
|
|
95
|
-
success: false,
|
|
96
|
-
message: `Failed to delete data${query ? ` with '${query}'` : ''}: ${error}`,
|
|
97
|
-
error: "DELETE_FAILED",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
DeleteDataTool.MAX_ROWS_DEFAULT = 1000;
|
|
103
|
-
//# sourceMappingURL=DeleteDataTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeleteDataTool.js","sourceRoot":"","sources":["../../src/tools/DeleteDataTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,MAAM,OAAO,cAAc;IAA3B;QAEE,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,mGAAmG,CAAC;QAElH,gBAAW,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kCAAkC;iBAChD;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,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,EAAE,KAAK,CAAC,CAAC;YAC7C,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,wBAAwB,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,EAAE;gBAC5E,KAAK,EAAE,eAAe;aACvB,CAAC;QACJ,CAAC;IACH,CAAC;;AA7EuB,+BAAgB,GAAG,IAAI,AAAP,CAAQ"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
export declare class DescribeTableTool implements Tool {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
inputSchema: any;
|
|
8
|
-
run(params: {
|
|
9
|
-
tableName: string;
|
|
10
|
-
database?: string;
|
|
11
|
-
environment?: string;
|
|
12
|
-
}): Promise<{
|
|
13
|
-
success: boolean;
|
|
14
|
-
message: string;
|
|
15
|
-
error: string;
|
|
16
|
-
database?: undefined;
|
|
17
|
-
schema?: undefined;
|
|
18
|
-
tableName?: undefined;
|
|
19
|
-
columnCount?: undefined;
|
|
20
|
-
columns?: undefined;
|
|
21
|
-
} | {
|
|
22
|
-
success: boolean;
|
|
23
|
-
message: string;
|
|
24
|
-
database: string | undefined;
|
|
25
|
-
schema: string;
|
|
26
|
-
tableName: string;
|
|
27
|
-
columnCount: number;
|
|
28
|
-
columns: sql.IRecordSet<any>;
|
|
29
|
-
error?: undefined;
|
|
30
|
-
}>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=DescribeTableTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DescribeTableTool.d.ts","sourceRoot":"","sources":["../../src/tools/DescribeTableTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAG1D,qBAAa,iBAAkB,YAAW,IAAI;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,SAAoB;IACxB,WAAW,SAEqE;IAChF,WAAW,EAaN,GAAG,CAAC;IAEH,GAAG,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;;;;;CAyFjF"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
import { getEnvironmentManager } from "../config/EnvironmentManager.js";
|
|
3
|
-
export class DescribeTableTool {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.name = "describe_table";
|
|
6
|
-
this.description = "Describes the schema (columns and types) of a specified MSSQL Database table. " +
|
|
7
|
-
"For server-level access environments, you can specify a database to target.";
|
|
8
|
-
this.inputSchema = {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {
|
|
11
|
-
tableName: {
|
|
12
|
-
type: "string",
|
|
13
|
-
description: "Name of the table to describe (can include schema: 'dbo.TableName')",
|
|
14
|
-
},
|
|
15
|
-
database: {
|
|
16
|
-
type: "string",
|
|
17
|
-
description: "Optional: Target database name for server-level access environments.",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
required: ["tableName"],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async run(params) {
|
|
24
|
-
try {
|
|
25
|
-
const { tableName, database, environment } = params;
|
|
26
|
-
// Validate database access if specified
|
|
27
|
-
if (database) {
|
|
28
|
-
const envManager = getEnvironmentManager();
|
|
29
|
-
const dbCheck = envManager.isDatabaseAllowed(environment, database);
|
|
30
|
-
if (!dbCheck.allowed) {
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
message: dbCheck.reason || `Access to database '${database}' is not allowed.`,
|
|
34
|
-
error: "DATABASE_ACCESS_DENIED",
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// Parse schema and table name
|
|
39
|
-
let schemaName = "dbo";
|
|
40
|
-
let actualTableName = tableName;
|
|
41
|
-
if (tableName.includes(".")) {
|
|
42
|
-
const parts = tableName.split(".");
|
|
43
|
-
schemaName = parts[0];
|
|
44
|
-
actualTableName = parts[1];
|
|
45
|
-
}
|
|
46
|
-
const request = new sql.Request(params.pool);
|
|
47
|
-
// Build query with optional database context
|
|
48
|
-
let query;
|
|
49
|
-
if (database) {
|
|
50
|
-
const safeDbName = database.replace(/]/g, "]]");
|
|
51
|
-
query = `
|
|
52
|
-
USE [${safeDbName}];
|
|
53
|
-
SELECT
|
|
54
|
-
COLUMN_NAME as name,
|
|
55
|
-
DATA_TYPE as type,
|
|
56
|
-
CHARACTER_MAXIMUM_LENGTH as max_length,
|
|
57
|
-
IS_NULLABLE as nullable,
|
|
58
|
-
COLUMN_DEFAULT as default_value,
|
|
59
|
-
ORDINAL_POSITION as position
|
|
60
|
-
FROM INFORMATION_SCHEMA.COLUMNS
|
|
61
|
-
WHERE TABLE_NAME = @tableName AND TABLE_SCHEMA = @schemaName
|
|
62
|
-
ORDER BY ORDINAL_POSITION
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
query = `
|
|
67
|
-
SELECT
|
|
68
|
-
COLUMN_NAME as name,
|
|
69
|
-
DATA_TYPE as type,
|
|
70
|
-
CHARACTER_MAXIMUM_LENGTH as max_length,
|
|
71
|
-
IS_NULLABLE as nullable,
|
|
72
|
-
COLUMN_DEFAULT as default_value,
|
|
73
|
-
ORDINAL_POSITION as position
|
|
74
|
-
FROM INFORMATION_SCHEMA.COLUMNS
|
|
75
|
-
WHERE TABLE_NAME = @tableName AND TABLE_SCHEMA = @schemaName
|
|
76
|
-
ORDER BY ORDINAL_POSITION
|
|
77
|
-
`;
|
|
78
|
-
}
|
|
79
|
-
request.input("tableName", sql.NVarChar, actualTableName);
|
|
80
|
-
request.input("schemaName", sql.NVarChar, schemaName);
|
|
81
|
-
const result = await request.query(query);
|
|
82
|
-
if (result.recordset.length === 0) {
|
|
83
|
-
return {
|
|
84
|
-
success: false,
|
|
85
|
-
message: `Table '${schemaName}.${actualTableName}' not found${database ? ` in database [${database}]` : ""}.`,
|
|
86
|
-
error: "TABLE_NOT_FOUND",
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
success: true,
|
|
91
|
-
message: `Described table '${schemaName}.${actualTableName}'${database ? ` in [${database}]` : ""}`,
|
|
92
|
-
database: database || undefined,
|
|
93
|
-
schema: schemaName,
|
|
94
|
-
tableName: actualTableName,
|
|
95
|
-
columnCount: result.recordset.length,
|
|
96
|
-
columns: result.recordset,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return {
|
|
101
|
-
success: false,
|
|
102
|
-
message: `Failed to describe table: ${error}`,
|
|
103
|
-
error: "QUERY_FAILED",
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
//# sourceMappingURL=DescribeTableTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DescribeTableTool.js","sourceRoot":"","sources":["../../src/tools/DescribeTableTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,OAAO,iBAAiB;IAA9B;QAEE,SAAI,GAAG,gBAAgB,CAAC;QACxB,gBAAW,GACT,gFAAgF;YAChF,6EAA6E,CAAC;QAChF,gBAAW,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qEAAqE;iBACnF;gBACD,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oB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
|
-
export declare class DropTableTool implements Tool {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
inputSchema: any;
|
|
7
|
-
run(params: any): Promise<{
|
|
8
|
-
success: boolean;
|
|
9
|
-
message: string;
|
|
10
|
-
}>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=DropTableTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropTableTool.d.ts","sourceRoot":"","sources":["../../src/tools/DropTableTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE1D,qBAAa,aAAc,YAAW,IAAI;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,SAAgB;IACpB,WAAW,SAA4C;IACvD,WAAW,EAMN,GAAG,CAAC;IAEH,GAAG,CAAC,MAAM,EAAE,GAAG;;;;CAqBtB"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
export class DropTableTool {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.name = "drop_table";
|
|
5
|
-
this.description = "Drops a table from the MSSQL Database.";
|
|
6
|
-
this.inputSchema = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: {
|
|
9
|
-
tableName: { type: "string", description: "Name of the table to drop" }
|
|
10
|
-
},
|
|
11
|
-
required: ["tableName"],
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
async run(params) {
|
|
15
|
-
try {
|
|
16
|
-
const { tableName } = params;
|
|
17
|
-
// Basic validation to prevent SQL injection
|
|
18
|
-
if (!/^[\w\d_]+$/.test(tableName)) {
|
|
19
|
-
throw new Error("Invalid table name.");
|
|
20
|
-
}
|
|
21
|
-
const query = `DROP TABLE [${tableName}]`;
|
|
22
|
-
await new sql.Request(params.pool).query(query);
|
|
23
|
-
return {
|
|
24
|
-
success: true,
|
|
25
|
-
message: `Table '${tableName}' dropped successfully.`
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error("Error dropping table:", error);
|
|
30
|
-
return {
|
|
31
|
-
success: false,
|
|
32
|
-
message: `Failed to drop table: ${error}`
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=DropTableTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropTableTool.js","sourceRoot":"","sources":["../../src/tools/DropTableTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,MAAM,OAAO,aAAa;IAA1B;QAEE,SAAI,GAAG,YAAY,CAAC;QACpB,gBAAW,GAAG,wCAAwC,CAAC;QACvD,gBAAW,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B,EAAE;aACxE;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;SACjB,CAAC;IAuBX,CAAC;IArBC,KAAK,CAAC,GAAG,CAAC,MAAW;QACnB,IAAI,CAAC;YACH,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;YAC7B,4CAA4C;YAC5C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACzC,CAAC;YACD,MAAM,KAAK,GAAG,eAAe,SAAS,GAAG,CAAC;YAC1C,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,UAAU,SAAS,yBAAyB;aACtD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,yBAAyB,KAAK,EAAE;aAC1C,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
export declare class ExplainQueryTool implements Tool {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
inputSchema: any;
|
|
7
|
-
run(params: any): Promise<{
|
|
8
|
-
success: boolean;
|
|
9
|
-
message: string;
|
|
10
|
-
hasPlanXml: boolean;
|
|
11
|
-
} | {
|
|
12
|
-
success: boolean;
|
|
13
|
-
message: string;
|
|
14
|
-
error: string;
|
|
15
|
-
} | {
|
|
16
|
-
planXml: string;
|
|
17
|
-
success: boolean;
|
|
18
|
-
message: string;
|
|
19
|
-
hasPlanXml: boolean;
|
|
20
|
-
error?: undefined;
|
|
21
|
-
}>;
|
|
22
|
-
private extractPlanXml;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=ExplainQueryTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExplainQueryTool.d.ts","sourceRoot":"","sources":["../../src/tools/ExplainQueryTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAG1D,qBAAa,gBAAiB,YAAW,IAAI;IAC3C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,SAAmB;IACvB,WAAW,SAAgG;IAE3G,WAAW,EAiBN,GAAG,CAAC;IAEH,GAAG,CAAC,MAAM,EAAE,GAAG;;;;;;;;;;;;;;;IA4DrB,OAAO,CAAC,cAAc;CAuBvB"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import sql from "mssql";
|
|
2
|
-
import { getEnvironmentManager } from "../config/EnvironmentManager.js";
|
|
3
|
-
export class ExplainQueryTool {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.name = "explain_query";
|
|
6
|
-
this.description = "Generates an estimated execution plan (SHOWPLAN_XML) for a SQL query without executing it.";
|
|
7
|
-
this.inputSchema = {
|
|
8
|
-
type: "object",
|
|
9
|
-
properties: {
|
|
10
|
-
query: {
|
|
11
|
-
type: "string",
|
|
12
|
-
description: "SQL statement to analyze (typically SELECT/UPDATE/INSERT/DELETE).",
|
|
13
|
-
},
|
|
14
|
-
environment: {
|
|
15
|
-
type: "string",
|
|
16
|
-
description: "Optional environment name to target (prod, staging, etc).",
|
|
17
|
-
},
|
|
18
|
-
includePlanXml: {
|
|
19
|
-
type: "boolean",
|
|
20
|
-
description: "If true (default), returns the raw SHOWPLAN XML. Set false for summary only.",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
required: ["query"],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async run(params) {
|
|
27
|
-
const { query, includePlanXml = true, environment } = params ?? {};
|
|
28
|
-
if (typeof query !== "string" || !query.trim()) {
|
|
29
|
-
return {
|
|
30
|
-
success: false,
|
|
31
|
-
message: "explain_query requires a non-empty SQL string.",
|
|
32
|
-
error: "INVALID_QUERY",
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
const sanitizedQuery = query.trim();
|
|
36
|
-
const envManager = getEnvironmentManager();
|
|
37
|
-
const pool = await envManager.getConnection(environment);
|
|
38
|
-
let showplanEnabled = false;
|
|
39
|
-
try {
|
|
40
|
-
const planRequest = new sql.Request(pool);
|
|
41
|
-
await planRequest.batch("SET SHOWPLAN_XML ON;");
|
|
42
|
-
showplanEnabled = true;
|
|
43
|
-
const explainRequest = new sql.Request(pool);
|
|
44
|
-
const result = await explainRequest.query(sanitizedQuery);
|
|
45
|
-
const planOutput = result.recordset?.[0];
|
|
46
|
-
const planXml = this.extractPlanXml(planOutput);
|
|
47
|
-
const summary = {
|
|
48
|
-
success: true,
|
|
49
|
-
message: "Generated estimated execution plan.",
|
|
50
|
-
hasPlanXml: Boolean(planXml),
|
|
51
|
-
};
|
|
52
|
-
if (includePlanXml && planXml) {
|
|
53
|
-
return {
|
|
54
|
-
...summary,
|
|
55
|
-
planXml,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return summary;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
message: `Failed to generate plan: ${errorMessage}`,
|
|
65
|
-
error: "SHOWPLAN_FAILED",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
if (showplanEnabled) {
|
|
70
|
-
try {
|
|
71
|
-
const resetRequest = new sql.Request(pool);
|
|
72
|
-
await resetRequest.batch("SET SHOWPLAN_XML OFF;");
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
// ignore
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
extractPlanXml(row) {
|
|
81
|
-
if (!row) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
const knownColumns = [
|
|
85
|
-
"ShowPlanXML",
|
|
86
|
-
"Microsoft SQL Server 2005 XML Showplan",
|
|
87
|
-
"Plan",
|
|
88
|
-
];
|
|
89
|
-
for (const column of knownColumns) {
|
|
90
|
-
if (row[column]) {
|
|
91
|
-
return row[column];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const firstXml = Object.values(row).find((value) => typeof value === "string" && value.trim().startsWith("<?xml"));
|
|
95
|
-
return firstXml ?? null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=ExplainQueryTool.js.map
|