vibecheck-mcp-server 2.0.1
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 +191 -0
- package/agent-checkpoint.js +364 -0
- package/architect-tools.js +707 -0
- package/audit-mcp.js +206 -0
- package/codebase-architect-tools.js +838 -0
- package/guardrail-2.0-tools.js +748 -0
- package/guardrail-tools.js +1075 -0
- package/hygiene-tools.js +428 -0
- package/index-v1.js +698 -0
- package/index.js +1409 -0
- package/index.old.js +4137 -0
- package/intelligence-tools.js +664 -0
- package/intent-drift-tools.js +873 -0
- package/mdc-generator.js +298 -0
- package/package.json +47 -0
- package/premium-tools.js +1275 -0
- package/test-mcp.js +108 -0
- package/test-tools.js +36 -0
- package/tier-auth.js +147 -0
package/audit-mcp.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Bridge for MCP Server
|
|
3
|
+
*
|
|
4
|
+
* ES Module wrapper for audit trail functionality in MCP context.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import * as crypto from 'crypto';
|
|
10
|
+
|
|
11
|
+
const AUDIT_DIR = ".guardrail/audit";
|
|
12
|
+
const AUDIT_FILE = "audit.log.jsonl";
|
|
13
|
+
const GENESIS_HASH = "0".repeat(64);
|
|
14
|
+
|
|
15
|
+
function getCurrentTier() {
|
|
16
|
+
return process.env.GUARDRAIL_TIER || "free";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getCurrentActor() {
|
|
20
|
+
const env = process.env;
|
|
21
|
+
const userId = env.GUARDRAIL_USER_ID || env.USER || env.USERNAME || "mcp-client";
|
|
22
|
+
const userName = env.GUARDRAIL_USER_NAME || env.USERNAME;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
id: userId,
|
|
26
|
+
type: "system",
|
|
27
|
+
name: userName || "MCP Client",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const REDACTION_PATTERNS = [
|
|
32
|
+
/(?:api[_-]?key|apikey|token|secret|password|pwd|auth)[=:]\s*['"]?([a-zA-Z0-9_\-]{16,})['"]?/gi,
|
|
33
|
+
/eyJ[a-zA-Z0-9_-]+\.eyJ[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/g,
|
|
34
|
+
/(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}/g,
|
|
35
|
+
/(?:sk_live_|sk_test_|pk_live_|pk_test_)[a-zA-Z0-9]+/g,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
function redactSensitive(input) {
|
|
39
|
+
if (typeof input !== "string") return input;
|
|
40
|
+
let result = input;
|
|
41
|
+
for (const pattern of REDACTION_PATTERNS) {
|
|
42
|
+
result = result.replace(pattern, "[REDACTED]");
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function redactMetadata(metadata, tier) {
|
|
48
|
+
if (!metadata) return undefined;
|
|
49
|
+
|
|
50
|
+
if (["compliance", "enterprise", "unlimited"].includes(tier)) {
|
|
51
|
+
return redactObject(metadata);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (tier === "pro") {
|
|
55
|
+
return {
|
|
56
|
+
command: metadata.command,
|
|
57
|
+
score: metadata.score,
|
|
58
|
+
durationMs: metadata.durationMs,
|
|
59
|
+
errorCode: metadata.errorCode,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { score: metadata.score };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function redactObject(obj) {
|
|
67
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
68
|
+
const result = {};
|
|
69
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
70
|
+
if (typeof value === "string") {
|
|
71
|
+
result[key] = redactSensitive(value);
|
|
72
|
+
} else if (Array.isArray(value)) {
|
|
73
|
+
result[key] = value.map((v) => (typeof v === "string" ? redactSensitive(v) : v));
|
|
74
|
+
} else if (typeof value === "object" && value !== null) {
|
|
75
|
+
result[key] = redactObject(value);
|
|
76
|
+
} else {
|
|
77
|
+
result[key] = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function computeHash(event) {
|
|
84
|
+
const payload = JSON.stringify({
|
|
85
|
+
id: event.id,
|
|
86
|
+
timestamp: event.timestamp,
|
|
87
|
+
actor: event.actor,
|
|
88
|
+
surface: event.surface,
|
|
89
|
+
action: event.action,
|
|
90
|
+
category: event.category,
|
|
91
|
+
target: event.target,
|
|
92
|
+
tier: event.tier,
|
|
93
|
+
result: event.result,
|
|
94
|
+
metadata: event.metadata,
|
|
95
|
+
prevHash: event.prevHash,
|
|
96
|
+
version: event.version,
|
|
97
|
+
});
|
|
98
|
+
return crypto.createHash("sha256").update(payload).digest("hex");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getAuditFilePath(basePath = process.cwd()) {
|
|
102
|
+
return path.join(basePath, AUDIT_DIR, AUDIT_FILE);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function ensureAuditDir(basePath = process.cwd()) {
|
|
106
|
+
const dir = path.join(basePath, AUDIT_DIR);
|
|
107
|
+
if (!fs.existsSync(dir)) {
|
|
108
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getLastHash(basePath = process.cwd()) {
|
|
113
|
+
const filePath = getAuditFilePath(basePath);
|
|
114
|
+
if (!fs.existsSync(filePath)) {
|
|
115
|
+
return GENESIS_HASH;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
119
|
+
const lines = content.split("\n").filter((line) => line.trim());
|
|
120
|
+
if (lines.length === 0) {
|
|
121
|
+
return GENESIS_HASH;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const lastEvent = JSON.parse(lines[lines.length - 1]);
|
|
126
|
+
return lastEvent.hash || GENESIS_HASH;
|
|
127
|
+
} catch {
|
|
128
|
+
return GENESIS_HASH;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function createEvent(input, prevHash) {
|
|
133
|
+
const tier = getCurrentTier();
|
|
134
|
+
const id = crypto.randomUUID();
|
|
135
|
+
const timestamp = new Date().toISOString();
|
|
136
|
+
|
|
137
|
+
const eventWithoutHash = {
|
|
138
|
+
id,
|
|
139
|
+
timestamp,
|
|
140
|
+
actor: input.actor || getCurrentActor(),
|
|
141
|
+
surface: input.surface,
|
|
142
|
+
action: input.action,
|
|
143
|
+
category: input.category,
|
|
144
|
+
target: input.target,
|
|
145
|
+
tier,
|
|
146
|
+
result: input.result,
|
|
147
|
+
metadata: redactMetadata(input.metadata, tier),
|
|
148
|
+
prevHash,
|
|
149
|
+
version: 1,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const hash = computeHash(eventWithoutHash);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...eventWithoutHash,
|
|
156
|
+
hash,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function emit(input, basePath = process.cwd()) {
|
|
161
|
+
try {
|
|
162
|
+
ensureAuditDir(basePath);
|
|
163
|
+
const prevHash = getLastHash(basePath);
|
|
164
|
+
const event = createEvent(input, prevHash);
|
|
165
|
+
|
|
166
|
+
const filePath = getAuditFilePath(basePath);
|
|
167
|
+
fs.appendFileSync(filePath, JSON.stringify(event) + "\n", "utf8");
|
|
168
|
+
|
|
169
|
+
return event;
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (process.env.GUARDRAIL_DEBUG) {
|
|
172
|
+
console.error("[audit] Failed to emit event:", err.message);
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function emitToolInvoke(toolName, args, result, metadata = {}) {
|
|
179
|
+
return emit({
|
|
180
|
+
surface: "mcp",
|
|
181
|
+
action: "tool.invoke",
|
|
182
|
+
category: "tool",
|
|
183
|
+
target: { type: "tool", name: toolName },
|
|
184
|
+
result,
|
|
185
|
+
metadata: { command: toolName, args: JSON.stringify(args), ...metadata },
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function emitToolComplete(toolName, result, metadata = {}) {
|
|
190
|
+
return emit({
|
|
191
|
+
surface: "mcp",
|
|
192
|
+
action: "tool.complete",
|
|
193
|
+
category: "tool",
|
|
194
|
+
target: { type: "tool", name: toolName },
|
|
195
|
+
result,
|
|
196
|
+
metadata: { command: toolName, ...metadata },
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const auditMcp = {
|
|
201
|
+
emit,
|
|
202
|
+
emitToolInvoke,
|
|
203
|
+
emitToolComplete,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export default auditMcp;
|