@eyeoverthink/sva-gate 0.0.0-stage → 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.
- package/LICENSE +201 -0
- package/README.md +131 -2
- package/bin/sva-gate.js +153 -0
- package/package.json +61 -4
- package/src/index.d.ts +96 -0
- package/src/index.js +46 -0
- package/src/lib/binder-induction.js +204 -0
- package/src/lib/judge-verify.js +190 -0
- package/src/lib/membrane-core.js +130 -0
- package/src/lib/sentinel.js +88 -0
- package/src/lib/stream-guard.js +166 -0
- package/src/mcp-server.js +264 -0
- package/src/membrane.js +3 -0
- package/src/receipt.js +341 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Zero-dependency Streaming Token Guard for LLM NDJSON / text streams.
|
|
2
|
+
// Prevents credentials and PII split across arbitrary token boundaries (e.g. "sk-" + "ant-..." or "123-" + "45-6789")
|
|
3
|
+
// from leaking mid-stream before sealing/redaction triggers.
|
|
4
|
+
// Ported from StreamCanaryInterceptor's cross-token tail-prefix buffering design.
|
|
5
|
+
import { detect, SealSession } from './membrane-core.js';
|
|
6
|
+
|
|
7
|
+
export const SECRET_PREFIXES = [
|
|
8
|
+
'sk-ant-',
|
|
9
|
+
'sk-proj-',
|
|
10
|
+
'sk-',
|
|
11
|
+
'AIza',
|
|
12
|
+
'ghp_',
|
|
13
|
+
'gho_',
|
|
14
|
+
'github_pat_',
|
|
15
|
+
'AKIA',
|
|
16
|
+
'xoxb-',
|
|
17
|
+
'xoxp-',
|
|
18
|
+
'Bearer ',
|
|
19
|
+
'-----BEGIN ',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const MAX_PREFIX_LEN = Math.max(...SECRET_PREFIXES.map((p) => p.length));
|
|
23
|
+
const CRED_CHAR = /[A-Za-z0-9_\-./+=:]/;
|
|
24
|
+
|
|
25
|
+
// Returns how many trailing characters of `text` could be the start of a split secret prefix,
|
|
26
|
+
// an in-progress token/key, an email local-part, or a partial SSN/phone/card digit run.
|
|
27
|
+
export function tailHoldLength(text) {
|
|
28
|
+
if (!text) return 0;
|
|
29
|
+
let hold = 0;
|
|
30
|
+
|
|
31
|
+
// 1. Partial match against any known secret prefix (e.g. trailing "sk-" or "ghp")
|
|
32
|
+
const maxCheck = Math.min(text.length, MAX_PREFIX_LEN);
|
|
33
|
+
for (const pfx of SECRET_PREFIXES) {
|
|
34
|
+
for (let len = 1; len <= Math.min(pfx.length, maxCheck); len++) {
|
|
35
|
+
if (text.endsWith(pfx.slice(0, len))) hold = Math.max(hold, len);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2. Active secret prefix still accumulating token chars right up to the end of the chunk
|
|
40
|
+
for (const pfx of SECRET_PREFIXES) {
|
|
41
|
+
const idx = text.lastIndexOf(pfx);
|
|
42
|
+
if (idx !== -1) {
|
|
43
|
+
const tail = text.slice(idx);
|
|
44
|
+
if (/^[A-Za-z0-9_\-./+=: ]+$/.test(tail) && tail.length < 256) {
|
|
45
|
+
hold = Math.max(hold, tail.length);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 3. Partial trailing digit/separator run (could become SSN 123-45-6789, phone, or card number)
|
|
51
|
+
const digitTail = text.match(/[+\d][\d\s.\-()]{0,22}$/);
|
|
52
|
+
if (digitTail) hold = Math.max(hold, digitTail[0].length);
|
|
53
|
+
|
|
54
|
+
// 4. Partial trailing email-like token containing '@' or identifier before '@'
|
|
55
|
+
const emailTail = text.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]*$/);
|
|
56
|
+
if (emailTail) hold = Math.max(hold, emailTail[0].length);
|
|
57
|
+
|
|
58
|
+
return Math.min(hold, text.length);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class StreamSealGuard {
|
|
62
|
+
constructor({ session = null, mode = 'seal', maxBuffer = 4096 } = {}) {
|
|
63
|
+
this.session = session || new SealSession();
|
|
64
|
+
this.mode = mode; // 'seal' (typed placeholders) | 'redact' ([REDACTED:<TYPE>])
|
|
65
|
+
this.maxBuffer = maxBuffer;
|
|
66
|
+
this.buffer = '';
|
|
67
|
+
this.chunksProcessed = 0;
|
|
68
|
+
this.sealsApplied = 0;
|
|
69
|
+
this.alerts = [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_sealWindow(text) {
|
|
73
|
+
if (!text) return '';
|
|
74
|
+
const spans = detect(text);
|
|
75
|
+
if (spans.length === 0) return text;
|
|
76
|
+
this.sealsApplied += spans.length;
|
|
77
|
+
this.alerts.push({
|
|
78
|
+
chunkIndex: this.chunksProcessed,
|
|
79
|
+
types: [...new Set(spans.map((s) => s.type))],
|
|
80
|
+
count: spans.length,
|
|
81
|
+
});
|
|
82
|
+
if (this.mode === 'redact') {
|
|
83
|
+
let out = '';
|
|
84
|
+
let pos = 0;
|
|
85
|
+
for (const sp of spans) {
|
|
86
|
+
out += text.slice(pos, sp.start) + `[REDACTED:${sp.type}]`;
|
|
87
|
+
pos = sp.end;
|
|
88
|
+
}
|
|
89
|
+
return out + text.slice(pos);
|
|
90
|
+
}
|
|
91
|
+
return this.session.apply(text, spans);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Feed one streaming token/chunk; returns the safe-to-emit prefix while holding any boundary-split candidate.
|
|
95
|
+
push(chunk) {
|
|
96
|
+
this.chunksProcessed++;
|
|
97
|
+
const combined = this.buffer + String(chunk ?? '');
|
|
98
|
+
if (!combined) return '';
|
|
99
|
+
|
|
100
|
+
// Never hold unbounded memory on adversarial non-whitespace streams
|
|
101
|
+
let hold = tailHoldLength(combined);
|
|
102
|
+
if (hold > this.maxBuffer) hold = 0;
|
|
103
|
+
|
|
104
|
+
// Also hold the trailing identifier if we are mid-word next to a potential '@' or secret
|
|
105
|
+
if (hold === 0 && CRED_CHAR.test(combined[combined.length - 1])) {
|
|
106
|
+
const wordTail = combined.match(/[A-Za-z0-9._%+-]{1,32}$/);
|
|
107
|
+
if (wordTail && wordTail[0].length < combined.length) hold = wordTail[0].length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const emitRaw = hold > 0 ? combined.slice(0, combined.length - hold) : combined;
|
|
111
|
+
this.buffer = hold > 0 ? combined.slice(combined.length - hold) : '';
|
|
112
|
+
return this._sealWindow(emitRaw);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Flush remaining buffered tail at end-of-stream.
|
|
116
|
+
flush() {
|
|
117
|
+
const rest = this.buffer;
|
|
118
|
+
this.buffer = '';
|
|
119
|
+
return this._sealWindow(rest);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Process one Ollama-style NDJSON line (supports both /api/generate `.response` and /api/chat `.message.content`).
|
|
123
|
+
processNdjsonLine(line) {
|
|
124
|
+
const parsed = JSON.parse(line);
|
|
125
|
+
if (parsed.response !== undefined) {
|
|
126
|
+
parsed.response = this.push(parsed.response);
|
|
127
|
+
if (parsed.done === true) parsed.response += this.flush();
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
if (parsed.message?.content !== undefined) {
|
|
131
|
+
parsed.message.content = this.push(parsed.message.content);
|
|
132
|
+
if (parsed.done === true) parsed.message.content += this.flush();
|
|
133
|
+
return parsed;
|
|
134
|
+
}
|
|
135
|
+
if (parsed.done === true && this.buffer) {
|
|
136
|
+
parsed.flushedTail = this.flush();
|
|
137
|
+
}
|
|
138
|
+
return parsed;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Async generator wrapper for any chunked UTF-8 / string NDJSON stream.
|
|
142
|
+
async *interceptNdjson(readableStream) {
|
|
143
|
+
let lineBuf = '';
|
|
144
|
+
const dec = new TextDecoder();
|
|
145
|
+
for await (const chunk of readableStream) {
|
|
146
|
+
lineBuf += typeof chunk === 'string' ? chunk : dec.decode(chunk, { stream: true });
|
|
147
|
+
const lines = lineBuf.split('\n');
|
|
148
|
+
lineBuf = lines.pop() || '';
|
|
149
|
+
for (const line of lines) {
|
|
150
|
+
if (line.trim()) yield this.processNdjsonLine(line);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (lineBuf.trim()) yield this.processNdjsonLine(lineBuf);
|
|
154
|
+
const tail = this.flush();
|
|
155
|
+
if (tail) yield { response: tail, done: true };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getStats() {
|
|
159
|
+
return {
|
|
160
|
+
chunksProcessed: this.chunksProcessed,
|
|
161
|
+
sealsApplied: this.sealsApplied,
|
|
162
|
+
withheld: { ...this.session.counts },
|
|
163
|
+
alerts: this.alerts.slice(),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// Zero-dependency stdio JSON-RPC 2.0 MCP Server for @eyeoverthink/sva-gate.
|
|
2
|
+
// Exposes 6 deterministic verification tools spanning all 3 SVA layers:
|
|
3
|
+
// 1. sva_seal_text (EMA/1 privacy membrane + StreamSealGuard + injection scan)
|
|
4
|
+
// 2. sva_mint_receipt (SVA-ER/1 Ed25519 + RFC 6962 Merkle receipt & OPEG/1 envelope)
|
|
5
|
+
// 3. sva_verify_receipt (SVA-ER/1 & IETF draft-zambo-aer1-26 AER-1 v0.4 verifier)
|
|
6
|
+
// 4. sva_opeg_check (OPEG/1 S4_COMMIT fail-closed execution gate)
|
|
7
|
+
// 5. sva_judge_audit (SVA-JEV/1 calibrated epistemic judge & planted-fake gate)
|
|
8
|
+
// 6. sva_crystallize_skill (VSC/1 zero-LLM binder induction + leave-one-out check)
|
|
9
|
+
|
|
10
|
+
import readline from 'node:readline';
|
|
11
|
+
import { mintSvaEr1, verifyAnyReceipt, evaluateOpeg1 } from './receipt.js';
|
|
12
|
+
import { detect, SealSession, StreamSealGuard, scanInjection } from './membrane.js';
|
|
13
|
+
import { evaluateSvaJev1 } from './lib/judge-verify.js';
|
|
14
|
+
import { induce, leaveOneOut, applySpec, novelWording } from './lib/binder-induction.js';
|
|
15
|
+
|
|
16
|
+
export const SERVER_INFO = {
|
|
17
|
+
name: '@eyeoverthink/sva-gate',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const MCP_TOOLS = [
|
|
22
|
+
{
|
|
23
|
+
name: 'sva_seal_text',
|
|
24
|
+
description: 'Seal PII and secrets (emails, SSNs, API keys, phones) into typed placeholders with zero-leak audit and prompt-injection scan. Optionally pass chunks[] to run StreamSealGuard across token boundaries.',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
text: { type: 'string', description: 'Plain text to seal before cloud egress.' },
|
|
29
|
+
chunks: { type: 'array', items: { type: 'string' }, description: 'Optional streaming token chunks to seal via StreamSealGuard.' },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'sva_mint_receipt',
|
|
35
|
+
description: 'Mint an Ed25519-signed, RFC 6962 Merkle-proven SVA-ER/1 execution receipt and matching OPEG/1 S4_COMMIT envelope for a sanitized JSON result object (rSan).',
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
required: ['rSan'],
|
|
39
|
+
properties: {
|
|
40
|
+
rSan: { type: 'object', description: 'Sanitized result object to bind cryptographically.' },
|
|
41
|
+
missionId: { type: 'string', description: 'Optional mission identifier.' },
|
|
42
|
+
agencyName: { type: 'string', description: 'Optional agency/issuer display name.' },
|
|
43
|
+
clockStatus: { type: 'string', enum: ['attested', 'drift', 'unattested'], description: 'Explicit clock honesty state (default: unattested).' },
|
|
44
|
+
seedHex: { type: 'string', description: 'Optional 64-hex-char Ed25519 signing seed (ephemeral key generated if omitted).' },
|
|
45
|
+
events: { type: 'array', items: { type: 'object' }, description: 'Optional execution log events to include in the Merkle tree.' },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'sva_verify_receipt',
|
|
51
|
+
description: 'Verify an SVA-ER/1 receipt (Ed25519 + RFC 6962 Merkle + deliverable digest + RFC 3339 clock) OR an IETF draft-zambo-aer1-26 AER-1 v0.4 receipt offline.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
required: ['receipt'],
|
|
55
|
+
properties: {
|
|
56
|
+
receipt: { type: 'object', description: 'SVA-ER/1 or AER-1 v0.4 receipt JSON object.' },
|
|
57
|
+
deliverable: { description: 'Optional deliverable string or JSON object to verify against deliverableSha256.' },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'sva_opeg_check',
|
|
63
|
+
description: 'Evaluate an OPEG/1 S4_COMMIT gate envelope fail-closed. Blocks DIRECT_INFERENCE, tampered rSan payloads, and invalid SVA-ER/1 or AER-1 v0.4 receipts.',
|
|
64
|
+
inputSchema: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
required: ['envelope'],
|
|
67
|
+
properties: {
|
|
68
|
+
envelope: { type: 'object', description: 'OPEG/1 S4_COMMIT envelope JSON object.' },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'sva_judge_audit',
|
|
74
|
+
description: 'Evaluate an SVA-JEV/1 epistemic judge envelope (calibration Wilson 95% CI, independent JEV vote with author self-vote exclusion, verbatim >=12-char quote check, or planted-fake + zero-LLM new_terms claim trace).',
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
required: ['envelope'],
|
|
78
|
+
properties: {
|
|
79
|
+
envelope: { type: 'object', description: 'SVA-JEV/1 envelope with spec="sva-jev/1", semantics="stability-signal-not-correctness", and mode.' },
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'sva_crystallize_skill',
|
|
85
|
+
description: 'Induce a zero-LLM deterministic parameter binder from positive/negative examples, check leave-one-out accuracy, and optionally test binding against a new task string.',
|
|
86
|
+
inputSchema: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
required: ['examples'],
|
|
89
|
+
properties: {
|
|
90
|
+
examples: {
|
|
91
|
+
type: 'array',
|
|
92
|
+
items: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
required: ['task', 'input'],
|
|
95
|
+
properties: {
|
|
96
|
+
task: { type: 'string' },
|
|
97
|
+
input: { type: 'object' },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
description: 'Array of solved positive { task, input } examples.',
|
|
101
|
+
},
|
|
102
|
+
negatives: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
items: { type: 'object', properties: { task: { type: 'string' } } },
|
|
105
|
+
description: 'Optional refused near-miss { task } counter-examples.',
|
|
106
|
+
},
|
|
107
|
+
skill: { type: 'object', description: 'Optional skill schema with params.properties metadata.' },
|
|
108
|
+
testTask: { type: 'string', description: 'Optional novel task string to test binder extraction and near-miss rejection.' },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
function runTool(name, args = {}) {
|
|
115
|
+
switch (name) {
|
|
116
|
+
case 'sva_seal_text': {
|
|
117
|
+
if (Array.isArray(args.chunks) && args.chunks.length > 0) {
|
|
118
|
+
const sg = new StreamSealGuard();
|
|
119
|
+
const sealed = args.chunks.map((c) => sg.push(String(c))).join('') + sg.flush();
|
|
120
|
+
const fullRaw = args.chunks.map(String).join('');
|
|
121
|
+
return {
|
|
122
|
+
mode: 'stream',
|
|
123
|
+
sealed,
|
|
124
|
+
audit: sg.session.audit(sealed),
|
|
125
|
+
injection: scanInjection(fullRaw),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const text = String(args.text ?? '');
|
|
129
|
+
const findings = detect(text);
|
|
130
|
+
const session = new SealSession();
|
|
131
|
+
const sealed = session.apply(text, findings);
|
|
132
|
+
return {
|
|
133
|
+
mode: 'single',
|
|
134
|
+
sealed,
|
|
135
|
+
findingsCount: findings.length,
|
|
136
|
+
audit: session.audit(sealed),
|
|
137
|
+
injection: scanInjection(text),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
case 'sva_mint_receipt': {
|
|
141
|
+
return mintSvaEr1({
|
|
142
|
+
rSan: args.rSan,
|
|
143
|
+
missionId: args.missionId,
|
|
144
|
+
agencyName: args.agencyName,
|
|
145
|
+
clockStatus: args.clockStatus || 'unattested',
|
|
146
|
+
seedHex: args.seedHex || null,
|
|
147
|
+
events: Array.isArray(args.events) ? args.events : [],
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
case 'sva_verify_receipt': {
|
|
151
|
+
return verifyAnyReceipt(args.receipt, { deliverable: args.deliverable ?? null });
|
|
152
|
+
}
|
|
153
|
+
case 'sva_opeg_check': {
|
|
154
|
+
return evaluateOpeg1(args.envelope);
|
|
155
|
+
}
|
|
156
|
+
case 'sva_judge_audit': {
|
|
157
|
+
return evaluateSvaJev1(args.envelope);
|
|
158
|
+
}
|
|
159
|
+
case 'sva_crystallize_skill': {
|
|
160
|
+
const pos = (Array.isArray(args.examples) ? args.examples : []).map((e) => ({
|
|
161
|
+
task: e.task,
|
|
162
|
+
input: e.input ?? e.params,
|
|
163
|
+
}));
|
|
164
|
+
const neg = Array.isArray(args.negatives) ? args.negatives : [];
|
|
165
|
+
const skill = args.skill && typeof args.skill === 'object' ? args.skill : { params: { properties: {} } };
|
|
166
|
+
const induced = induce(pos, neg, skill);
|
|
167
|
+
const spec = induced?.spec || null;
|
|
168
|
+
const looRows = spec ? leaveOneOut(pos, neg, skill) : [];
|
|
169
|
+
const looPassed = looRows.filter((r) => r.ok).length;
|
|
170
|
+
const loo = { passed: looPassed, total: looRows.length, ok: looRows.length > 0 && looPassed === looRows.length };
|
|
171
|
+
const out = { induced: Boolean(spec), error: induced?.error ?? null, leaveOneOut: loo, spec };
|
|
172
|
+
if (spec && typeof args.testTask === 'string') {
|
|
173
|
+
const bound = applySpec(spec, args.testTask);
|
|
174
|
+
const novel = novelWording(pos, args.testTask);
|
|
175
|
+
out.testResult = {
|
|
176
|
+
routed: Boolean(bound && novel.length === 0),
|
|
177
|
+
novelWordingRejected: novel.length > 0 || !bound,
|
|
178
|
+
novelWords: novel,
|
|
179
|
+
bound,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
default:
|
|
185
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function createMcpHandler() {
|
|
190
|
+
return function handleRequest(msg) {
|
|
191
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') {
|
|
192
|
+
return { jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid JSON-RPC 2.0 request' } };
|
|
193
|
+
}
|
|
194
|
+
const { id, method, params } = msg;
|
|
195
|
+
// Notifications have no id and expect no response
|
|
196
|
+
if (id === undefined) return null;
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
if (method === 'initialize') {
|
|
200
|
+
const protocolVersion = typeof params?.protocolVersion === 'string' ? params.protocolVersion : '2025-03-26';
|
|
201
|
+
return {
|
|
202
|
+
jsonrpc: '2.0',
|
|
203
|
+
id,
|
|
204
|
+
result: {
|
|
205
|
+
protocolVersion,
|
|
206
|
+
capabilities: { tools: {} },
|
|
207
|
+
serverInfo: SERVER_INFO,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (method === 'ping') {
|
|
212
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
213
|
+
}
|
|
214
|
+
if (method === 'tools/list') {
|
|
215
|
+
return { jsonrpc: '2.0', id, result: { tools: MCP_TOOLS } };
|
|
216
|
+
}
|
|
217
|
+
if (method === 'tools/call') {
|
|
218
|
+
const toolName = params?.name;
|
|
219
|
+
const toolArgs = params?.arguments || {};
|
|
220
|
+
const data = runTool(toolName, toolArgs);
|
|
221
|
+
return {
|
|
222
|
+
jsonrpc: '2.0',
|
|
223
|
+
id,
|
|
224
|
+
result: {
|
|
225
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
226
|
+
structuredContent: data,
|
|
227
|
+
isError: false,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return { jsonrpc: '2.0', id, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
232
|
+
} catch (err) {
|
|
233
|
+
return {
|
|
234
|
+
jsonrpc: '2.0',
|
|
235
|
+
id,
|
|
236
|
+
result: {
|
|
237
|
+
content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }],
|
|
238
|
+
isError: true,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function startStdioMcpServer(input = process.stdin, output = process.stdout) {
|
|
246
|
+
const handle = createMcpHandler();
|
|
247
|
+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
|
248
|
+
rl.on('line', (line) => {
|
|
249
|
+
const trimmed = line.trim();
|
|
250
|
+
if (!trimmed) return;
|
|
251
|
+
let parsed;
|
|
252
|
+
try {
|
|
253
|
+
parsed = JSON.parse(trimmed);
|
|
254
|
+
} catch {
|
|
255
|
+
output.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) + '\n');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const resp = handle(parsed);
|
|
259
|
+
if (resp !== null) {
|
|
260
|
+
output.write(JSON.stringify(resp) + '\n');
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return rl;
|
|
264
|
+
}
|
package/src/membrane.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { detect, SealSession, MembraneLeak, MEMBRANE_NOTE } from './lib/membrane-core.js';
|
|
2
|
+
export { scanInjection, stripHidden, redactSecrets, wrapUntrusted, screenGoal } from './lib/sentinel.js';
|
|
3
|
+
export { StreamSealGuard, tailHoldLength, SECRET_PREFIXES } from './lib/stream-guard.js';
|