@guava-parity/guard-scanner 8.0.0 → 9.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.
- package/package.json +1 -1
- package/src/cli.js +8 -0
- package/src/mcp-server.js +466 -0
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -43,6 +43,13 @@ if (args.includes('--version') || args.includes('-V')) {
|
|
|
43
43
|
process.exit(0);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// ── serve subcommand (MCP server) ────────────────────────────
|
|
47
|
+
if (args[0] === 'serve') {
|
|
48
|
+
const { startServer } = require('./mcp-server.js');
|
|
49
|
+
startServer();
|
|
50
|
+
// Server runs until stdin closes
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
// ── watch subcommand ──────────────────────────────────────────
|
|
47
54
|
if (args[0] === 'watch') {
|
|
48
55
|
const watchDir = args[1] || '.';
|
|
@@ -151,6 +158,7 @@ Examples:
|
|
|
151
158
|
🛡️ guard-scanner v${VERSION} — Agent Skill Security Scanner
|
|
152
159
|
|
|
153
160
|
Usage: guard-scanner [scan-dir] [options]
|
|
161
|
+
guard-scanner serve Start as MCP server (stdio)
|
|
154
162
|
guard-scanner audit <npm|github|clawhub|all> <username> [options]
|
|
155
163
|
|
|
156
164
|
Options:
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* guard-scanner MCP Server — Zero-dependency stdio JSON-RPC 2.0
|
|
4
|
+
*
|
|
5
|
+
* @security-manifest
|
|
6
|
+
* env-read: [VT_API_KEY (optional, for audit vt-scan)]
|
|
7
|
+
* env-write: []
|
|
8
|
+
* network: [npm registry, GitHub API, VirusTotal API — only for audit_assets]
|
|
9
|
+
* fs-read: [scan target directories, openclaw config]
|
|
10
|
+
* fs-write: [~/.openclaw/guard-scanner/audit.jsonl]
|
|
11
|
+
* exec: none
|
|
12
|
+
* purpose: MCP server exposing guard-scanner static/runtime analysis over stdio
|
|
13
|
+
*
|
|
14
|
+
* Protocol: MCP (Model Context Protocol) over stdio transport
|
|
15
|
+
* Implements: initialize, tools/list, tools/call, notifications
|
|
16
|
+
*
|
|
17
|
+
* Tools:
|
|
18
|
+
* scan_skill — Scan a directory for security threats (166 patterns)
|
|
19
|
+
* scan_text — Scan a code/text snippet inline
|
|
20
|
+
* check_tool_call — Runtime check before a tool call (26 checks, 5 layers)
|
|
21
|
+
* audit_assets — Audit npm/GitHub/ClawHub assets for exposure
|
|
22
|
+
* get_stats — Get scanner capabilities and statistics
|
|
23
|
+
*
|
|
24
|
+
* @author Guava 🍈 & Dee
|
|
25
|
+
* @license MIT
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const { GuardScanner, VERSION, scanToolCall, getCheckStats, LAYER_NAMES } = require('./scanner.js');
|
|
29
|
+
const { AssetAuditor, AUDIT_VERSION } = require('./asset-auditor.js');
|
|
30
|
+
|
|
31
|
+
// ── MCP Protocol Constants ──
|
|
32
|
+
|
|
33
|
+
const JSONRPC = '2.0';
|
|
34
|
+
const MCP_VERSION = '2025-11-05';
|
|
35
|
+
|
|
36
|
+
const SERVER_INFO = {
|
|
37
|
+
name: 'guard-scanner',
|
|
38
|
+
version: VERSION,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const SERVER_CAPABILITIES = {
|
|
42
|
+
tools: {},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// ── Tool Definitions ──
|
|
46
|
+
|
|
47
|
+
const TOOLS = [
|
|
48
|
+
{
|
|
49
|
+
name: 'scan_skill',
|
|
50
|
+
description: 'Scan a directory for agent security threats. Detects prompt injection, data exfiltration, credential theft, reverse shells, and 166+ threat patterns across 23 categories. Returns risk score, verdict, and detailed findings.',
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
path: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
description: 'Absolute path to the directory to scan',
|
|
57
|
+
},
|
|
58
|
+
verbose: {
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
description: 'Include detailed finding samples',
|
|
61
|
+
default: false,
|
|
62
|
+
},
|
|
63
|
+
strict: {
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
description: 'Lower detection thresholds (more sensitive)',
|
|
66
|
+
default: false,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ['path'],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'scan_text',
|
|
74
|
+
description: 'Scan a code or text snippet for security threats inline. Useful for checking generated code, tool descriptions, or agent prompts before execution. Returns matched patterns with severity levels.',
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
text: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
description: 'The code or text content to scan',
|
|
81
|
+
},
|
|
82
|
+
filename: {
|
|
83
|
+
type: 'string',
|
|
84
|
+
description: 'Optional filename hint for file-type detection (e.g. "script.js")',
|
|
85
|
+
default: 'snippet.txt',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
required: ['text'],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'check_tool_call',
|
|
93
|
+
description: 'Runtime security check for an agent tool call (before_tool_call equivalent). Checks 26 threat patterns across 5 layers: Threat Detection, Trust Defense, Safety Judge, Brain/Behavioral, Trust Exploitation. Returns whether the call should be blocked.',
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
tool: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'Name of the tool being called (e.g. "exec", "write", "shell")',
|
|
100
|
+
},
|
|
101
|
+
args: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
description: 'Arguments/parameters of the tool call',
|
|
104
|
+
additionalProperties: true,
|
|
105
|
+
},
|
|
106
|
+
mode: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
enum: ['monitor', 'enforce', 'strict'],
|
|
109
|
+
description: 'Guard mode — monitor: log only, enforce: block CRITICAL (default), strict: block HIGH+CRITICAL',
|
|
110
|
+
default: 'enforce',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
required: ['tool', 'args'],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'audit_assets',
|
|
118
|
+
description: 'Audit npm packages or GitHub repositories for security exposure. Checks for accidental source leaks, overly permissive access, and supply chain risks.',
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
username: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'npm or GitHub username to audit',
|
|
125
|
+
},
|
|
126
|
+
scope: {
|
|
127
|
+
type: 'string',
|
|
128
|
+
enum: ['npm', 'github', 'all'],
|
|
129
|
+
description: 'What to audit — npm packages, GitHub repos, or all',
|
|
130
|
+
default: 'all',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
required: ['username'],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'get_stats',
|
|
138
|
+
description: 'Get guard-scanner capabilities, version, and detection statistics. Returns pattern counts, runtime check counts by layer and severity, supported categories, and configuration.',
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
// ── Tool Handlers ──
|
|
147
|
+
|
|
148
|
+
function handleScanSkill({ path: scanPath, verbose = false, strict = false }) {
|
|
149
|
+
if (!scanPath) return errorResult('path is required');
|
|
150
|
+
|
|
151
|
+
const fs = require('fs');
|
|
152
|
+
if (!fs.existsSync(scanPath)) {
|
|
153
|
+
return errorResult(`Directory not found: ${scanPath}`);
|
|
154
|
+
}
|
|
155
|
+
if (!fs.statSync(scanPath).isDirectory()) {
|
|
156
|
+
return errorResult(`Not a directory: ${scanPath}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const scanner = new GuardScanner({ verbose, strict, quiet: true });
|
|
160
|
+
scanner.scanDirectory(scanPath);
|
|
161
|
+
const report = scanner.toJSON();
|
|
162
|
+
|
|
163
|
+
// Count findings by severity
|
|
164
|
+
let critical = 0, high = 0, medium = 0, low = 0, total = 0;
|
|
165
|
+
for (const skill of report.findings) {
|
|
166
|
+
for (const f of skill.findings) {
|
|
167
|
+
total++;
|
|
168
|
+
if (f.severity === 'CRITICAL') critical++;
|
|
169
|
+
else if (f.severity === 'HIGH') high++;
|
|
170
|
+
else if (f.severity === 'MEDIUM') medium++;
|
|
171
|
+
else low++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const verdict = report.stats.malicious > 0 ? '🔴 MALICIOUS'
|
|
176
|
+
: report.stats.suspicious > 0 ? '🟡 SUSPICIOUS'
|
|
177
|
+
: '🟢 SAFE';
|
|
178
|
+
|
|
179
|
+
return successResult(
|
|
180
|
+
`🛡️ Scan: ${verdict}\n` +
|
|
181
|
+
`Files: ${report.stats.scanned}, Skills: ${report.findings.length}\n` +
|
|
182
|
+
`Clean: ${report.stats.clean}, Suspicious: ${report.stats.suspicious}, Malicious: ${report.stats.malicious}\n` +
|
|
183
|
+
`Findings: ${total} (Critical: ${critical}, High: ${high}, Medium: ${medium}, Low: ${low})\n` +
|
|
184
|
+
(total > 0
|
|
185
|
+
? '\nTop findings:\n' + report.findings.flatMap(s =>
|
|
186
|
+
s.findings.slice(0, 5).map(f =>
|
|
187
|
+
` [${f.severity}] ${f.id}: ${f.desc} — ${s.skill}/${f.file}`
|
|
188
|
+
)
|
|
189
|
+
).slice(0, 10).join('\n')
|
|
190
|
+
: '\n✅ No threats detected.')
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function handleScanText({ text, filename = 'snippet.txt' }) {
|
|
195
|
+
if (!text) return errorResult('text is required');
|
|
196
|
+
|
|
197
|
+
const os = require('os');
|
|
198
|
+
const fs = require('fs');
|
|
199
|
+
const path = require('path');
|
|
200
|
+
|
|
201
|
+
// Write text to temp file, scan, cleanup
|
|
202
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gs-'));
|
|
203
|
+
const tmpFile = path.join(tmpDir, filename);
|
|
204
|
+
fs.writeFileSync(tmpFile, text);
|
|
205
|
+
|
|
206
|
+
const scanner = new GuardScanner({ quiet: true });
|
|
207
|
+
scanner.scanDirectory(tmpDir);
|
|
208
|
+
const report = scanner.toJSON();
|
|
209
|
+
|
|
210
|
+
// Cleanup
|
|
211
|
+
try { fs.unlinkSync(tmpFile); fs.rmdirSync(tmpDir); } catch { /* ok */ }
|
|
212
|
+
|
|
213
|
+
return successResult(
|
|
214
|
+
`🛡️ Text Scan: ${report.verdict}\n` +
|
|
215
|
+
`Score: ${report.risk.score} (${report.risk.level})\n` +
|
|
216
|
+
`Findings: ${report.summary.totalFindings}\n` +
|
|
217
|
+
(report.findings.length > 0
|
|
218
|
+
? '\nDetected:\n' + report.findings.map(f =>
|
|
219
|
+
` [${f.severity}] ${f.id}: ${f.desc}`
|
|
220
|
+
).join('\n')
|
|
221
|
+
: '\n✅ No threats detected.')
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function handleCheckToolCall({ tool, args, mode = 'enforce' }) {
|
|
226
|
+
if (!tool) return errorResult('tool is required');
|
|
227
|
+
if (args === undefined) return errorResult('args is required');
|
|
228
|
+
|
|
229
|
+
const result = scanToolCall(tool, args, { mode, auditLog: true });
|
|
230
|
+
|
|
231
|
+
if (result.detections.length === 0) {
|
|
232
|
+
return successResult(
|
|
233
|
+
`✅ Tool call "${tool}" passed all 26 runtime checks.\nMode: ${mode}`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const lines = result.detections.map(d =>
|
|
238
|
+
` [${d.action.toUpperCase()}] ${d.id} (${d.severity}, L${d.layer}): ${d.desc}`
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return successResult(
|
|
242
|
+
`🛡️ Runtime Check: ${result.blocked ? '🚫 BLOCKED' : '⚠️ WARNINGS'}\n` +
|
|
243
|
+
`Tool: ${tool} | Mode: ${mode}\n` +
|
|
244
|
+
`Detections: ${result.detections.length}\n\n` +
|
|
245
|
+
lines.join('\n') +
|
|
246
|
+
(result.blocked ? `\n\n❌ Blocked: ${result.blockReason}` : '')
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function handleAuditAssets({ username, scope = 'all' }) {
|
|
251
|
+
if (!username) return errorResult('username is required');
|
|
252
|
+
|
|
253
|
+
const auditor = new AssetAuditor({ quiet: true });
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
if (scope === 'npm' || scope === 'all') {
|
|
257
|
+
await auditor.auditNpm(username);
|
|
258
|
+
}
|
|
259
|
+
if (scope === 'github' || scope === 'all') {
|
|
260
|
+
await auditor.auditGithub(username);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const report = auditor.toJSON();
|
|
264
|
+
const verdict = auditor.getVerdict();
|
|
265
|
+
|
|
266
|
+
return successResult(
|
|
267
|
+
`🛡️ Asset Audit: ${verdict.label}\n` +
|
|
268
|
+
`User: ${username} | Scope: ${scope}\n` +
|
|
269
|
+
`Alerts: ${report.summary.totalAlerts} ` +
|
|
270
|
+
`(Critical: ${report.summary.critical}, High: ${report.summary.high}, ` +
|
|
271
|
+
`Medium: ${report.summary.medium}, Low: ${report.summary.low})\n` +
|
|
272
|
+
(report.alerts.length > 0
|
|
273
|
+
? '\nAlerts:\n' + report.alerts.slice(0, 10).map(a =>
|
|
274
|
+
` [${a.severity}] ${a.source}: ${a.message}`
|
|
275
|
+
).join('\n')
|
|
276
|
+
: '\n✅ No exposure detected.')
|
|
277
|
+
);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
return errorResult(`Audit failed: ${e.message}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function handleGetStats() {
|
|
284
|
+
const runtimeStats = getCheckStats();
|
|
285
|
+
|
|
286
|
+
return successResult(
|
|
287
|
+
`🛡️ guard-scanner v${VERSION}\n\n` +
|
|
288
|
+
`Static Analysis:\n` +
|
|
289
|
+
` • 166 threat patterns across 23 categories\n` +
|
|
290
|
+
` • Entropy-based secret detection\n` +
|
|
291
|
+
` • Data flow analysis (JS)\n` +
|
|
292
|
+
` • Cross-file reference checking\n` +
|
|
293
|
+
` • SKILL.md manifest validation\n` +
|
|
294
|
+
` • Dependency chain scanning\n` +
|
|
295
|
+
` • SARIF, JSON, HTML reporting\n\n` +
|
|
296
|
+
`Runtime Guard:\n` +
|
|
297
|
+
` • ${runtimeStats.total} checks across ${Object.keys(runtimeStats.byLayer).length} layers\n` +
|
|
298
|
+
Object.entries(runtimeStats.byLayer).map(([l, c]) =>
|
|
299
|
+
` • Layer ${l} (${LAYER_NAMES[l] || 'Unknown'}): ${c} checks`
|
|
300
|
+
).join('\n') + '\n\n' +
|
|
301
|
+
`Asset Audit: v${AUDIT_VERSION}\n` +
|
|
302
|
+
` • npm package exposure detection\n` +
|
|
303
|
+
` • GitHub repository scanning\n` +
|
|
304
|
+
` • ClawHub skill auditing\n\n` +
|
|
305
|
+
`Performance: 0.016ms/scan average\n` +
|
|
306
|
+
`Dependencies: 0 external (node:fs, node:path, node:https only)`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ── Result helpers ──
|
|
311
|
+
|
|
312
|
+
function successResult(text) {
|
|
313
|
+
return { content: [{ type: 'text', text }], isError: false };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function errorResult(text) {
|
|
317
|
+
return { content: [{ type: 'text', text: `❌ ${text}` }], isError: true };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ── MCP JSON-RPC over stdio ──
|
|
321
|
+
|
|
322
|
+
class MCPServer {
|
|
323
|
+
constructor() {
|
|
324
|
+
this._initialized = false;
|
|
325
|
+
this._buffer = '';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
start() {
|
|
329
|
+
process.stdin.setEncoding('utf8');
|
|
330
|
+
process.stdin.on('data', (chunk) => this._onData(chunk));
|
|
331
|
+
process.stdin.on('end', () => process.exit(0));
|
|
332
|
+
process.stderr.write(`🛡️ guard-scanner MCP server v${VERSION} started\n`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
_onData(chunk) {
|
|
336
|
+
this._buffer += chunk;
|
|
337
|
+
|
|
338
|
+
// Parse newline-delimited JSON-RPC messages
|
|
339
|
+
let newlineIdx;
|
|
340
|
+
while ((newlineIdx = this._buffer.indexOf('\n')) !== -1) {
|
|
341
|
+
const line = this._buffer.slice(0, newlineIdx).trim();
|
|
342
|
+
this._buffer = this._buffer.slice(newlineIdx + 1);
|
|
343
|
+
|
|
344
|
+
if (line.length === 0) continue;
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
const msg = JSON.parse(line);
|
|
348
|
+
this._handleMessage(msg);
|
|
349
|
+
} catch (e) {
|
|
350
|
+
// If parse fails, try Content-Length header protocol
|
|
351
|
+
if (line.startsWith('Content-Length:')) {
|
|
352
|
+
this._handleContentLength(line);
|
|
353
|
+
}
|
|
354
|
+
// else ignore malformed input
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Handle Content-Length based protocol (MCP stdio standard)
|
|
359
|
+
this._tryParseContentLength();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
_handleContentLength(headerLine) {
|
|
363
|
+
// Already handled in _tryParseContentLength
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
_tryParseContentLength() {
|
|
367
|
+
// MCP stdio: "Content-Length: N\r\n\r\n{json}"
|
|
368
|
+
const clMatch = this._buffer.match(/Content-Length:\s*(\d+)\r?\n\r?\n/);
|
|
369
|
+
if (!clMatch) return;
|
|
370
|
+
|
|
371
|
+
const contentLength = parseInt(clMatch[1], 10);
|
|
372
|
+
const headerEnd = clMatch.index + clMatch[0].length;
|
|
373
|
+
const available = this._buffer.length - headerEnd;
|
|
374
|
+
|
|
375
|
+
if (available < contentLength) return; // wait for more data
|
|
376
|
+
|
|
377
|
+
const body = this._buffer.slice(headerEnd, headerEnd + contentLength);
|
|
378
|
+
this._buffer = this._buffer.slice(headerEnd + contentLength);
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
const msg = JSON.parse(body);
|
|
382
|
+
this._handleMessage(msg);
|
|
383
|
+
} catch { /* ignore */ }
|
|
384
|
+
|
|
385
|
+
// Recurse for more messages
|
|
386
|
+
this._tryParseContentLength();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async _handleMessage(msg) {
|
|
390
|
+
if (!msg.method) return; // Not a request or notification
|
|
391
|
+
|
|
392
|
+
// Notifications (no id) — acknowledge silently
|
|
393
|
+
if (msg.id === undefined || msg.id === null) {
|
|
394
|
+
// notifications/initialized, notifications/cancelled, etc.
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
let result;
|
|
399
|
+
try {
|
|
400
|
+
result = await this._dispatch(msg.method, msg.params || {});
|
|
401
|
+
this._send({ jsonrpc: JSONRPC, id: msg.id, result });
|
|
402
|
+
} catch (e) {
|
|
403
|
+
this._send({
|
|
404
|
+
jsonrpc: JSONRPC,
|
|
405
|
+
id: msg.id,
|
|
406
|
+
error: { code: e.code || -32603, message: e.message },
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async _dispatch(method, params) {
|
|
412
|
+
switch (method) {
|
|
413
|
+
case 'initialize':
|
|
414
|
+
this._initialized = true;
|
|
415
|
+
return {
|
|
416
|
+
protocolVersion: MCP_VERSION,
|
|
417
|
+
capabilities: SERVER_CAPABILITIES,
|
|
418
|
+
serverInfo: SERVER_INFO,
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
case 'tools/list':
|
|
422
|
+
return { tools: TOOLS };
|
|
423
|
+
|
|
424
|
+
case 'tools/call':
|
|
425
|
+
return this._callTool(params.name, params.arguments || {});
|
|
426
|
+
|
|
427
|
+
case 'ping':
|
|
428
|
+
return {};
|
|
429
|
+
|
|
430
|
+
default:
|
|
431
|
+
throw Object.assign(new Error(`Method not found: ${method}`), { code: -32601 });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async _callTool(name, args) {
|
|
436
|
+
switch (name) {
|
|
437
|
+
case 'scan_skill':
|
|
438
|
+
return handleScanSkill(args);
|
|
439
|
+
case 'scan_text':
|
|
440
|
+
return handleScanText(args);
|
|
441
|
+
case 'check_tool_call':
|
|
442
|
+
return handleCheckToolCall(args);
|
|
443
|
+
case 'audit_assets':
|
|
444
|
+
return await handleAuditAssets(args);
|
|
445
|
+
case 'get_stats':
|
|
446
|
+
return handleGetStats();
|
|
447
|
+
default:
|
|
448
|
+
return errorResult(`Unknown tool: ${name}`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
_send(msg) {
|
|
453
|
+
const body = JSON.stringify(msg);
|
|
454
|
+
const header = `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n`;
|
|
455
|
+
process.stdout.write(header + body);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ── Export for CLI integration ──
|
|
460
|
+
|
|
461
|
+
function startServer() {
|
|
462
|
+
const server = new MCPServer();
|
|
463
|
+
server.start();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
module.exports = { MCPServer, startServer, TOOLS };
|