@connorbritain/mssql-mcp-server 0.1.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/README.md +61 -0
- package/dist/audit/AuditLogger.d.ts +25 -0
- package/dist/audit/AuditLogger.d.ts.map +1 -0
- package/dist/audit/AuditLogger.js +91 -0
- package/dist/audit/AuditLogger.js.map +1 -0
- package/dist/config/EnvironmentManager.d.ts +36 -0
- package/dist/config/EnvironmentManager.d.ts.map +1 -0
- package/dist/config/EnvironmentManager.js +185 -0
- package/dist/config/EnvironmentManager.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +615 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/CreateIndexTool.d.ts +24 -0
- package/dist/tools/CreateIndexTool.d.ts.map +1 -0
- package/dist/tools/CreateIndexTool.js +64 -0
- package/dist/tools/CreateIndexTool.js.map +1 -0
- package/dist/tools/CreateTableTool.d.ts +12 -0
- package/dist/tools/CreateTableTool.d.ts.map +1 -0
- package/dist/tools/CreateTableTool.js +49 -0
- package/dist/tools/CreateTableTool.js.map +1 -0
- package/dist/tools/DeleteDataTool.d.ts +56 -0
- package/dist/tools/DeleteDataTool.d.ts.map +1 -0
- package/dist/tools/DeleteDataTool.js +103 -0
- package/dist/tools/DeleteDataTool.js.map +1 -0
- package/dist/tools/DescribeTableTool.d.ts +20 -0
- package/dist/tools/DescribeTableTool.d.ts.map +1 -0
- package/dist/tools/DescribeTableTool.js +34 -0
- package/dist/tools/DescribeTableTool.js.map +1 -0
- package/dist/tools/DropTableTool.d.ts +12 -0
- package/dist/tools/DropTableTool.d.ts.map +1 -0
- package/dist/tools/DropTableTool.js +37 -0
- package/dist/tools/DropTableTool.js.map +1 -0
- package/dist/tools/ExplainQueryTool.d.ts +24 -0
- package/dist/tools/ExplainQueryTool.d.ts.map +1 -0
- package/dist/tools/ExplainQueryTool.js +98 -0
- package/dist/tools/ExplainQueryTool.js.map +1 -0
- package/dist/tools/InsertDataTool.d.ts +17 -0
- package/dist/tools/InsertDataTool.d.ts.map +1 -0
- package/dist/tools/InsertDataTool.js +144 -0
- package/dist/tools/InsertDataTool.js.map +1 -0
- package/dist/tools/ListTableTool.d.ts +18 -0
- package/dist/tools/ListTableTool.d.ts.map +1 -0
- package/dist/tools/ListTableTool.js +43 -0
- package/dist/tools/ListTableTool.js.map +1 -0
- package/dist/tools/ProfileTableTool.d.ts +78 -0
- package/dist/tools/ProfileTableTool.d.ts.map +1 -0
- package/dist/tools/ProfileTableTool.js +372 -0
- package/dist/tools/ProfileTableTool.js.map +1 -0
- package/dist/tools/ReadDataTool.d.ts +58 -0
- package/dist/tools/ReadDataTool.d.ts.map +1 -0
- package/dist/tools/ReadDataTool.js +265 -0
- package/dist/tools/ReadDataTool.js.map +1 -0
- package/dist/tools/RelationshipInspectorTool.d.ts +46 -0
- package/dist/tools/RelationshipInspectorTool.d.ts.map +1 -0
- package/dist/tools/RelationshipInspectorTool.js +155 -0
- package/dist/tools/RelationshipInspectorTool.js.map +1 -0
- package/dist/tools/SearchSchemaTool.d.ts +88 -0
- package/dist/tools/SearchSchemaTool.d.ts.map +1 -0
- package/dist/tools/SearchSchemaTool.js +236 -0
- package/dist/tools/SearchSchemaTool.js.map +1 -0
- package/dist/tools/TestConnectionTool.d.ts +36 -0
- package/dist/tools/TestConnectionTool.d.ts.map +1 -0
- package/dist/tools/TestConnectionTool.js +155 -0
- package/dist/tools/TestConnectionTool.js.map +1 -0
- package/dist/tools/UpdateDataTool.d.ts +61 -0
- package/dist/tools/UpdateDataTool.d.ts.map +1 -0
- package/dist/tools/UpdateDataTool.js +117 -0
- package/dist/tools/UpdateDataTool.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import sql from "mssql";
|
|
2
|
+
export class UpdateDataTool {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.name = "update_data";
|
|
5
|
+
this.description = "Updates data in an MSSQL Database table with preview and confirmation. Shows affected rows before committing changes. The WHERE clause must be provided for security.";
|
|
6
|
+
this.inputSchema = {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
tableName: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "Name of the table to update"
|
|
12
|
+
},
|
|
13
|
+
updates: {
|
|
14
|
+
type: "object",
|
|
15
|
+
description: "Key-value pairs of columns to update. Example: { 'status': 'active', 'last_updated': '2025-01-01' }",
|
|
16
|
+
},
|
|
17
|
+
whereClause: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "WHERE clause to identify which records to update. Example: \"genre = 'comedy' AND created_date <= '2025-07-05'\""
|
|
20
|
+
},
|
|
21
|
+
confirmUpdate: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
description: "Set to true to confirm and execute the update after preview. First call without this to see preview.",
|
|
24
|
+
},
|
|
25
|
+
maxRows: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Maximum number of rows allowed to update. Defaults to 1000 for safety.",
|
|
28
|
+
},
|
|
29
|
+
environment: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Optional environment name to target",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ["tableName", "updates", "whereClause"],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async run(params) {
|
|
38
|
+
let query;
|
|
39
|
+
try {
|
|
40
|
+
const { tableName, updates, whereClause, confirmUpdate, maxRows, environment } = params;
|
|
41
|
+
// Basic validation: ensure whereClause is not empty
|
|
42
|
+
if (!whereClause || whereClause.trim() === '') {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
message: "WHERE clause is required for security reasons. Use 'WHERE 1=1' to update all rows (not recommended).",
|
|
46
|
+
error: "MISSING_WHERE_CLAUSE",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const maxAllowed = maxRows || UpdateDataTool.MAX_ROWS_DEFAULT;
|
|
50
|
+
// Step 1: Get count of affected rows
|
|
51
|
+
const countQuery = `SELECT COUNT(*) as affectedRows FROM ${tableName} WHERE ${whereClause}`;
|
|
52
|
+
const countRequest = new sql.Request();
|
|
53
|
+
const countResult = await countRequest.query(countQuery);
|
|
54
|
+
const affectedRows = countResult.recordset[0].affectedRows;
|
|
55
|
+
if (affectedRows === 0) {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
message: "No rows match the WHERE clause. No update will be performed.",
|
|
59
|
+
error: "NO_ROWS_MATCHED",
|
|
60
|
+
affectedRows: 0,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (affectedRows > maxAllowed) {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
message: `Update would affect ${affectedRows} rows, which exceeds the maximum of ${maxAllowed}. Refine your WHERE clause or increase maxRows parameter.`,
|
|
67
|
+
error: "TOO_MANY_ROWS",
|
|
68
|
+
affectedRows,
|
|
69
|
+
maxAllowed,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Step 2: Show preview if not confirmed
|
|
73
|
+
if (!confirmUpdate) {
|
|
74
|
+
const previewQuery = `SELECT TOP 10 * FROM ${tableName} WHERE ${whereClause}`;
|
|
75
|
+
const previewRequest = new sql.Request();
|
|
76
|
+
const previewResult = await previewRequest.query(previewQuery);
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
needsConfirmation: true,
|
|
80
|
+
message: `Preview: ${affectedRows} row(s) will be updated. Review the preview below and re-run with confirmUpdate: true to proceed.`,
|
|
81
|
+
affectedRows,
|
|
82
|
+
preview: previewResult.recordset,
|
|
83
|
+
updates,
|
|
84
|
+
error: "CONFIRMATION_REQUIRED",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Step 3: Execute the update
|
|
88
|
+
const request = new sql.Request();
|
|
89
|
+
// Build SET clause with parameterized queries for security
|
|
90
|
+
const setClause = Object.keys(updates)
|
|
91
|
+
.map((key, index) => {
|
|
92
|
+
const paramName = `update_${index}`;
|
|
93
|
+
request.input(paramName, updates[key]);
|
|
94
|
+
return `[${key}] = @${paramName}`;
|
|
95
|
+
})
|
|
96
|
+
.join(", ");
|
|
97
|
+
query = `UPDATE ${tableName} SET ${setClause} WHERE ${whereClause}`;
|
|
98
|
+
const result = await request.query(query);
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
message: `Successfully updated ${result.rowsAffected[0]} row(s) in table '${tableName}'`,
|
|
102
|
+
rowsAffected: result.rowsAffected[0],
|
|
103
|
+
updates,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error("Error updating data:", error);
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
message: `Failed to update data${query ? ` with '${query}'` : ''}: ${error}`,
|
|
111
|
+
error: "UPDATE_FAILED",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
UpdateDataTool.MAX_ROWS_DEFAULT = 1000;
|
|
117
|
+
//# sourceMappingURL=UpdateDataTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UpdateDataTool.js","sourceRoot":"","sources":["../../src/tools/UpdateDataTool.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,MAAM,OAAO,cAAc;IAA3B;QAEE,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,uKAAuK,CAAC;QACtL,gBAAW,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;iBAC3C;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qGAAqG;iBACnH;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kHAAkH;iBAChI;gBACD,aAA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AAM,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAE1C,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,wBAAwB,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,qBAAqB,SAAS,GAAG;gBACxF,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;gBACpC,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sBAAsB,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;;AAzFuB,+BAAgB,GAAG,IAAI,AAAP,CAAQ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@connorbritain/mssql-mcp-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server for Microsoft SQL Server - enterprise-ready schema discovery, profiling, and safe data operations",
|
|
5
|
+
"keywords": ["mcp", "sql-server", "mssql", "database", "ai", "claude", "windsurf", "model-context-protocol"],
|
|
6
|
+
"author": "Connor England <connor.r.england@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ConnorBritain/mssql-mcp-server.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/ConnorBritain/mssql-mcp-server",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ConnorBritain/mssql-mcp-server/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"bin": {
|
|
18
|
+
"mssql-mcp-server": "dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc && shx chmod +x dist/*.js",
|
|
22
|
+
"prepare": "npm run build",
|
|
23
|
+
"watch": "tsc --watch",
|
|
24
|
+
"start": "node dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/mssql": "^9.1.7",
|
|
31
|
+
"@types/node": "^20.14.2",
|
|
32
|
+
"shx": "^0.3.4",
|
|
33
|
+
"typescript": "^5.4.5"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@azure/identity": "^4.4.0",
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.23.0",
|
|
38
|
+
"dotenv": "^16.4.5",
|
|
39
|
+
"mssql": "^10.0.1"
|
|
40
|
+
},
|
|
41
|
+
"type": "module"
|
|
42
|
+
}
|