@vicinitysoftware/mcp-sql 1.0.1 → 1.0.6

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 CHANGED
@@ -2,6 +2,8 @@
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 pkg from "mssql";
6
+ const { ConnectionPool, NVarChar } = pkg;
5
7
  import * as fs from "fs";
6
8
  import * as path from "path";
7
9
  import * as url from "url";
@@ -9,33 +11,33 @@ import * as dotenv from "dotenv";
9
11
  dotenv.config();
10
12
  // ── Database config ───────────────────────────────────────────────────────────
11
13
  const useWindowsAuth = !process.env.VICINITY_SQL_USER && !process.env.VICINITY_SQL_PASSWORD;
12
- const dbConfig = {
13
- server: process.env.VICINITY_SQL_SERVER,
14
- database: process.env.VICINITY_SQL_DATABASE,
15
- ...(useWindowsAuth
16
- ? {
17
- options: {
18
- trustedConnection: true,
19
- trustServerCertificate: true,
20
- connectTimeout: 15000,
21
- requestTimeout: parseInt(process.env.VICINITY_SQL_TIMEOUT || "30000"),
22
- },
23
- }
24
- : {
25
- user: process.env.VICINITY_SQL_USER,
26
- password: process.env.VICINITY_SQL_PASSWORD,
27
- port: parseInt(process.env.VICINITY_SQL_PORT || "1433"),
28
- options: {
29
- encrypt: process.env.VICINITY_SQL_ENCRYPT === "true",
30
- trustServerCertificate: process.env.VICINITY_SQL_TRUST_SERVER_CERT !== "false",
31
- connectTimeout: 15000,
32
- requestTimeout: parseInt(process.env.VICINITY_SQL_TIMEOUT || "30000"),
33
- },
34
- }),
35
- pool: { max: 5, min: 0, idleTimeoutMillis: 30000 },
36
- };
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
+ };
37
40
  const MAX_ROWS = parseInt(process.env.VICINITY_SQL_MAX_ROWS || "500");
38
- import { ConnectionPool, NVarChar } from "mssql";
39
41
  let pool;
40
42
  async function getPool() {
41
43
  if (!pool) {
@@ -56,12 +58,12 @@ async function runQuery(querySql, maxRows = 100) {
56
58
  if (rows.length === 0)
57
59
  return "Query returned no results.";
58
60
  const columns = Object.keys(rows[0]);
59
- 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)));
60
62
  const fmt = (vals) => vals.map((v, i) => v.padEnd(colWidths[i])).join(" ");
61
63
  const lines = [
62
64
  fmt(columns),
63
- colWidths.map(w => "-".repeat(w)).join("--"),
64
- ...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")))),
65
67
  `\n(${rows.length} rows${result.recordset.length > limit ? " — truncated" : ""})`,
66
68
  ];
67
69
  return lines.join("\n");
@@ -183,7 +185,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
183
185
  result = `Table '${args?.schema ?? "dbo"}.${args?.table_name}' not found.`;
184
186
  }
185
187
  else {
186
- const lines = [`${"Column".padEnd(40)} ${"Type".padEnd(20)} ${"Nullable".padEnd(10)} MaxLen`, "-".repeat(80)];
188
+ const lines = [
189
+ `${"Column".padEnd(40)} ${"Type".padEnd(20)} ${"Nullable".padEnd(10)} MaxLen`,
190
+ "-".repeat(80),
191
+ ];
187
192
  for (const r of res.recordset) {
188
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 ?? ""}`);
189
194
  }
@@ -199,7 +204,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
199
204
  return { content: [{ type: "text", text: result }] };
200
205
  }
201
206
  catch (err) {
202
- return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
207
+ const message = err instanceof Error ? err.message : String(err);
208
+ return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
203
209
  }
204
210
  });
205
211
  // ── Start ─────────────────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vicinitysoftware/mcp-sql",
3
- "version": "1.0.1",
3
+ "version": "1.0.6",
4
4
  "description": "MCP server for Vicinity Software SQL databases",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",