shellward 0.5.14 → 0.5.15
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/mcp-server.js +23 -40
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/mcp-server.ts +21 -42
package/dist/mcp-server.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
// }
|
|
19
19
|
import { ShellWard } from './core/engine.js';
|
|
20
20
|
import { readFileSync } from 'fs';
|
|
21
|
+
import { createInterface } from 'readline';
|
|
21
22
|
import { fileURLToPath } from 'url';
|
|
22
23
|
import { dirname, join } from 'path';
|
|
23
24
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -290,51 +291,33 @@ function handleRequest(req) {
|
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
293
|
// ===== Stdio Transport =====
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (!lengthMatch) {
|
|
307
|
-
rawBuffer = rawBuffer.slice(headerEnd + 4);
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
const contentLength = parseInt(lengthMatch[1], 10);
|
|
311
|
-
const bodyStart = headerEnd + 4;
|
|
312
|
-
if (rawBuffer.length < bodyStart + contentLength)
|
|
313
|
-
break;
|
|
314
|
-
const body = rawBuffer.slice(bodyStart, bodyStart + contentLength).toString('utf8');
|
|
315
|
-
rawBuffer = rawBuffer.slice(bodyStart + contentLength);
|
|
316
|
-
try {
|
|
317
|
-
const req = JSON.parse(body);
|
|
318
|
-
const res = handleRequest(req);
|
|
319
|
-
if (res) {
|
|
320
|
-
send(res);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
catch {
|
|
324
|
-
send({
|
|
325
|
-
jsonrpc: '2.0',
|
|
326
|
-
id: null,
|
|
327
|
-
error: { code: -32700, message: 'Parse error' },
|
|
328
|
-
});
|
|
294
|
+
// MCP stdio: newline-delimited JSON-RPC messages (no Content-Length framing).
|
|
295
|
+
// Each message is a single JSON object followed by \n.
|
|
296
|
+
// Messages MUST NOT contain embedded newlines.
|
|
297
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
298
|
+
rl.on('line', (line) => {
|
|
299
|
+
const trimmed = line.trim();
|
|
300
|
+
if (!trimmed)
|
|
301
|
+
return;
|
|
302
|
+
try {
|
|
303
|
+
const req = JSON.parse(trimmed);
|
|
304
|
+
const res = handleRequest(req);
|
|
305
|
+
if (res) {
|
|
306
|
+
send(res);
|
|
329
307
|
}
|
|
330
308
|
}
|
|
309
|
+
catch {
|
|
310
|
+
send({
|
|
311
|
+
jsonrpc: '2.0',
|
|
312
|
+
id: null,
|
|
313
|
+
error: { code: -32700, message: 'Parse error' },
|
|
314
|
+
});
|
|
315
|
+
}
|
|
331
316
|
});
|
|
332
317
|
function send(msg) {
|
|
333
|
-
|
|
334
|
-
const header = `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n`;
|
|
335
|
-
process.stdout.write(header + body);
|
|
318
|
+
process.stdout.write(JSON.stringify(msg) + '\n');
|
|
336
319
|
}
|
|
337
|
-
|
|
320
|
+
rl.on('close', () => process.exit(0));
|
|
338
321
|
process.stdin.on('error', () => process.exit(1));
|
|
339
322
|
// Log to stderr so it doesn't interfere with stdio protocol
|
|
340
323
|
process.stderr.write(`[ShellWard MCP] Server started (mode: ${guard.config.mode}, locale: ${guard.locale})\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shellward",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.15",
|
|
4
4
|
"mcpName": "io.github.jnMetaCode/shellward",
|
|
5
5
|
"description": "AI agent security & MCP security middleware — prompt injection detection, AI firewall, runtime guardrails & data-loss prevention for LLM tool calls. 8-layer defense against data exfiltration & dangerous commands. Zero dependencies. SDK + OpenClaw plugin. Supports LangChain, AutoGPT, Claude Code, Cursor, OpenAI Agents.",
|
|
6
6
|
"keywords": [
|
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/jnMetaCode/shellward",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.5.
|
|
9
|
+
"version": "0.5.15",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "shellward",
|
|
14
|
-
"version": "0.5.
|
|
14
|
+
"version": "0.5.15",
|
|
15
15
|
"runtime": "node",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
package/src/mcp-server.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import { ShellWard } from './core/engine.js'
|
|
21
21
|
import { readFileSync } from 'fs'
|
|
22
|
+
import { createInterface } from 'readline'
|
|
22
23
|
import { fileURLToPath } from 'url'
|
|
23
24
|
import { dirname, join } from 'path'
|
|
24
25
|
|
|
@@ -332,58 +333,36 @@ function handleRequest(req: JsonRpcRequest): JsonRpcResponse | null {
|
|
|
332
333
|
}
|
|
333
334
|
|
|
334
335
|
// ===== Stdio Transport =====
|
|
335
|
-
//
|
|
336
|
-
//
|
|
336
|
+
// MCP stdio: newline-delimited JSON-RPC messages (no Content-Length framing).
|
|
337
|
+
// Each message is a single JSON object followed by \n.
|
|
338
|
+
// Messages MUST NOT contain embedded newlines.
|
|
337
339
|
|
|
338
|
-
|
|
340
|
+
const rl = createInterface({ input: process.stdin, terminal: false })
|
|
339
341
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
rl.on('line', (line: string) => {
|
|
343
|
+
const trimmed = line.trim()
|
|
344
|
+
if (!trimmed) return
|
|
342
345
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (headerEnd === -1) break
|
|
349
|
-
|
|
350
|
-
const header = rawBuffer.slice(0, headerEnd).toString('ascii')
|
|
351
|
-
const lengthMatch = header.match(/Content-Length:\s*(\d+)/i)
|
|
352
|
-
if (!lengthMatch) {
|
|
353
|
-
rawBuffer = rawBuffer.slice(headerEnd + 4)
|
|
354
|
-
continue
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const contentLength = parseInt(lengthMatch[1], 10)
|
|
358
|
-
const bodyStart = headerEnd + 4
|
|
359
|
-
if (rawBuffer.length < bodyStart + contentLength) break
|
|
360
|
-
|
|
361
|
-
const body = rawBuffer.slice(bodyStart, bodyStart + contentLength).toString('utf8')
|
|
362
|
-
rawBuffer = rawBuffer.slice(bodyStart + contentLength)
|
|
363
|
-
|
|
364
|
-
try {
|
|
365
|
-
const req = JSON.parse(body) as JsonRpcRequest
|
|
366
|
-
const res = handleRequest(req)
|
|
367
|
-
if (res) {
|
|
368
|
-
send(res)
|
|
369
|
-
}
|
|
370
|
-
} catch {
|
|
371
|
-
send({
|
|
372
|
-
jsonrpc: '2.0',
|
|
373
|
-
id: null,
|
|
374
|
-
error: { code: -32700, message: 'Parse error' },
|
|
375
|
-
})
|
|
346
|
+
try {
|
|
347
|
+
const req = JSON.parse(trimmed) as JsonRpcRequest
|
|
348
|
+
const res = handleRequest(req)
|
|
349
|
+
if (res) {
|
|
350
|
+
send(res)
|
|
376
351
|
}
|
|
352
|
+
} catch {
|
|
353
|
+
send({
|
|
354
|
+
jsonrpc: '2.0',
|
|
355
|
+
id: null,
|
|
356
|
+
error: { code: -32700, message: 'Parse error' },
|
|
357
|
+
})
|
|
377
358
|
}
|
|
378
359
|
})
|
|
379
360
|
|
|
380
361
|
function send(msg: JsonRpcResponse) {
|
|
381
|
-
|
|
382
|
-
const header = `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n`
|
|
383
|
-
process.stdout.write(header + body)
|
|
362
|
+
process.stdout.write(JSON.stringify(msg) + '\n')
|
|
384
363
|
}
|
|
385
364
|
|
|
386
|
-
|
|
365
|
+
rl.on('close', () => process.exit(0))
|
|
387
366
|
process.stdin.on('error', () => process.exit(1))
|
|
388
367
|
|
|
389
368
|
// Log to stderr so it doesn't interfere with stdio protocol
|