@vaultcompass/vault-guard-mcp 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +303 -0
  3. package/package.json +46 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vault & Compass LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,303 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // src/index.ts
28
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
29
+
30
+ // src/server.ts
31
+ var import_path2 = __toESM(require("path"));
32
+ var import_fs2 = __toESM(require("fs"));
33
+ var import_zod = require("zod");
34
+ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
35
+ var import_vault_guard_core2 = require("@vaultcompass/vault-guard-core");
36
+ var import_vault_guard_telemetry = require("@vaultcompass/vault-guard-telemetry");
37
+
38
+ // src/workspace-scan.ts
39
+ var import_fs = __toESM(require("fs"));
40
+ var import_path = __toESM(require("path"));
41
+ var import_vault_guard_core = require("@vaultcompass/vault-guard-core");
42
+ var MAX_FILE_SIZE = 10 * 1024 * 1024;
43
+ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
44
+ ".png",
45
+ ".jpg",
46
+ ".jpeg",
47
+ ".gif",
48
+ ".ico",
49
+ ".pdf",
50
+ ".zip",
51
+ ".tar",
52
+ ".gz",
53
+ ".exe",
54
+ ".dll",
55
+ ".so",
56
+ ".dylib",
57
+ ".bin"
58
+ ]);
59
+ function isBinaryFile(filePath) {
60
+ return BINARY_EXTENSIONS.has(import_path.default.extname(filePath).toLowerCase());
61
+ }
62
+ async function scanWorkspaceDirectory(root, scanner, concurrency = 10) {
63
+ const files = await (0, import_vault_guard_core.getFilesToScanAsync)(root, false);
64
+ const results = [];
65
+ let filesScanned = 0;
66
+ let bytesScanned = 0;
67
+ const scanOne = async (file) => {
68
+ try {
69
+ if (isBinaryFile(file)) return;
70
+ const st = await import_fs.default.promises.stat(file);
71
+ if (!st.isFile()) return;
72
+ filesScanned += 1;
73
+ bytesScanned += st.size;
74
+ const matches = await (0, import_vault_guard_core.scanTextFileAsync)(scanner, file, { maxFileBytes: MAX_FILE_SIZE });
75
+ if (matches.length > 0) {
76
+ results.push({ file, matches });
77
+ }
78
+ } catch {
79
+ }
80
+ };
81
+ for (let i = 0; i < files.length; i += concurrency) {
82
+ const batch = files.slice(i, i + concurrency);
83
+ await Promise.all(batch.map(scanOne));
84
+ }
85
+ return { results, filesScanned, bytesScanned };
86
+ }
87
+
88
+ // src/server.ts
89
+ function makeScanner() {
90
+ const cwd = process.cwd();
91
+ let cfg;
92
+ try {
93
+ cfg = (0, import_vault_guard_core2.loadConfig)(cwd);
94
+ } catch (e) {
95
+ if (e instanceof import_vault_guard_core2.ConfigError) {
96
+ process.stderr.write(
97
+ `vault-guard MCP: ignoring broken config at ${e.filePath} \u2014 ${e.message}
98
+ `
99
+ );
100
+ cfg = {};
101
+ } else {
102
+ throw e;
103
+ }
104
+ }
105
+ return new import_vault_guard_core2.SecretScanner(cfg);
106
+ }
107
+ function toolPayload(obj) {
108
+ return {
109
+ content: [{ type: "text", text: JSON.stringify(obj, null, 2) }]
110
+ };
111
+ }
112
+ function createMcpServer() {
113
+ const server = new import_mcp.McpServer(
114
+ { name: "vault-guard", version: "1.0.0" },
115
+ {
116
+ capabilities: {
117
+ tools: {}
118
+ },
119
+ instructions: "Vault Guard MCP: scan workspaces/files/text for secrets (SARIF-shaped JSON), report token estimates, and record opt-in session/usage events to local ~/.vault-guard/usage.sqlite."
120
+ }
121
+ );
122
+ const telemetry = new import_vault_guard_telemetry.TelemetryStore();
123
+ const tokenCounter = new import_vault_guard_core2.TokenCounter();
124
+ server.registerTool(
125
+ "scan_workspace",
126
+ {
127
+ title: "Scan workspace directory",
128
+ description: "Run the Vault Guard secret scanner on a directory (respects .gitignore). Returns JSON, SARIF string, and summary.",
129
+ inputSchema: {
130
+ root: import_zod.z.string().optional().describe("Directory to scan (default: process.cwd())")
131
+ }
132
+ },
133
+ async ({ root }) => {
134
+ const scanner = makeScanner();
135
+ const dir = import_path2.default.resolve(process.cwd(), root ?? ".");
136
+ const t0 = Date.now();
137
+ const { results, filesScanned, bytesScanned } = await scanWorkspaceDirectory(dir, scanner);
138
+ const run = {
139
+ duration_ms: Date.now() - t0,
140
+ files_scanned: filesScanned,
141
+ bytes_scanned: bytesScanned,
142
+ patterns_active: scanner.getActivePatternCount()
143
+ };
144
+ return toolPayload({
145
+ summary: {
146
+ files_with_secrets: results.length,
147
+ total_matches: results.reduce((n, r) => n + r.matches.length, 0)
148
+ },
149
+ json: JSON.parse((0, import_vault_guard_core2.formatJson)(results, { cwd: dir, run })),
150
+ sarif: (0, import_vault_guard_core2.formatSarif)(results, { cwd: dir, run }),
151
+ results
152
+ });
153
+ }
154
+ );
155
+ server.registerTool(
156
+ "scan_file",
157
+ {
158
+ title: "Scan a single file",
159
+ description: "Scan one file on disk for secrets. Returns JSON + SARIF.",
160
+ inputSchema: {
161
+ file_path: import_zod.z.string().describe("Absolute or relative path to a file")
162
+ }
163
+ },
164
+ async ({ file_path }) => {
165
+ const scanner = makeScanner();
166
+ const fp = import_path2.default.resolve(process.cwd(), file_path);
167
+ if (!import_fs2.default.existsSync(fp) || !import_fs2.default.statSync(fp).isFile()) {
168
+ return toolPayload({ error: "not_a_file", path: fp });
169
+ }
170
+ const t0 = Date.now();
171
+ const matches = scanner.scan(fp);
172
+ const st = import_fs2.default.statSync(fp);
173
+ const run = {
174
+ duration_ms: Date.now() - t0,
175
+ files_scanned: 1,
176
+ bytes_scanned: st.size,
177
+ patterns_active: scanner.getActivePatternCount()
178
+ };
179
+ const results = matches.length ? [{ file: fp, matches }] : [];
180
+ return toolPayload({
181
+ summary: { files_with_secrets: results.length, total_matches: matches.length },
182
+ json: JSON.parse((0, import_vault_guard_core2.formatJson)(results, { cwd: process.cwd(), run })),
183
+ sarif: (0, import_vault_guard_core2.formatSarif)(results, { cwd: process.cwd(), run })
184
+ });
185
+ }
186
+ );
187
+ server.registerTool(
188
+ "scan_text",
189
+ {
190
+ title: "Scan pasted text",
191
+ description: "Scan arbitrary UTF-8 text (e.g. proposed AI edit). Optional virtual_path for SARIF artifact URI only.",
192
+ inputSchema: {
193
+ text: import_zod.z.string().describe("UTF-8 content to scan"),
194
+ virtual_path: import_zod.z.string().optional().describe("Synthetic path label for SARIF (default: inline://snippet)")
195
+ }
196
+ },
197
+ async ({ text, virtual_path }) => {
198
+ const scanner = makeScanner();
199
+ const t0 = Date.now();
200
+ const matches = scanner.scanContent(text);
201
+ const label = virtual_path ?? "inline://snippet";
202
+ const results = matches.length ? [{ file: label, matches }] : [];
203
+ const bytes = Buffer.byteLength(text, "utf8");
204
+ const run = {
205
+ duration_ms: Date.now() - t0,
206
+ files_scanned: 1,
207
+ bytes_scanned: bytes,
208
+ patterns_active: scanner.getActivePatternCount()
209
+ };
210
+ return toolPayload({
211
+ summary: { total_matches: matches.length },
212
+ // virtual_path is a label, not a real path; skip relativization to preserve it verbatim.
213
+ json: JSON.parse((0, import_vault_guard_core2.formatJson)(results, { cwd: null, run })),
214
+ sarif: (0, import_vault_guard_core2.formatSarif)(results, { cwd: null, run })
215
+ });
216
+ }
217
+ );
218
+ server.registerTool(
219
+ "report_token_usage",
220
+ {
221
+ title: "Estimate token usage",
222
+ description: "Rough on-disk token estimate for paths (same heuristic as vault-guard tokens). Does not call cloud APIs.",
223
+ inputSchema: {
224
+ paths: import_zod.z.array(import_zod.z.string()).optional().describe("Files or directories to include (default: cwd)")
225
+ }
226
+ },
227
+ async ({ paths }) => {
228
+ const targets = paths && paths.length > 0 ? paths : [process.cwd()];
229
+ let total = 0;
230
+ const breakdown = {};
231
+ const walkFile = (file) => {
232
+ try {
233
+ if (!import_fs2.default.existsSync(file)) return;
234
+ const st = import_fs2.default.statSync(file);
235
+ if (st.isFile()) {
236
+ const n = tokenCounter.countTokensInFile(file);
237
+ total += n;
238
+ const ext = import_path2.default.extname(file) || "(no-ext)";
239
+ breakdown[ext] = (breakdown[ext] ?? 0) + n;
240
+ } else if (st.isDirectory()) {
241
+ const entries = import_fs2.default.readdirSync(file, { withFileTypes: true });
242
+ for (const e of entries) {
243
+ if (e.name === "node_modules" || e.name === ".git") continue;
244
+ walkFile(import_path2.default.join(file, e.name));
245
+ }
246
+ }
247
+ } catch {
248
+ }
249
+ };
250
+ for (const t of targets) {
251
+ walkFile(import_path2.default.resolve(process.cwd(), t));
252
+ }
253
+ const estCostAnthropic = tokenCounter.calculateCost("anthropic", total, 0);
254
+ return toolPayload({
255
+ total_tokens_estimated: total,
256
+ breakdown,
257
+ est_cost_usd_anthropic_input_only: Math.round(estCostAnthropic * 1e4) / 1e4
258
+ });
259
+ }
260
+ );
261
+ server.registerTool(
262
+ "record_session_event",
263
+ {
264
+ title: "Record session / accuracy event",
265
+ description: "Append an opt-in local telemetry row (e.g. accept/revert/secret_blocked). Stored under ~/.vault-guard/usage.sqlite only.",
266
+ inputSchema: {
267
+ event_type: import_zod.z.string().describe("e.g. accept | reject | revert | secret_blocked | completion"),
268
+ model: import_zod.z.string().optional(),
269
+ cwd: import_zod.z.string().optional(),
270
+ language: import_zod.z.string().optional(),
271
+ lines_accepted: import_zod.z.number().int().optional(),
272
+ lines_suggested: import_zod.z.number().int().optional(),
273
+ lines_reverted: import_zod.z.number().int().optional(),
274
+ extra: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional()
275
+ }
276
+ },
277
+ async (args) => {
278
+ telemetry.recordSession({
279
+ eventType: args.event_type,
280
+ model: args.model,
281
+ cwd: args.cwd,
282
+ language: args.language,
283
+ linesAccepted: args.lines_accepted,
284
+ linesSuggested: args.lines_suggested,
285
+ linesReverted: args.lines_reverted,
286
+ extra: args.extra
287
+ });
288
+ return toolPayload({ ok: true });
289
+ }
290
+ );
291
+ return server;
292
+ }
293
+
294
+ // src/index.ts
295
+ async function main() {
296
+ const server = createMcpServer();
297
+ const transport = new import_stdio.StdioServerTransport();
298
+ await server.connect(transport);
299
+ }
300
+ void main().catch((err) => {
301
+ console.error(err);
302
+ process.exit(1);
303
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@vaultcompass/vault-guard-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for Vault Guard — scan tools + local telemetry hooks",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "vault-guard-mcp": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/vaultcompasshq/vault-guard.git",
18
+ "directory": "packages/mcp"
19
+ },
20
+ "engines": {
21
+ "node": ">=22.0.0",
22
+ "npm": ">=9.0.0",
23
+ "pnpm": ">=9.0.0"
24
+ },
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.29.0",
28
+ "zod": "^4.4.3",
29
+ "@vaultcompass/vault-guard-core": "1.0.0",
30
+ "@vaultcompass/vault-guard-telemetry": "1.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^30.0.0",
34
+ "@types/node": "^25.9.1",
35
+ "esbuild": "^0.25.0",
36
+ "jest": "^30.4.2",
37
+ "ts-jest": "^29.4.11",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "scripts": {
41
+ "build": "node scripts/build.cjs",
42
+ "test": "jest",
43
+ "test:coverage": "jest --coverage",
44
+ "start": "node dist/index.js"
45
+ }
46
+ }