@vicinitysoftware/mcp-sql 1.0.0 → 1.0.5
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 +42 -23
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -2,32 +2,47 @@
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import
|
|
5
|
+
import pkg from "mssql";
|
|
6
|
+
const { ConnectionPool, NVarChar } = pkg;
|
|
6
7
|
import * as fs from "fs";
|
|
7
8
|
import * as path from "path";
|
|
8
9
|
import * as url from "url";
|
|
9
10
|
import * as dotenv from "dotenv";
|
|
10
11
|
dotenv.config();
|
|
11
12
|
// ── Database config ───────────────────────────────────────────────────────────
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
const useWindowsAuth = !process.env.VICINITY_SQL_USER && !process.env.VICINITY_SQL_PASSWORD;
|
|
14
|
+
const dbConfig = useWindowsAuth
|
|
15
|
+
? {
|
|
16
|
+
server: process.env.VICINITY_SQL_SERVER,
|
|
17
|
+
database: process.env.VICINITY_SQL_DATABASE,
|
|
18
|
+
options: {
|
|
19
|
+
trustedConnection: true,
|
|
20
|
+
trustServerCertificate: true,
|
|
21
|
+
connectTimeout: 15000,
|
|
22
|
+
requestTimeout: parseInt(process.env.VICINITY_SQL_TIMEOUT || "30000"),
|
|
23
|
+
},
|
|
24
|
+
pool: { max: 5, min: 0, idleTimeoutMillis: 30000 },
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
server: process.env.VICINITY_SQL_SERVER,
|
|
28
|
+
database: process.env.VICINITY_SQL_DATABASE,
|
|
29
|
+
user: process.env.VICINITY_SQL_USER,
|
|
30
|
+
password: process.env.VICINITY_SQL_PASSWORD,
|
|
31
|
+
port: parseInt(process.env.VICINITY_SQL_PORT || "1433"),
|
|
32
|
+
options: {
|
|
33
|
+
encrypt: process.env.VICINITY_SQL_ENCRYPT === "true",
|
|
34
|
+
trustServerCertificate: process.env.VICINITY_SQL_TRUST_SERVER_CERT !== "false",
|
|
35
|
+
connectTimeout: 15000,
|
|
36
|
+
requestTimeout: parseInt(process.env.VICINITY_SQL_TIMEOUT || "30000"),
|
|
37
|
+
},
|
|
38
|
+
pool: { max: 5, min: 0, idleTimeoutMillis: 30000 },
|
|
39
|
+
};
|
|
26
40
|
const MAX_ROWS = parseInt(process.env.VICINITY_SQL_MAX_ROWS || "500");
|
|
27
41
|
let pool;
|
|
28
42
|
async function getPool() {
|
|
29
43
|
if (!pool) {
|
|
30
|
-
pool =
|
|
44
|
+
pool = new ConnectionPool(dbConfig);
|
|
45
|
+
await pool.connect();
|
|
31
46
|
}
|
|
32
47
|
return pool;
|
|
33
48
|
}
|
|
@@ -43,12 +58,12 @@ async function runQuery(querySql, maxRows = 100) {
|
|
|
43
58
|
if (rows.length === 0)
|
|
44
59
|
return "Query returned no results.";
|
|
45
60
|
const columns = Object.keys(rows[0]);
|
|
46
|
-
const colWidths = columns.map(c => Math.max(c.length, ...rows.map(r => String(r[c] ?? "NULL").length)));
|
|
61
|
+
const colWidths = columns.map((c) => Math.max(c.length, ...rows.map((r) => String(r[c] ?? "NULL").length)));
|
|
47
62
|
const fmt = (vals) => vals.map((v, i) => v.padEnd(colWidths[i])).join(" ");
|
|
48
63
|
const lines = [
|
|
49
64
|
fmt(columns),
|
|
50
|
-
colWidths.map(w => "-".repeat(w)).join("--"),
|
|
51
|
-
...rows.map(r => fmt(columns.map(c => String(r[c] ?? "NULL")))),
|
|
65
|
+
colWidths.map((w) => "-".repeat(w)).join("--"),
|
|
66
|
+
...rows.map((r) => fmt(columns.map((c) => String(r[c] ?? "NULL")))),
|
|
52
67
|
`\n(${rows.length} rows${result.recordset.length > limit ? " — truncated" : ""})`,
|
|
53
68
|
];
|
|
54
69
|
return lines.join("\n");
|
|
@@ -158,8 +173,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
158
173
|
else if (name === "describe_table") {
|
|
159
174
|
const p = await getPool();
|
|
160
175
|
const res = await p.request()
|
|
161
|
-
.input("table",
|
|
162
|
-
.input("schema",
|
|
176
|
+
.input("table", NVarChar, args?.table_name)
|
|
177
|
+
.input("schema", NVarChar, args?.schema ?? "dbo")
|
|
163
178
|
.query(`
|
|
164
179
|
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, CHARACTER_MAXIMUM_LENGTH
|
|
165
180
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
@@ -170,7 +185,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
170
185
|
result = `Table '${args?.schema ?? "dbo"}.${args?.table_name}' not found.`;
|
|
171
186
|
}
|
|
172
187
|
else {
|
|
173
|
-
const lines = [
|
|
188
|
+
const lines = [
|
|
189
|
+
`${"Column".padEnd(40)} ${"Type".padEnd(20)} ${"Nullable".padEnd(10)} MaxLen`,
|
|
190
|
+
"-".repeat(80),
|
|
191
|
+
];
|
|
174
192
|
for (const r of res.recordset) {
|
|
175
193
|
lines.push(`${String(r.COLUMN_NAME).padEnd(40)} ${String(r.DATA_TYPE).padEnd(20)} ${String(r.IS_NULLABLE).padEnd(10)} ${r.CHARACTER_MAXIMUM_LENGTH ?? ""}`);
|
|
176
194
|
}
|
|
@@ -186,7 +204,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
186
204
|
return { content: [{ type: "text", text: result }] };
|
|
187
205
|
}
|
|
188
206
|
catch (err) {
|
|
189
|
-
|
|
207
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
208
|
+
return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
|
|
190
209
|
}
|
|
191
210
|
});
|
|
192
211
|
// ── Start ─────────────────────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vicinitysoftware/mcp-sql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "MCP server for Vicinity Software SQL databases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"resources/",
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
|
-
"engines": {
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
|
+
},
|
|
16
18
|
"scripts": {
|
|
17
19
|
"build": "tsc",
|
|
18
20
|
"prepublishOnly": "npm run build"
|
|
@@ -27,4 +29,4 @@
|
|
|
27
29
|
"@types/node": "^20.0.0",
|
|
28
30
|
"typescript": "^5.0.0"
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
}
|